From a90654a897e9961446d45e5920da568388d45767 Mon Sep 17 00:00:00 2001 From: barleybobs <53116390+barleybobs@users.noreply.github.com> Date: Wed, 28 Feb 2024 09:32:55 +0000 Subject: [PATCH] Update coordinator.py --- custom_components/ecowater_softener/coordinator.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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}")