Skip to content

Commit

Permalink
Merge pull request #10 from barleybobs/dev
Browse files Browse the repository at this point in the history
Fixed issue with out_of_salt being equal to 'Today' or 'Tomorrow'
  • Loading branch information
barleybobs authored Feb 6, 2022
2 parents 88b477c + cd55ad4 commit 29a31c9
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions custom_components/ecowater_softener/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 29a31c9

Please sign in to comment.