Skip to content

Commit

Permalink
Add old state entity to events (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtomlinson authored Aug 14, 2020
1 parent e76488d commit 1a0ee19
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions opsdroid_homeassistant/connector/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,16 @@ async def _handle_message(self, msg):

if msg_type == "event":
try:
new_state = msg["event"]["data"]["new_state"]
old_state = msg["event"]["data"]["old_state"]
event = HassEvent(raw_event=msg)
event.update_entity("event_type", msg["event"]["event_type"])
event.update_entity("entity_id", msg["event"]["data"]["entity_id"])
event.update_entity("state", msg["event"]["data"]["new_state"]["state"])
changed = (
msg["event"]["data"]["old_state"] is None
or msg["event"]["data"]["new_state"]["state"]
!= msg["event"]["data"]["old_state"]["state"]
event.update_entity("state", new_state["state"])
event.update_entity(
"old_state", old_state["state"] if old_state is not None else None
)
changed = old_state is None or new_state["state"] != old_state["state"]
event.update_entity("changed", changed)
await self.opsdroid.parse(event)
except (TypeError, KeyError):
Expand Down

0 comments on commit 1a0ee19

Please sign in to comment.