Skip to content

Commit

Permalink
Improve handling of changing programs while there is an active program
Browse files Browse the repository at this point in the history
  • Loading branch information
ekutner committed Jun 14, 2022
1 parent 14508f7 commit 59038ce
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
3 changes: 2 additions & 1 deletion home_connect_async/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ def __init__(self, auth:AbstractAuth, lang:str=None, log_mode:LogMode=None):
self._log_mode = log_mode


async def _async_request(self, method, endpoint, data=None) -> ApiResponse:
async def _async_request(self, method:str, endpoint:str, data=None) -> ApiResponse:
""" Main function to call the Home Connect API over HTTPS """
method = method.capitalize()
retry = 3
response = None
while retry:
Expand Down
16 changes: 13 additions & 3 deletions home_connect_async/appliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class Option():
allowedvalues:Optional[list[str]] = None
execution:Optional[str] = None
liveupdate:Optional[bool] = None
access:Optional[str] = None

@classmethod
def create(cls, data:dict):
Expand All @@ -89,6 +90,7 @@ def create(cls, data:dict):
option.allowedvalues = constraints.get('allowedvalues')
option.execution = constraints.get('execution')
option.liveupdate = constraints.get('liveupdate')
option.access = constraints.get('access')
return option

def get_option_to_apply(self, value, exception_on_error=False):
Expand Down Expand Up @@ -267,23 +269,31 @@ async def async_select_program(self, key:str=None, options:Sequence[dict]=None,

key = program.key
previous_program = self.startonly_program if self.startonly_program else self.selected_program
if program.execution == 'startonly':
if program.execution == 'startonly' and not self.active_program:
self.startonly_program = program
_LOGGER.debug("Setting startonly_program=%s", program.key)
if not previous_program or previous_program.key != key:
await self._callbacks.async_broadcast_event(self, Events.PROGRAM_SELECTED)
return
else:
self.startonly_program = None

async with Synchronization.selected_program_lock:
res = await self._async_set_program(key, options, 'selected')
if self.active_program:
res = await self._async_set_program(key, options, 'active')
else:
res = await self._async_set_program(key, options, 'selected')
if res and (previous_program.key != key):
# There is a race condition between this and the selected program event
# so check if it was alreayd update so we don't call twice
# Note that this can't be dropped because the new options notification may arrive before the
# program selected event and then the option values will not match the values that were there for the
# previous program
self.selected_program = await self._async_fetch_programs('selected')
if self.active_program:
self.active_program = await self._async_fetch_programs('active')
else:
self.selected_program = await self._async_fetch_programs('selected')
# TODO: Consider if the above updates can be removed or if adding available_programs is required
self.available_programs = await self._async_fetch_programs('available')
await self._callbacks.async_broadcast_event(self, Events.PROGRAM_SELECTED)
await self._callbacks.async_broadcast_event(self, Events.DATA_CHANGED)
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.0-b5',
version = '0.7.0-b6',
license='MIT',
description = 'Async SDK for BSH Home Connect API',
author = 'Eran Kutner',
Expand Down

0 comments on commit 59038ce

Please sign in to comment.