Skip to content

Commit

Permalink
Fix opentherm_gw availability (home-assistant#121892)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvn23 authored Jul 15, 2024
1 parent df00e1a commit 894f3fe
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
5 changes: 5 additions & 0 deletions homeassistant/components/opentherm_gw/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,3 +470,8 @@ async def handle_report(status):
async_dispatcher_send(self.hass, self.update_signal, status)

self.gateway.subscribe(handle_report)

@property
def connected(self):
"""Report whether or not we are connected to the gateway."""
return self.gateway.connection.connected
7 changes: 2 additions & 5 deletions homeassistant/components/opentherm_gw/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class OpenThermBinarySensor(BinarySensorEntity):

_attr_should_poll = False
_attr_entity_registry_enabled_default = False
_attr_available = False

def __init__(self, gw_dev, var, source, device_class, friendly_name_format):
"""Initialize the binary sensor."""
Expand Down Expand Up @@ -85,14 +86,10 @@ async def async_will_remove_from_hass(self) -> None:
_LOGGER.debug("Removing OpenTherm Gateway binary sensor %s", self._attr_name)
self._unsub_updates()

@property
def available(self):
"""Return availability of the sensor."""
return self._attr_is_on is not None

@callback
def receive_report(self, status):
"""Handle status updates from the component."""
self._attr_available = self._gateway.connected
state = status[self._source].get(self._var)
self._attr_is_on = None if state is None else bool(state)
self.async_write_ha_state()
2 changes: 1 addition & 1 deletion homeassistant/components/opentherm_gw/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ async def async_will_remove_from_hass(self) -> None:
@callback
def receive_report(self, status):
"""Receive and handle a new report from the Gateway."""
self._attr_available = status != gw_vars.DEFAULT_STATUS
self._attr_available = self._gateway.connected
ch_active = status[gw_vars.BOILER].get(gw_vars.DATA_SLAVE_CH_ACTIVE)
flame_on = status[gw_vars.BOILER].get(gw_vars.DATA_SLAVE_FLAME_ON)
cooling_active = status[gw_vars.BOILER].get(gw_vars.DATA_SLAVE_COOLING_ACTIVE)
Expand Down
7 changes: 2 additions & 5 deletions homeassistant/components/opentherm_gw/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class OpenThermSensor(SensorEntity):

_attr_should_poll = False
_attr_entity_registry_enabled_default = False
_attr_available = False

def __init__(
self,
Expand Down Expand Up @@ -94,14 +95,10 @@ async def async_will_remove_from_hass(self) -> None:
_LOGGER.debug("Removing OpenTherm Gateway sensor %s", self._attr_name)
self._unsub_updates()

@property
def available(self):
"""Return availability of the sensor."""
return self._attr_native_value is not None

@callback
def receive_report(self, status):
"""Handle status updates from the component."""
self._attr_available = self._gateway.connected
value = status[self._source].get(self._var)
self._attr_native_value = value
self.async_write_ha_state()

0 comments on commit 894f3fe

Please sign in to comment.