Skip to content

Commit 86c2956

Browse files
committed
Handle mqtt connection events
1 parent bdf9d31 commit 86c2956

File tree

7 files changed

+23
-6
lines changed

7 files changed

+23
-6
lines changed

pyhon/appliance.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ def __init__(
4343
self._additional_data: Dict[str, Any] = {}
4444
self._last_update: Optional[datetime] = None
4545
self._default_setting = HonParameter("", {}, "")
46+
self._connection = (
47+
not self._attributes.get("lastConnEvent", {}).get("category", "")
48+
== "DISCONNECTED"
49+
)
4650

4751
try:
4852
self._extra: Optional[ApplianceBase] = importlib.import_module(
@@ -90,6 +94,14 @@ def _check_name_zone(self, name: str, frontend: bool = True) -> str:
9094
return f"{attribute}{zone}{self._zone}"
9195
return attribute
9296

97+
@property
98+
def connection(self) -> bool:
99+
return self._connection
100+
101+
@connection.setter
102+
def connection(self, connection: bool) -> None:
103+
self._connection = connection
104+
93105
@property
94106
def appliance_model_id(self) -> str:
95107
return str(self._info.get("applianceModelId", ""))

pyhon/appliances/dw.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
class Appliance(ApplianceBase):
88
def attributes(self, data: Dict[str, Any]) -> Dict[str, Any]:
99
data = super().attributes(data)
10-
if data.get("lastConnEvent", {}).get("category", "") == "DISCONNECTED":
10+
if not self.parent.connection:
1111
data["parameters"]["machMode"].value = "0"
1212
data["active"] = bool(data.get("activity"))
1313
return data

pyhon/appliances/ov.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
class Appliance(ApplianceBase):
77
def attributes(self, data: Dict[str, Any]) -> Dict[str, Any]:
88
data = super().attributes(data)
9-
if data.get("lastConnEvent", {}).get("category", "") == "DISCONNECTED":
9+
if not self.parent.connection:
1010
data["parameters"]["temp"].value = 0
1111
data["parameters"]["onOffStatus"].value = 0
1212
data["parameters"]["remoteCtrValid"].value = 0

pyhon/appliances/td.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
class Appliance(ApplianceBase):
99
def attributes(self, data: Dict[str, Any]) -> Dict[str, Any]:
1010
data = super().attributes(data)
11-
if data.get("lastConnEvent", {}).get("category", "") == "DISCONNECTED":
11+
if not self.parent.connection:
1212
data["parameters"]["machMode"].value = "0"
1313
data["active"] = bool(data.get("activity"))
1414
data["pause"] = data["parameters"]["machMode"] == "3"

pyhon/appliances/wd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
class Appliance(ApplianceBase):
88
def attributes(self, data: Dict[str, Any]) -> Dict[str, Any]:
99
data = super().attributes(data)
10-
if data.get("lastConnEvent", {}).get("category", "") == "DISCONNECTED":
10+
if not self.parent.connection:
1111
data["parameters"]["machMode"].value = "0"
1212
data["active"] = bool(data.get("activity"))
1313
data["pause"] = data["parameters"]["machMode"] == "3"

pyhon/connection/mqtt.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,14 @@ def _on_publish_received(self, data: mqtt5.PublishReceivedData) -> None:
9090
appliance.sync_params_to_command("settings")
9191
self._hon.notify()
9292
elif topic and "disconnected" in topic:
93-
_LOGGER.info("Disconnected %s", appliance.nick_name)
93+
_LOGGER.info(
94+
"Disconnected %s: %s",
95+
appliance.nick_name,
96+
payload.get("disconnectReason"),
97+
)
98+
appliance.connection = False
9499
elif topic and "connected" in topic:
100+
appliance.connection = True
95101
_LOGGER.info("Connected %s", appliance.nick_name)
96102
elif topic and "discovery" in topic:
97103
_LOGGER.info("Discovered %s", appliance.nick_name)

pyhon/hon.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import asyncio
21
import logging
32
from pathlib import Path
43
from types import TracebackType

0 commit comments

Comments
 (0)