Skip to content

Commit

Permalink
Do not stop polling when device is marked unavailable
Browse files Browse the repository at this point in the history
Ref.
#167
  • Loading branch information
nao-pon committed Feb 12, 2024
1 parent 3c130e8 commit 0286da5
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 66 deletions.
5 changes: 0 additions & 5 deletions custom_components/echonetlite/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@ def __init__(self, name, connector):
self._attr_should_poll = True
self._attr_available = True

self._real_should_poll = True

self.update_option_listener()
self._set_attrs()

Expand Down Expand Up @@ -369,9 +367,6 @@ async def async_update_callback(self, isPush=False):
_force = bool(not self._attr_available and self._server_state["available"])
self._olddata = self._connector._update_data.copy()
self._attr_available = self._server_state["available"]
self._attr_should_poll = (
self._real_should_poll if self._attr_available else False
)
self._set_attrs()
self.async_schedule_update_ha_state(_force)
if isPush:
Expand Down
8 changes: 1 addition & 7 deletions custom_components/echonetlite/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,6 @@ async def async_update_callback(self, isPush=False):
if changed:
self._olddata = self._connector._update_data.copy()
self._attr_available = self._server_state["available"]
self._attr_should_poll = (
self._real_should_poll if self._attr_available else False
)
self._set_attrs()
self.async_schedule_update_ha_state()
if isPush:
Expand Down Expand Up @@ -227,11 +224,8 @@ def update_option_listener(self):
and ENL_FAN_OSCILLATION not in self._connector._ntfPropertyMap
)
)
self._real_should_poll = (
self._connector._user_options.get(CONF_FORCE_POLLING, False) or _should_poll
)
self._attr_should_poll = (
self._real_should_poll if self._attr_available else False
self._connector._user_options.get(CONF_FORCE_POLLING, False) or _should_poll
)
self._attr_extra_state_attributes = {"notify": "No" if _should_poll else "Yes"}
_LOGGER.debug(f"{self._attr_name}: _should_poll is {_should_poll}")
10 changes: 1 addition & 9 deletions custom_components/echonetlite/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ def __init__(self, name, connector):
self._attr_should_poll = True
self._attr_available = True

self._real_should_poll = True

self.update_option_listener()

async def async_update(self):
Expand Down Expand Up @@ -227,9 +225,6 @@ async def async_update_callback(self, isPush=False):
else False
)
self._attr_available = self._server_state["available"]
self._attr_should_poll = (
self._real_should_poll if self._attr_available else False
)
self._set_attrs()
self.async_schedule_update_ha_state(_force)
if isPush and self._attr_should_poll:
Expand All @@ -252,11 +247,8 @@ def update_option_listener(self):
and ENL_COLOR_TEMP not in self._connector._ntfPropertyMap
)
)
self._real_should_poll = bool(
self._attr_should_poll = bool(
self._connector._user_options.get(CONF_FORCE_POLLING, False) or _should_poll
)
self._attr_should_poll = (
self._real_should_poll if self._attr_available else False
)
self._attr_extra_state_attributes = {"notify": "No" if _should_poll else "Yes"}
_LOGGER.debug(f"{self._attr_name}: _should_poll is {_should_poll}")
10 changes: 1 addition & 9 deletions custom_components/echonetlite/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ def __init__(self, hass, connector, config, code, options, name=None):
self._attr_should_poll = True
self._attr_available = True

self._real_should_poll = True

self.update_option_listener()

@property
Expand Down Expand Up @@ -170,18 +168,12 @@ async def async_update_callback(self, isPush=False):
self._attr_native_value = new_val
self._attr_native_max_value = self.get_max_value()
self._attr_available = self._server_state["available"]
self._attr_should_poll = (
self._real_should_poll if self._attr_available else False
)
self.async_schedule_update_ha_state(_force)

def update_option_listener(self):
_should_poll = self._code not in self._connector._ntfPropertyMap
self._real_should_poll = (
self._connector._user_options.get(CONF_FORCE_POLLING, False) or _should_poll
)
self._attr_should_poll = (
self._real_should_poll if self._attr_available else False
self._connector._user_options.get(CONF_FORCE_POLLING, False) or _should_poll
)
self._attr_extra_state_attributes = {"notify": "No" if _should_poll else "Yes"}
_LOGGER.debug(
Expand Down
10 changes: 1 addition & 9 deletions custom_components/echonetlite/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ def __init__(self, hass, connector, config, code, options, name=None):
self._attr_available = True
self._attr_force_update = False

self._real_should_poll = True

self.update_option_listener()

@property
Expand Down Expand Up @@ -153,19 +151,13 @@ async def async_update_callback(self, isPush=False):
_force = bool(not self._attr_available and self._server_state["available"])
self._attr_current_option = new_val
self._attr_available = self._server_state["available"]
self._attr_should_poll = (
self._real_should_poll if self._attr_available else False
)
self.update_attr()
self.async_schedule_update_ha_state(_force)

def update_option_listener(self):
_should_poll = self._code not in self._connector._ntfPropertyMap
self._real_should_poll = (
self._connector._user_options.get(CONF_FORCE_POLLING, False) or _should_poll
)
self._attr_should_poll = (
self._real_should_poll if self._attr_available else False
self._connector._user_options.get(CONF_FORCE_POLLING, False) or _should_poll
)
self._attr_extra_state_attributes = {"notify": "No" if _should_poll else "Yes"}
_LOGGER.debug(
Expand Down
10 changes: 1 addition & 9 deletions custom_components/echonetlite/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,6 @@ def __init__(self, connector, op_code, attributes, name=None, hass=None) -> None
self._attr_should_poll = True
self._attr_available = True

self._real_should_poll = True

self.update_option_listener()

@property
Expand Down Expand Up @@ -478,18 +476,12 @@ async def async_update_callback(self, isPush=False):
self._state_value = new_val
self._attr_native_value = self.get_attr_native_value()
self._attr_available = self._server_state["available"]
self._attr_should_poll = (
self._real_should_poll if self._attr_available else False
)
self.async_schedule_update_ha_state(_force)

def update_option_listener(self):
_should_poll = self._op_code not in self._connector._ntfPropertyMap
self._real_should_poll = (
self._connector._user_options.get(CONF_FORCE_POLLING, False) or _should_poll
)
self._attr_should_poll = (
self._real_should_poll if self._attr_available else False
self._connector._user_options.get(CONF_FORCE_POLLING, False) or _should_poll
)
self._attr_extra_state_attributes = {"notify": "No" if _should_poll else "Yes"}
_LOGGER.debug(
Expand Down
10 changes: 1 addition & 9 deletions custom_components/echonetlite/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@ def __init__(self, hass, connector, config, code, options, name=None):
self._attr_should_poll = True
self._attr_available = True

self._real_should_poll = True

self.update_option_listener()

@property
Expand Down Expand Up @@ -216,18 +214,12 @@ async def async_update_callback(self, isPush=False):
_force = bool(not self._attr_available and self._server_state["available"])
self._attr_is_on = new_val
self._attr_available = self._server_state["available"]
self._attr_should_poll = (
self._real_should_poll if self._attr_available else False
)
self.async_schedule_update_ha_state(_force)

def update_option_listener(self):
_should_poll = self._code not in self._connector._ntfPropertyMap
self._real_should_poll = (
self._connector._user_options.get(CONF_FORCE_POLLING, False) or _should_poll
)
self._attr_should_poll = (
self._real_should_poll if self._attr_available else False
self._connector._user_options.get(CONF_FORCE_POLLING, False) or _should_poll
)
self._attr_extra_state_attributes = {"notify": "No" if _should_poll else "Yes"}
_LOGGER.debug(
Expand Down
10 changes: 1 addition & 9 deletions custom_components/echonetlite/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ def __init__(self, hass, connector, config, code, options, device_name=None):
self._attr_should_poll = True
self._attr_available = True

self._real_should_poll = True

self.update_option_listener()

@property
Expand Down Expand Up @@ -137,18 +135,12 @@ async def async_update_callback(self, isPush=False):
_force = bool(not self._attr_available and self._server_state["available"])
self._attr_native_value = new_val
self._attr_available = self._server_state["available"]
self._attr_should_poll = (
self._real_should_poll if self._attr_available else False
)
self.async_schedule_update_ha_state(_force)

def update_option_listener(self):
_should_poll = self._code not in self._connector._ntfPropertyMap
self._real_should_poll = (
self._connector._user_options.get(CONF_FORCE_POLLING, False) or _should_poll
)
self._attr_should_poll = (
self._real_should_poll if self._attr_available else False
self._connector._user_options.get(CONF_FORCE_POLLING, False) or _should_poll
)
self._attr_extra_state_attributes = {"notify": "No" if _should_poll else "Yes"}
_LOGGER.debug(
Expand Down

0 comments on commit 0286da5

Please sign in to comment.