diff --git a/custom_components/ecowater_softener/coordinator.py b/custom_components/ecowater_softener/coordinator.py index 96e1639..315592d 100644 --- a/custom_components/ecowater_softener/coordinator.py +++ b/custom_components/ecowater_softener/coordinator.py @@ -58,7 +58,9 @@ async def _async_update_data(self): if str(data_json['out_of_salt']).lower() == 'today': data[OUT_OF_SALT_ON] = datetime.today().strftime('%Y-%m-%d') elif str(data_json['out_of_salt']).lower() == 'tomorrow': - data[OUT_OF_SALT_ON] = (datetime.today() + datetime.timedelta(days=1)).strftime('%Y-%m-%d') + data[OUT_OF_SALT_ON] = (datetime.today() + timedelta(days=1)).strftime('%Y-%m-%d') + elif str(data_json['out_of_salt']).lower() == 'yesterday': + data[OUT_OF_SALT_ON] = (datetime.today() - timedelta(days=1)).strftime('%Y-%m-%d') # Runs correct datetime.strptime() depending on date format entered during setup. elif self._dateformat == "dd/mm/yyyy": data[OUT_OF_SALT_ON] = datetime.strptime(data_json['out_of_salt'], '%d/%m/%Y').strftime('%Y-%m-%d') @@ -80,4 +82,4 @@ async def _async_update_data(self): return data except Exception as e: - raise UpdateFailed(f"Error communicating with API: {e}") \ No newline at end of file + raise UpdateFailed(f"Error communicating with API: {e}")