From cd55ad4ef6962b82fbbe7e3a56421525078ce614 Mon Sep 17 00:00:00 2001 From: barleybobs <53116390+barleybobs@users.noreply.github.com> Date: Sun, 6 Feb 2022 11:01:43 +0000 Subject: [PATCH] Add files via upload --- custom_components/ecowater_softener/sensor.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/custom_components/ecowater_softener/sensor.py b/custom_components/ecowater_softener/sensor.py index 7c18e14..ae4fdda 100644 --- a/custom_components/ecowater_softener/sensor.py +++ b/custom_components/ecowater_softener/sensor.py @@ -115,8 +115,13 @@ async def async_update(self): self._attrs[ATTR_STATUS] = 'Online' if data_json['online'] == True else 'Offline' self._attrs[ATTR_DAYS_UNTIL_OUT_OF_SALT] = data_json['out_of_salt_days'] - #Runs correct datetime.strptime() depending on date format entered during setup. - if self._dateformat == "dd/mm/yyyy": + # Checks if date is 'today' or 'tomorrow' + if str(data_json['out_of_salt']).lower() == 'today': + self._attrs[ATTR_OUT_OF_SALT_ON] = datetime.today().strftime('%Y-%m-%d') + elif str(data_json['out_of_salt']).lower() == 'tomorrow': + self._attrs[ATTR_OUT_OF_SALT_ON] = (datetime.today() + datetime.timedelta(days=1)).strftime('%Y-%m-%d') + # Runs correct datetime.strptime() depending on date format entered during setup. + elif self._dateformat == "dd/mm/yyyy": self._attrs[ATTR_OUT_OF_SALT_ON] = datetime.strptime(data_json['out_of_salt'], '%d/%m/%Y').strftime('%Y-%m-%d') elif self._dateformat == "mm/dd/yyyy": self._attrs[ATTR_OUT_OF_SALT_ON] = datetime.strptime(data_json['out_of_salt'], '%m/%d/%Y').strftime('%Y-%m-%d')