Skip to content

Commit

Permalink
Add support for disabled appliances
Browse files Browse the repository at this point in the history
  • Loading branch information
ekutner committed Sep 20, 2023
1 parent 601c547 commit cb07a57
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions home_connect_async/homeconnect.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,25 @@ class RefreshMode(Enum):
# )


_disabled_appliances:Optional[list[str]] = field(default_factory=lambda: list() )

# Internal fields - not serialized to JSON
_api:Optional[HomeConnectApi] = field(default=None, metadata=config(encoder=lambda val: None, exclude=lambda val: True))
_updates_task:Optional[Task] = field(default=None, metadata=config(encoder=lambda val: None, exclude=lambda val: True))
_load_task:Optional[Task] = field(default=None, metadata=config(encoder=lambda val: None, exclude=lambda val: True))
_callbacks:Optional[CallbackRegistry] = field(default_factory=lambda: CallbackRegistry(), metadata=config(encoder=lambda val: None, exclude=lambda val: True))


@classmethod
async def async_create(cls,
am:AuthManager,
json_data:str=None,
delayed_load:bool=False,
refresh:RefreshMode=RefreshMode.DYNAMIC_ONLY,
auto_update:bool=False,
lang:str=None) -> HomeConnect:
lang:str=None,
disabled_appliances:list[str] = []
) -> HomeConnect:
""" Factory for creating a HomeConnect object - DO NOT USE THE DEFAULT CONSTRUCTOR
Parameters:
Expand Down Expand Up @@ -94,6 +99,7 @@ async def async_create(cls,

hc._api = api
hc._refresh_mode = refresh
hc._disabled_appliances = disabled_appliances

if not delayed_load:
await hc.async_load_data(refresh)
Expand Down Expand Up @@ -146,6 +152,9 @@ async def async_load_data(self,
if 'homeappliances' in data:
for ha in data['homeappliances']:
haid = ha['haId']
if haid in self._disabled_appliances or haid.lower().replace('-','_') in self._disabled_appliances:
continue

haid_list.append(haid)
if ha['connected']:
if haid in self.appliances:
Expand Down Expand Up @@ -302,7 +311,7 @@ def parse_sse_error(error:str) -> int:
async def _async_process_updates(self, event:MessageEvent):
""" Handle the different kinds of events received over the SSE channel """
haid = event.last_event_id
if event.type == 'KEEP-ALIVE':
if event.type == 'KEEP-ALIVE' or haid.lower().replace('-','_') in self._disabled_appliances:
self._last_update = datetime.now()
return
if haid not in self.appliances:
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.10',
version = '0.7.11',
license='MIT',
description = 'Async SDK for BSH Home Connect API',
author = 'Eran Kutner',
Expand Down

0 comments on commit cb07a57

Please sign in to comment.