Skip to content

Commit

Permalink
Initialize Wasp state on app load
Browse files Browse the repository at this point in the history
  • Loading branch information
wernerhp committed Aug 21, 2020
1 parent 7f2bb0a commit faee7e0
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion apps/wasp.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ def initialize(self):

self.sensors = self.door_sensors + self.motion_sensors

self.set_state(self.wasp_id, state="off", attributes={
"device_class": "occupancy",
"friendly_name": self.friendly_name,
}
)

handles = []
handle = self.listen_event(self.state_changed_callback, "state_changed")
handles.append(handle)
Expand Down Expand Up @@ -72,7 +78,8 @@ def detect_wasp(self):
def update_box_state(self, data, wasp=False):
"""Update the box state."""
state = "on" if wasp else "off"
last_changed = datetime.fromisoformat(data.get("new_state").get("last_changed"))
new = data.get("new_state")
last_changed = datetime.fromisoformat(new.get("last_changed")) if new else self.datetime()
last_changed = last_changed.replace(microsecond=0)
self.last_state = self.set_state(self.wasp_id, state=state, attributes={
"last_changed": last_changed.isoformat(),
Expand Down

0 comments on commit faee7e0

Please sign in to comment.