aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Basche <andre.basche@gmail.com>2024-04-09 22:46:47 +0200
committerAndre Basche <andre.basche@gmail.com>2024-04-09 22:47:28 +0200
commit63752e13d6c8e74284ad72e04306e9fedde58b40 (patch)
tree9b8a45edc30ce567d2f1244bfdcde28ade5b1aa9
parent6aa7dd811259994d30d81ced839889c1402ec737 (diff)
Fix connection failuresv0.17.4
-rw-r--r--pyhon/connection/api.py1
-rw-r--r--pyhon/connection/handler/hon.py3
-rw-r--r--pyhon/connection/mqtt.py6
-rw-r--r--setup.py2
4 files changed, 8 insertions, 4 deletions
diff --git a/pyhon/connection/api.py b/pyhon/connection/api.py
index 788a067..2140fa4 100644
--- a/pyhon/connection/api.py
+++ b/pyhon/connection/api.py
@@ -78,6 +78,7 @@ class HonAPI:
78 self._password, 78 self._password,
79 session=self._session, 79 session=self._session,
80 mobile_id=self._mobile_id, 80 mobile_id=self._mobile_id,
81 refresh_token=self._refresh_token,
81 ).create() 82 ).create()
82 return self 83 return self
83 84
diff --git a/pyhon/connection/handler/hon.py b/pyhon/connection/handler/hon.py
index 988c8f4..9cce8ee 100644
--- a/pyhon/connection/handler/hon.py
+++ b/pyhon/connection/handler/hon.py
@@ -62,6 +62,7 @@ class HonConnectionHandler(ConnectionHandler):
62 await self.auth.refresh(self._refresh_token) 62 await self.auth.refresh(self._refresh_token)
63 if not (self.auth.cognito_token and self.auth.id_token): 63 if not (self.auth.cognito_token and self.auth.id_token):
64 await self.auth.authenticate() 64 await self.auth.authenticate()
65 self._refresh_token = self.auth.refresh_token
65 headers["cognito-token"] = self.auth.cognito_token 66 headers["cognito-token"] = self.auth.cognito_token
66 headers["id-token"] = self.auth.id_token 67 headers["id-token"] = self.auth.id_token
67 return self._HEADERS | headers 68 return self._HEADERS | headers
@@ -77,7 +78,7 @@ class HonConnectionHandler(ConnectionHandler):
77 self.auth.token_expires_soon or response.status in [401, 403] 78 self.auth.token_expires_soon or response.status in [401, 403]
78 ) and loop == 0: 79 ) and loop == 0:
79 _LOGGER.info("Try refreshing token...") 80 _LOGGER.info("Try refreshing token...")
80 await self.auth.refresh() 81 await self.auth.refresh(self._refresh_token)
81 async with self._intercept( 82 async with self._intercept(
82 method, url, *args, loop=loop + 1, **kwargs 83 method, url, *args, loop=loop + 1, **kwargs
83 ) as result: 84 ) as result:
diff --git a/pyhon/connection/mqtt.py b/pyhon/connection/mqtt.py
index 3210c6e..7c60a53 100644
--- a/pyhon/connection/mqtt.py
+++ b/pyhon/connection/mqtt.py
@@ -35,6 +35,7 @@ class MQTTClient:
35 async def create(self) -> "MQTTClient": 35 async def create(self) -> "MQTTClient":
36 await self._start() 36 await self._start()
37 self._subscribe_appliances() 37 self._subscribe_appliances()
38 await self.start_watchdog()
38 return self 39 return self
39 40
40 def _on_lifecycle_stopped( 41 def _on_lifecycle_stopped(
@@ -63,6 +64,7 @@ class MQTTClient:
63 self, 64 self,
64 lifecycle_connection_failure_data: mqtt5.LifecycleConnectFailureData, 65 lifecycle_connection_failure_data: mqtt5.LifecycleConnectFailureData,
65 ) -> None: 66 ) -> None:
67 self._connection = False
66 _LOGGER.info( 68 _LOGGER.info(
67 "Lifecycle Connection Failure - %s", str(lifecycle_connection_failure_data) 69 "Lifecycle Connection Failure - %s", str(lifecycle_connection_failure_data)
68 ) 70 )
@@ -88,7 +90,6 @@ class MQTTClient:
88 parameter 90 parameter
89 ) 91 )
90 appliance.sync_params_to_command("settings") 92 appliance.sync_params_to_command("settings")
91 self._hon.notify()
92 elif topic and "disconnected" in topic: 93 elif topic and "disconnected" in topic:
93 _LOGGER.info( 94 _LOGGER.info(
94 "Disconnected %s: %s", 95 "Disconnected %s: %s",
@@ -101,6 +102,7 @@ class MQTTClient:
101 _LOGGER.info("Connected %s", appliance.nick_name) 102 _LOGGER.info("Connected %s", appliance.nick_name)
102 elif topic and "discovery" in topic: 103 elif topic and "discovery" in topic:
103 _LOGGER.info("Discovered %s", appliance.nick_name) 104 _LOGGER.info("Discovered %s", appliance.nick_name)
105 self._hon.notify()
104 _LOGGER.info("%s - %s", topic, payload) 106 _LOGGER.info("%s - %s", topic, payload)
105 107
106 async def _start(self) -> None: 108 async def _start(self) -> None:
@@ -133,7 +135,7 @@ class MQTTClient:
133 135
134 async def start_watchdog(self) -> None: 136 async def start_watchdog(self) -> None:
135 if not self._watchdog_task or self._watchdog_task.done(): 137 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())
137 139
138 async def _watchdog(self) -> None: 140 async def _watchdog(self) -> None:
139 while True: 141 while True:
diff --git a/setup.py b/setup.py
index 58a9454..115205d 100644
--- a/setup.py
+++ b/setup.py
@@ -7,7 +7,7 @@ with open("README.md", "r", encoding="utf-8") as f:
7 7
8setup( 8setup(
9 name="pyhOn", 9 name="pyhOn",
10 version="0.17.3", 10 version="0.17.4",
11 author="Andre Basche", 11 author="Andre Basche",
12 description="Control hOn devices with python", 12 description="Control hOn devices with python",
13 long_description=long_description, 13 long_description=long_description,