updated entity registry access, fixes #209

This commit is contained in:
Tomaae 2022-06-25 13:55:46 +02:00
parent bd56487f42
commit 085a859dd7
No known key found for this signature in database
GPG key ID: 8360BBD8A381D1C0

View file

@ -13,8 +13,8 @@ from mac_vendor_lookup import AsyncMacLookup
from homeassistant.core import callback from homeassistant.core import callback
from homeassistant.helpers.dispatcher import async_dispatcher_send from homeassistant.helpers.dispatcher import async_dispatcher_send
from homeassistant.helpers.event import async_track_time_interval from homeassistant.helpers.event import async_track_time_interval
from homeassistant.helpers import entity_registry
from homeassistant.util.dt import utcnow from homeassistant.util.dt import utcnow
from homeassistant.components.device_tracker import DOMAIN as DEVICE_TRACKER_DOMAIN
from homeassistant.const import ( from homeassistant.const import (
CONF_NAME, CONF_NAME,
@ -453,15 +453,13 @@ class MikrotikControllerData:
# --------------------------- # ---------------------------
async def async_get_host_hass(self): async def async_get_host_hass(self):
"""Get host data from HA entity registry""" """Get host data from HA entity registry"""
registry = await self.hass.helpers.entity_registry.async_get_registry() registry = entity_registry.async_get(self.hass)
for entity in registry.entities.values(): for entity in registry.entities.values():
if ( if (
entity.config_entry_id == self.config_entry.entry_id entity.config_entry_id == self.config_entry.entry_id
and entity.domain == DEVICE_TRACKER_DOMAIN and entity.entity_id.startswith("device_tracker.")
and "-host-" in entity.unique_id
): ):
_, mac = entity.unique_id.split("-host-", 2) self.data["host_hass"][entity.unique_id.upper()] = entity.original_name
self.data["host_hass"][mac] = entity.original_name
# --------------------------- # ---------------------------
# async_hwinfo_update # async_hwinfo_update