mirror of
https://github.com/home-assistant/core.git
synced 2026-09-24 23:41:48 -05:00
Type the nmap_tracker device registry with a HassKey (#181102)
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
"""The Nmap Tracker integration."""
|
||||
# pylint: disable=home-assistant-use-runtime-data # Uses legacy hass.data[DOMAIN] pattern
|
||||
|
||||
import asyncio
|
||||
from dataclasses import dataclass
|
||||
@@ -33,7 +32,7 @@ from .const import (
|
||||
CONF_MAC_EXCLUDE,
|
||||
CONF_OPTIONS,
|
||||
DOMAIN,
|
||||
NMAP_TRACKED_DEVICES,
|
||||
NMAP_TRACKER_DATA,
|
||||
PLATFORMS,
|
||||
TRACKER_SCAN_INTERVAL,
|
||||
)
|
||||
@@ -90,8 +89,8 @@ _LOGGER = logging.getLogger(__name__)
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: NmapTrackerConfigEntry) -> bool:
|
||||
"""Set up Nmap Tracker from a config entry."""
|
||||
domain_data = hass.data.setdefault(DOMAIN, {})
|
||||
devices = domain_data.setdefault(NMAP_TRACKED_DEVICES, NmapTrackedDevices())
|
||||
if (devices := hass.data.get(NMAP_TRACKER_DATA)) is None:
|
||||
devices = hass.data[NMAP_TRACKER_DATA] = NmapTrackedDevices()
|
||||
scanner = NmapDeviceScanner(hass, entry, devices)
|
||||
await scanner.async_setup()
|
||||
entry.runtime_data = scanner
|
||||
@@ -144,9 +143,7 @@ async def async_migrate_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
@callback
|
||||
def _async_untrack_devices(hass: HomeAssistant, entry: ConfigEntry) -> None:
|
||||
"""Remove tracking for devices owned by this config entry."""
|
||||
# Uses legacy hass.data[DOMAIN] pattern
|
||||
# pylint: disable-next=home-assistant-use-runtime-data
|
||||
devices = hass.data[DOMAIN][NMAP_TRACKED_DEVICES]
|
||||
devices = hass.data[NMAP_TRACKER_DATA]
|
||||
remove_mac_addresses = [
|
||||
mac_address
|
||||
for mac_address, entry_id in devices.config_entry_owner.items()
|
||||
|
||||
@@ -1,14 +1,20 @@
|
||||
"""The Nmap Tracker integration."""
|
||||
|
||||
from typing import Final
|
||||
from typing import TYPE_CHECKING, Final
|
||||
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.util.hass_dict import HassKey
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from . import NmapTrackedDevices
|
||||
|
||||
DOMAIN: Final = "nmap_tracker"
|
||||
|
||||
PLATFORMS: Final = [Platform.DEVICE_TRACKER]
|
||||
|
||||
NMAP_TRACKED_DEVICES: Final = "nmap_tracked_devices"
|
||||
# Tracked devices are keyed by MAC across every config entry, so the registry
|
||||
# is shared rather than owned by any one entry.
|
||||
NMAP_TRACKER_DATA: HassKey[NmapTrackedDevices] = HassKey(DOMAIN)
|
||||
|
||||
# Interval in minutes to exclude devices from a scan while they are home
|
||||
CONF_HOME_INTERVAL: Final = "home_interval"
|
||||
|
||||
Reference in New Issue
Block a user