Skip to content

Commit

Permalink
Fix restoring state
Browse files Browse the repository at this point in the history
Device registry was getting cleared, so find dev_ids from entity registry instead.
  • Loading branch information
pnbruckner committed Jan 20, 2024
1 parent c5c1294 commit d426424
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions custom_components/gpslogger/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
ATTR_LONGITUDE,
)
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import device_registry as dr
from homeassistant.helpers import entity_registry as er
from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity_platform import AddEntitiesCallback
Expand Down Expand Up @@ -53,12 +53,10 @@ def _receive_data(device, gps, battery, accuracy, attrs):
entry.async_on_unload(async_dispatcher_connect(hass, TRACKER_UPDATE, _receive_data))

# Restore previously loaded devices
dev_reg = dr.async_get(hass)
ent_reg = er.async_get(hass)
dev_ids = {
identifier[1]
for device in dev_reg.devices.values()
for identifier in device.identifiers
if identifier[0] == GPL_DOMAIN
entity.unique_id
for entity in er.async_entries_for_config_entry(ent_reg, entry.entry_id)
}
if not dev_ids:
return
Expand Down

0 comments on commit d426424

Please sign in to comment.