Skip to content

Commit 48589ce

Browse files
fix: authenticate error when only fog device exists. (#60)
* fix: authenticate error when only fog device exists. (cherry picked from commit bf1c60f) * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent ced4e8a commit 48589ce

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

custom_components/deye_dehumidifier/__init__.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,22 +63,30 @@ def on_auth_token_refreshed(auth_token: str) -> None:
6363
entry.data[CONF_AUTH_TOKEN],
6464
)
6565
cloud_api.on_auth_token_refreshed = on_auth_token_refreshed
66-
mqtt_info = await cloud_api.get_deye_platform_mqtt_info()
67-
mqtt_client = DeyeMqttClient(
68-
mqtt_info["mqtthost"],
69-
mqtt_info["sslport"],
70-
mqtt_info["loginname"],
71-
mqtt_info["password"],
72-
mqtt_info["endpoint"],
73-
ssl.get_default_context(),
74-
)
75-
mqtt_client.connect()
66+
7667
device_list = list(
7768
filter(
7869
lambda d: d["product_type"] == "dehumidifier",
7970
await cloud_api.get_device_list(),
8071
)
8172
)
73+
74+
classic_device_list = [
75+
device for device in device_list if device["platform"] == 1
76+
]
77+
mqtt_client = None
78+
if len(classic_device_list) > 0:
79+
mqtt_info = await cloud_api.get_deye_platform_mqtt_info()
80+
mqtt_client = DeyeMqttClient(
81+
mqtt_info["mqtthost"],
82+
mqtt_info["sslport"],
83+
mqtt_info["loginname"],
84+
mqtt_info["password"],
85+
mqtt_info["endpoint"],
86+
ssl.get_default_context(),
87+
)
88+
mqtt_client.connect()
89+
8290
coordinator_map = {}
8391
for device in device_list:
8492
coordinator = DeyeDataUpdateCoordinator(
@@ -109,7 +117,8 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
109117
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
110118
data = hass.data[DOMAIN].pop(entry.entry_id)
111119
mqtt_client: DeyeMqttClient = data[DATA_MQTT_CLIENT]
112-
mqtt_client.disconnect()
120+
if mqtt_client is not None:
121+
mqtt_client.disconnect()
113122

114123
return unload_ok
115124

0 commit comments

Comments
 (0)