diff --git a/homeassistant/components/miflora/sensor.py b/homeassistant/components/miflora/sensor.py index a08c4ce5eacbe4..815a6e97bb8c0b 100644 --- a/homeassistant/components/miflora/sensor.py +++ b/homeassistant/components/miflora/sensor.py @@ -106,6 +106,7 @@ def __init__(self, poller, parameter, name, unit, icon, force_update, median): self._icon = icon self._name = name self._state = None + self._available = False self.data = [] self._force_update = force_update # Median is used to filter out outliers. median of 3 will filter @@ -132,6 +133,11 @@ def state(self): """Return the state of the sensor.""" return self._state + @property + def available(self): + """Return True if entity is available.""" + return self._available + @property def unit_of_measurement(self): """Return the units of measurement.""" @@ -156,15 +162,14 @@ def update(self): try: _LOGGER.debug("Polling data for %s", self.name) data = self.poller.parameter_value(self.parameter) - except OSError as ioerr: - _LOGGER.info("Polling error %s", ioerr) - return - except BluetoothBackendException as bterror: - _LOGGER.info("Polling error %s", bterror) + except (OSError, BluetoothBackendException) as err: + _LOGGER.info("Polling error %s: %s", type(err).__name__, err) + self._available = False return if data is not None: _LOGGER.debug("%s = %s", self.name, data) + self._available = True self.data.append(data) else: _LOGGER.info("Did not receive any data from Mi Flora sensor %s", self.name)