Skip to content

Commit 36b28f0

Browse files
authored
Merge pull request #13 from Angelius007/_attr_current_option-fix-select-entity
:fix _attr_current_option error on select entity + logs pour mqtt
2 parents 2f594d0 + 25c4725 commit 36b28f0

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

custom_components/ecoflow_cloud/api/ecoflow_mqtt.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ def __init__(self, mqtt_info: EcoflowMqttInfo, devices: dict[str, BaseDevice]):
3030
self.__client.on_connect = self.on_connect
3131
self.__client.on_disconnect = self.on_disconnect
3232
self.__client.on_message = self.on_message
33+
self.__client.on_socket_close = self.on_socket_close
3334

3435
_LOGGER.info(f"Connecting to MQTT Broker {self.__mqtt_info.url}:{self.__mqtt_info.port} with client id {self.__mqtt_info.client_id} and username {self.__mqtt_info.username}")
35-
self.__client.connect(self.__mqtt_info.url, self.__mqtt_info.port, 10)
36+
self.__client.connect(self.__mqtt_info.url, self.__mqtt_info.port, 30)
3637

3738
def is_connected(self):
3839
return self.__client.is_connected()
@@ -101,12 +102,16 @@ def on_connect(self, client, userdata, flags, rc):
101102

102103
return client
103104

105+
def on_socket_close(self, client, userdata, socket):
106+
_LOGGER.error(f"Unexpected MQTT Socket disconnection : {str(socket)}")
104107

105108
def on_disconnect(self, client, userdata, rc):
106109
if rc != 0:
107110
self.__error_count = self.__error_count+1
108111
_LOGGER.error(f"Unexpected MQTT disconnection: {rc} (Error count {self.__error_count}). Will auto-reconnect")
109112
time.sleep(15)
113+
if self.__error_count % 1000 :
114+
self.__error_count = 0 # reinit de temps en temps
110115

111116
def on_message(self, client, userdata, message):
112117
try:

custom_components/ecoflow_cloud/select.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ async def async_select_option(self, option: str):
4343
val = self.__options_dict[option]
4444
self.send_set_message(val, self.command_dict(val))
4545

46+
def current_option(self) -> str | None:
47+
return super().current_option()
4648

4749
class TimeoutDictSelectEntity(DictSelectEntity):
4850
_attr_icon = "mdi:timer-outline"

0 commit comments

Comments
 (0)