Skip to content

Commit

Permalink
Fix event handling bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
ekutner committed Nov 3, 2023
1 parent d625fc8 commit 3994bbb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions home_connect_async/appliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ async def async_update_data(self, data:dict) -> None:
#self.available_programs = await self._async_fetch_programs("available")
await self._callbacks.async_broadcast_event(self, Events.DATA_CHANGED)
self._active_program_fail_count = 0

elif ( # (key == "BSH.Common.Root.ActiveProgram" and value) or # NOTE: It seems that the ActiveProgam event is received before the API returns the active program so let's try to ignore it and rely on the OperationState only
# Apparently it is possible to get progress notifications without getting the Run OperationState first so we handle that
# but we want to give the OperationState event a chance to be received so we wait until the second progress event before we handle it as an active program
Expand Down Expand Up @@ -557,7 +557,7 @@ async def async_update_data(self, data:dict) -> None:
await self._callbacks.async_broadcast_event(self, Events.DATA_CHANGED)

elif key == "BSH.Common.Status.OperationState" and value == "BSH.Common.EnumType.OperationState.Ready" \
and self.status.get("BSH.Common.Status.OperationState", {"value": None}).value != value: # ignore repeating events
and ("BSH.Common.Status.OperationState" not in self.status or self.status["BSH.Common.Status.OperationState"].value != value): # ignore repeating events
prev_prog = self.active_program.key if self.active_program else None
self.active_program = None
self._active_program_fail_count = 0
Expand All @@ -571,7 +571,7 @@ async def async_update_data(self, data:dict) -> None:
await self._callbacks.async_broadcast_event(self, Events.PROGRAM_FINISHED, prev_prog)

elif key == "BSH.Common.Status.OperationState" and value == "BSH.Common.EnumType.OperationState.Inactive" \
and self.status.get("BSH.Common.Status.OperationState", {"value": None}).value != value:
and ("BSH.Common.Status.OperationState" not in self.status or self.status["BSH.Common.Status.OperationState"].value != value):
self.active_program = None
self._active_program_fail_count = 0
self.selected_program = None
Expand All @@ -580,12 +580,12 @@ async def async_update_data(self, data:dict) -> None:
await self._callbacks.async_broadcast_event(self, Events.DATA_CHANGED)

elif key == "BSH.Common.Status.OperationState" and value == "BSH.Common.EnumType.OperationState.Pause" \
and self.status.get("BSH.Common.Status.OperationState", {"value": None}).value != value:
and ("BSH.Common.Status.OperationState" not in self.status or self.status["BSH.Common.Status.OperationState"].value != value):
self.commands = await self._async_fetch_commands()

elif key == "BSH.Common.Status.OperationState" \
and value in [ "BSH.Common.EnumType.OperationState.ActionRequired", "BSH.Common.EnumType.OperationState.Error", "BSH.Common.EnumType.OperationState.Aborting" ] \
and self.status.get("BSH.Common.Status.OperationState", {"value": None}).value != value:
and ("BSH.Common.Status.OperationState" not in self.status or self.status["BSH.Common.Status.OperationState"].value != value):
_LOGGER.debug("The appliance entered and error operation state: %s", data)

elif key =="BSH.Common.Status.RemoteControlStartAllowed":
Expand All @@ -610,7 +610,7 @@ async def async_update_data(self, data:dict) -> None:
self.selected_program.options[key].displayvalue = data.get("displayvalue")
elif "programs/selected" in uri and key != "BSH.Common.Root.SelectedProgram":
_LOGGER.debug("Got event for unknown property: %s", data)
self.active_program = await self._async_fetch_programs("selected")
self.selected_program = await self._async_fetch_programs("selected")
await self._callbacks.async_broadcast_event(self, Events.DATA_CHANGED)

if self.active_program and self.active_program.options and key in self.active_program.options:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
setup(
name = 'home-connect-async',
packages = ['home_connect_async'],
version = '0.7.13',
version = '0.7.14',
license='MIT',
description = 'Async SDK for BSH Home Connect API',
author = 'Eran Kutner',
Expand Down

0 comments on commit 3994bbb

Please sign in to comment.