Skip to content

Commit

Permalink
Merge pull request #73 from jnxxx/Updates
Browse files Browse the repository at this point in the history
Two small updates
  • Loading branch information
MTrab committed Oct 7, 2023
2 parents c963564 + f01784c commit f8c57cf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
19 changes: 18 additions & 1 deletion custom_components/danfoss_ally/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions custom_components/danfoss_ally/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit f8c57cf

Please sign in to comment.