Skip to content

Commit

Permalink
Merge pull request #13 from Angelius007/_attr_current_option-fix-sele…
Browse files Browse the repository at this point in the history
…ct-entity

:fix _attr_current_option error on select entity + logs pour mqtt
  • Loading branch information
Angelius007 authored Aug 18, 2024
2 parents 2f594d0 + 25c4725 commit 36b28f0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 6 additions & 1 deletion custom_components/ecoflow_cloud/api/ecoflow_mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ def __init__(self, mqtt_info: EcoflowMqttInfo, devices: dict[str, BaseDevice]):
self.__client.on_connect = self.on_connect
self.__client.on_disconnect = self.on_disconnect
self.__client.on_message = self.on_message
self.__client.on_socket_close = self.on_socket_close

_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}")
self.__client.connect(self.__mqtt_info.url, self.__mqtt_info.port, 10)
self.__client.connect(self.__mqtt_info.url, self.__mqtt_info.port, 30)

def is_connected(self):
return self.__client.is_connected()
Expand Down Expand Up @@ -101,12 +102,16 @@ def on_connect(self, client, userdata, flags, rc):

return client

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

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

def on_message(self, client, userdata, message):
try:
Expand Down
2 changes: 2 additions & 0 deletions custom_components/ecoflow_cloud/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ async def async_select_option(self, option: str):
val = self.__options_dict[option]
self.send_set_message(val, self.command_dict(val))

def current_option(self) -> str | None:
return super().current_option()

class TimeoutDictSelectEntity(DictSelectEntity):
_attr_icon = "mdi:timer-outline"
Expand Down

0 comments on commit 36b28f0

Please sign in to comment.