Skip to content

Commit 34be47d

Browse files
author
ekutner
committed
Dynamically load avalable programs and options
1 parent 1825e94 commit 34be47d

File tree

8 files changed

+155
-88
lines changed

8 files changed

+155
-88
lines changed

home_connect_async/api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ async def async_delete(self, endpoint:str) -> ApiResponse:
100100

101101
async def async_get_event_stream(self, endpoint):
102102
""" Returns a Server Sent Events (SSE) stream to be consumed by the caller """
103-
return await self._auth.stream(endpoint)
103+
return await self._auth.stream(endpoint, self._lang)
104104

105105

106106
async def async_stream(self, endpoint:str, event_handler:Callable[[str], None]):
@@ -109,7 +109,7 @@ async def async_stream(self, endpoint:str, event_handler:Callable[[str], None]):
109109
event_source = None
110110
while True:
111111
try:
112-
event_source = await self._auth.stream(endpoint)
112+
event_source = await self._auth.stream(endpoint, self._lang)
113113
await event_source.connect()
114114
async for event in event_source:
115115
backoff = 1

home_connect_async/appliance.py

Lines changed: 136 additions & 81 deletions
Large diffs are not rendered by default.

home_connect_async/auth.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,23 @@ async def request(self, method, endpoint:str, lang:str=None, **kwargs) -> Client
3939
access_token = await self.async_get_access_token()
4040
headers['authorization'] = f'Bearer {access_token}'
4141
headers['Accept'] = 'application/vnd.bsh.sdk.v1+json'
42-
headers['Accept-Language'] = lang if lang else 'en-GB'
42+
if lang:
43+
headers['Accept-Language'] = lang
4344
if method == 'put':
4445
headers['Content-Type'] = 'application/vnd.bsh.sdk.v1+json'
4546

4647
return await self.websession.request(
4748
method, f"{self.host}{endpoint}", **kwargs, headers=headers,
4849
)
4950

50-
async def stream(self, endpoint:str, **kwargs) -> sse_client.EventSource:
51+
async def stream(self, endpoint:str, lang:str=None, **kwargs) -> sse_client.EventSource:
5152
""" Initiate a SSE stream """
5253
headers = {}
5354
access_token = await self.async_get_access_token()
5455
headers['authorization'] = f'Bearer {access_token}'
5556
headers['Accept'] = 'application/vnd.bsh.sdk.v1+json'
56-
#headers['Accept-Language'] = 'en-GB'
57+
if lang:
58+
headers['Accept-Language'] = lang
5759
#timeout = aiohttp.ClientTimeout(total = ( self._auth.access_token_expirs_at - datetime.now() ).total_seconds() )
5860
timeout = aiohttp.ClientTimeout(total = 3600 )
5961
return sse_client.EventSource(f"{self.host}{endpoint}", session=self.websession, headers=headers, timeout=timeout, **kwargs)

home_connect_async/callback_registery.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class CallbackRegistry():
1818
def __init__(self) -> None:
1919
self._callbacks = {}
2020

21+
2122
def register_callback(self,
2223
callback:Callable[[Appliance, str, any], None] | Callable[[Appliance, str], None] | Callable[[Appliance], None] | Callable[[], None],
2324
keys:str|Events|Sequence[str|Events],

home_connect_async/common.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
""" Common classes shared across the code """
22

3+
import asyncio
4+
5+
36
class HomeConnectError(Exception):
47
""" Common exception class for the SDK """
58
def __init__(self, msg:str = None, code:int = None, response = None, inner_exception = None):
@@ -18,3 +21,7 @@ def __init__(self, msg:str = None, code:int = None, response = None, inner_excep
1821
super().__init__(msg, code, self.error_key, self.error_description, inner_exception)
1922

2023

24+
class Synchronization():
25+
""" Class to hold global syncronization objects """
26+
selected_program_lock = asyncio.Lock()
27+

home_connect_async/const.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class Events(str,Enum):
1414
DISCONNECTED = "DISCONNECTED"
1515
PAIRED = "PAIRED"
1616
DEPAIRED = "DEPAIRED"
17+
PROGRAM_SELECTED = "PROGRAM_SELECTED"
1718
PROGRAM_STARTED = "PROGRAM_STARTED"
1819
PROGRAM_FINISHED = "PROGRAM_FINISHED"
1920
UNHANDLED = "UNHANDLED"

home_connect_async/homeconnect.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ async def async_create(cls,
9797
for appliance in hc.appliances.values():
9898
appliance._homeconnect = hc
9999
appliance._callbacks = hc._callbacks
100+
appliance._api = api
100101
except Exception as ex:
101102
_LOGGER.exception("Exception when loading HomeConnect data from JSON", exc_info=ex)
102103
if not hc:
@@ -332,7 +333,7 @@ async def _async_process_updates(self, event:MessageEvent):
332333
# haid = self._get_haId_from_event(item) if 'uri' in item else haid
333334
if haid in self.appliances:
334335
appliance = self.appliances[haid]
335-
await appliance.async_update_data(item['key'], item['value'])
336+
await appliance.async_update_data(item)
336337

337338

338339
# def _get_haId_from_event(self, event:dict):

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
setup(
44
name = 'home-connect-async',
55
packages = ['home_connect_async'],
6-
version = '0.5.8',
6+
version = '0.6.0',
77
license='MIT',
88
description = 'Async SDK for BSH Home Connect API',
99
author = 'Eran Kutner',

0 commit comments

Comments
 (0)