From 58ae117bb415e949a65d61abe3b1a19bca9ebca0 Mon Sep 17 00:00:00 2001 From: mvn23 Date: Thu, 2 Apr 2020 11:28:39 +0200 Subject: [PATCH] Add availability to opentherm_gw entities (#32408) * Add availability to opentherm_gw entities * Address PR comment --- homeassistant/components/opentherm_gw/binary_sensor.py | 8 +++++++- homeassistant/components/opentherm_gw/climate.py | 7 +++++++ homeassistant/components/opentherm_gw/sensor.py | 5 +++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/opentherm_gw/binary_sensor.py b/homeassistant/components/opentherm_gw/binary_sensor.py index 663635cd06a..62c0d3dd2c1 100644 --- a/homeassistant/components/opentherm_gw/binary_sensor.py +++ b/homeassistant/components/opentherm_gw/binary_sensor.py @@ -60,6 +60,11 @@ class OpenThermBinarySensor(BinarySensorDevice): ) self._unsub_updates() + @property + def available(self): + """Return availability of the sensor.""" + return self._state is not None + @property def entity_registry_enabled_default(self): """Disable binary_sensors by default.""" @@ -68,7 +73,8 @@ class OpenThermBinarySensor(BinarySensorDevice): @callback def receive_report(self, status): """Handle status updates from the component.""" - self._state = bool(status.get(self._var)) + state = status.get(self._var) + self._state = None if state is None else bool(state) self.async_write_ha_state() @property diff --git a/homeassistant/components/opentherm_gw/climate.py b/homeassistant/components/opentherm_gw/climate.py index b447018e799..a7e7eedef34 100644 --- a/homeassistant/components/opentherm_gw/climate.py +++ b/homeassistant/components/opentherm_gw/climate.py @@ -63,6 +63,7 @@ class OpenThermClimate(ClimateDevice): self.friendly_name = gw_dev.name self.floor_temp = options.get(CONF_FLOOR_TEMP, DEFAULT_FLOOR_TEMP) self.temp_precision = options.get(CONF_PRECISION, DEFAULT_PRECISION) + self._available = False self._current_operation = None self._current_temperature = None self._hvac_mode = HVAC_MODE_HEAT @@ -101,6 +102,7 @@ class OpenThermClimate(ClimateDevice): @callback def receive_report(self, status): """Receive and handle a new report from the Gateway.""" + self._available = bool(status) ch_active = status.get(gw_vars.DATA_SLAVE_CH_ACTIVE) flame_on = status.get(gw_vars.DATA_SLAVE_FLAME_ON) cooling_active = status.get(gw_vars.DATA_SLAVE_COOLING_ACTIVE) @@ -146,6 +148,11 @@ class OpenThermClimate(ClimateDevice): ) self.async_write_ha_state() + @property + def available(self): + """Return availability of the sensor.""" + return self._available + @property def name(self): """Return the friendly name.""" diff --git a/homeassistant/components/opentherm_gw/sensor.py b/homeassistant/components/opentherm_gw/sensor.py index c82cf14228b..b2f8e272983 100644 --- a/homeassistant/components/opentherm_gw/sensor.py +++ b/homeassistant/components/opentherm_gw/sensor.py @@ -61,6 +61,11 @@ class OpenThermSensor(Entity): _LOGGER.debug("Removing OpenTherm Gateway sensor %s", self._friendly_name) self._unsub_updates() + @property + def available(self): + """Return availability of the sensor.""" + return self._value is not None + @property def entity_registry_enabled_default(self): """Disable sensors by default."""