diff --git a/custom_components/danfoss_ally/__init__.py b/custom_components/danfoss_ally/__init__.py index c9025d0..e6b819a 100644 --- a/custom_components/danfoss_ally/__init__.py +++ b/custom_components/danfoss_ally/__init__.py @@ -10,7 +10,7 @@ from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry from homeassistant.core import HomeAssistant, callback from homeassistant.exceptions import ConfigEntryNotReady -from homeassistant.helpers import config_validation as cv +from homeassistant.helpers import config_validation as cv, device_registry as dr from homeassistant.helpers.dispatcher import dispatcher_send from homeassistant.helpers.event import async_track_time_interval from homeassistant.util import Throttle @@ -124,6 +124,23 @@ async def _update(now): await _update(None) + # Remove old devices + if allyconnector.ally.devices is not None and len(allyconnector.ally.devices) > 0: + # Build list of devices to keep + devices = [] + for device in allyconnector.ally.devices: + devices.append((DOMAIN, device)) + + # Remove devices no longr reported by the API + device_registry = dr.async_get(hass) + for device_entry in dr.async_entries_for_config_entry( + device_registry, entry.entry_id + ): + for identifier in device_entry.identifiers: + if identifier not in devices: + _LOGGER.warning("Removing device: %s", identifier) + device_registry.async_remove_device(device_entry.id) + update_track = async_track_time_interval( hass, _update, diff --git a/custom_components/danfoss_ally/sensor.py b/custom_components/danfoss_ally/sensor.py index 3e56036..cfa8c22 100644 --- a/custom_components/danfoss_ally/sensor.py +++ b/custom_components/danfoss_ally/sensor.py @@ -201,3 +201,7 @@ def _async_update_data(self): self._attr_native_value = self._device["ext_measured_rs"] elif self._type in self._device: self._attr_native_value = self._device[self._type] + + # Make external sensor temperature unavailable if value is -80 (feature disabled value) + if self.entity_description.key == AllySensorType.EXTERNAL_SENSOR_TEMPERATURE: + self._attr_available = self._attr_native_value != float(-80)