Skip to content

Commit 63752e1

Browse files
committed
Fix connection failures
1 parent 6aa7dd8 commit 63752e1

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed

pyhon/connection/api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ async def create(self) -> Self:
7878
self._password,
7979
session=self._session,
8080
mobile_id=self._mobile_id,
81+
refresh_token=self._refresh_token,
8182
).create()
8283
return self
8384

pyhon/connection/handler/hon.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ async def _check_headers(self, headers: Dict[str, str]) -> Dict[str, str]:
6262
await self.auth.refresh(self._refresh_token)
6363
if not (self.auth.cognito_token and self.auth.id_token):
6464
await self.auth.authenticate()
65+
self._refresh_token = self.auth.refresh_token
6566
headers["cognito-token"] = self.auth.cognito_token
6667
headers["id-token"] = self.auth.id_token
6768
return self._HEADERS | headers
@@ -77,7 +78,7 @@ async def _intercept(
7778
self.auth.token_expires_soon or response.status in [401, 403]
7879
) and loop == 0:
7980
_LOGGER.info("Try refreshing token...")
80-
await self.auth.refresh()
81+
await self.auth.refresh(self._refresh_token)
8182
async with self._intercept(
8283
method, url, *args, loop=loop + 1, **kwargs
8384
) as result:

pyhon/connection/mqtt.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def client(self) -> mqtt5.Client:
3535
async def create(self) -> "MQTTClient":
3636
await self._start()
3737
self._subscribe_appliances()
38+
await self.start_watchdog()
3839
return self
3940

4041
def _on_lifecycle_stopped(
@@ -63,6 +64,7 @@ def _on_lifecycle_connection_failure(
6364
self,
6465
lifecycle_connection_failure_data: mqtt5.LifecycleConnectFailureData,
6566
) -> None:
67+
self._connection = False
6668
_LOGGER.info(
6769
"Lifecycle Connection Failure - %s", str(lifecycle_connection_failure_data)
6870
)
@@ -88,7 +90,6 @@ def _on_publish_received(self, data: mqtt5.PublishReceivedData) -> None:
8890
parameter
8991
)
9092
appliance.sync_params_to_command("settings")
91-
self._hon.notify()
9293
elif topic and "disconnected" in topic:
9394
_LOGGER.info(
9495
"Disconnected %s: %s",
@@ -101,6 +102,7 @@ def _on_publish_received(self, data: mqtt5.PublishReceivedData) -> None:
101102
_LOGGER.info("Connected %s", appliance.nick_name)
102103
elif topic and "discovery" in topic:
103104
_LOGGER.info("Discovered %s", appliance.nick_name)
105+
self._hon.notify()
104106
_LOGGER.info("%s - %s", topic, payload)
105107

106108
async def _start(self) -> None:
@@ -133,7 +135,7 @@ def _subscribe(self, appliance: HonAppliance) -> None:
133135

134136
async def start_watchdog(self) -> None:
135137
if not self._watchdog_task or self._watchdog_task.done():
136-
await asyncio.create_task(self._watchdog())
138+
self._watchdog_task = asyncio.create_task(self._watchdog())
137139

138140
async def _watchdog(self) -> None:
139141
while True:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
setup(
99
name="pyhOn",
10-
version="0.17.3",
10+
version="0.17.4",
1111
author="Andre Basche",
1212
description="Control hOn devices with python",
1313
long_description=long_description,

0 commit comments

Comments
 (0)