Skip to content

Commit

Permalink
Fix water started timestamp parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
sebr committed Jan 25, 2020
1 parent 01b49fd commit 910cc22
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions custom_components/bhyve/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,15 @@ def _setup(self, device):
self._attrs[ATTR_IMAGE_URL] = image_url

if is_watering:
started_watering_at = watering_status.get(
"started_watering_station_at"
)
started_watering_at = watering_status.get("started_watering_station_at")
self._set_watering_started(started_watering_at)

def _set_watering_started(self, timestamp):
_LOGGER.debug("Timestamp is {}".format(timestamp))
if timestamp is not None:
self._attrs[ATTR_STARTED_WATERING_AT] = dt.as_local(dt.as_timestamp(timestamp))
self._attrs[ATTR_STARTED_WATERING_AT] = dt.as_local(
dt.parse_datetime(timestamp)
)
else:
self._attrs[ATTR_STARTED_WATERING_AT] = None

Expand All @@ -125,9 +126,7 @@ def _on_ws_data(self, data):
zone = data.get("current_station")
if zone == self._zone_id:
self._state = True
started_watering_at = watering_status.get(
"started_watering_station_at"
)
started_watering_at = data.get("started_watering_station_at")
self._set_watering_started(started_watering_at)
elif event == "change_mode":
program = data.get("program")
Expand Down

0 comments on commit 910cc22

Please sign in to comment.