Skip to content

Commit

Permalink
Support for start-only options, like delayed start
Browse files Browse the repository at this point in the history
  • Loading branch information
ekutner committed Feb 23, 2022
1 parent 34be47d commit 9d74e48
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
31 changes: 26 additions & 5 deletions home_connect_async/appliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
class Status():
""" Class to represent a Home Connect Status """
key:str
name:Optional[str] = None
value:Optional[any] = None
name:Optional[str] = None
displayvalue:Optional[str] = None

@classmethod
Expand Down Expand Up @@ -58,10 +58,10 @@ def create(cls, data:dict):
class Option():
""" Class to represent a Home Connect Option """
key:str
value:Optional[any] = None
type:Optional[str] = None
name:Optional[str] = None
unit:Optional[str] = None
value:Optional[any] = None
displayvalue:Optional[str] = None
min:Optional[int] = None
max:Optional[int] = None
Expand Down Expand Up @@ -165,13 +165,29 @@ class Appliance():
status:dict[str, Status] = None
settings:dict[str, Option] = None
commands:dict[str, Command] = None
start_options:dict[str, Option] = None

# Internal fields
_homeconnect:Optional[homeconnect.HomeConnect] = field(default_factory=lambda: None, metadata=config(encoder=lambda val: None, decoder=lambda val: None, exclude=lambda val: True))
_api:Optional[HomeConnectApi] = field(default=None, metadata=config(encoder=lambda val: None, exclude=lambda val: True))
_callbacks:Optional[callback_registery.CallbackRegistry] = field(default_factory=lambda: None, metadata=config(encoder=lambda val: None, exclude=lambda val: True))

#region - Manage Programs
def set_start_option(self, option_key:str, value) -> None:
""" Set an option that will be used when starting the program """
if not self.start_options:
self.start_options = {}
if option_key not in self.start_options:
self.start_options[option_key] = Option(option_key, value=value)
else:
self.start_options[option_key].value = value

def clear_start_option(self, option_key:str) -> None:
""" Clear a previously set start option """
if self.start_options and option_key in self.start_options:
del self.start_options[option_key]


async def async_get_active_program(self):
""" Get the active program """
prog = await self._async_fetch_programs('active')
Expand Down Expand Up @@ -235,10 +251,15 @@ async def async_start_program(self, program_key:str=None, options:Sequence[dict]
_LOGGER.warning("The selected program in not one of the available programs (not supported by the API)")
raise HomeConnectError("The specified program in not one of the available programs (not supported by the API)")

if options is None and self.selected_program and self.available_programs:
if options is None:
options = []
for opt in self.selected_program.options.values():
if opt.key in self.available_programs[program_key].options:
if self.selected_program and self.available_programs:
for opt in self.selected_program.options.values():
if opt.key in self.available_programs[program_key].options and (not self.start_options or opt.key not in self.start_options):
option = { "key": opt.key, "value": opt.value}
options.append(option)
if self.start_options:
for opt in self.start_options.values():
option = { "key": opt.key, "value": opt.value}
options.append(option)

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.6.0',
version = '0.6.1',
license='MIT',
description = 'Async SDK for BSH Home Connect API',
author = 'Eran Kutner',
Expand Down

0 comments on commit 9d74e48

Please sign in to comment.