From 450b7cd6443a9547c4c3273816adedc9b7232d37 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Sun, 31 Jul 2022 15:48:43 +0200 Subject: [PATCH] Use device_tracker SourceType enum [n-r] (#75965) --- homeassistant/components/netgear/device_tracker.py | 6 +++--- homeassistant/components/nmap_tracker/device_tracker.py | 6 +++--- homeassistant/components/owntracks/device_tracker.py | 6 +++--- homeassistant/components/owntracks/messages.py | 9 +++------ homeassistant/components/person/__init__.py | 4 ++-- homeassistant/components/ping/device_tracker.py | 6 +++--- homeassistant/components/renault/device_tracker.py | 6 +++--- .../components/ruckus_unleashed/device_tracker.py | 6 +++--- 8 files changed, 23 insertions(+), 26 deletions(-) diff --git a/homeassistant/components/netgear/device_tracker.py b/homeassistant/components/netgear/device_tracker.py index 0f7f5cffb10..cd648990e05 100644 --- a/homeassistant/components/netgear/device_tracker.py +++ b/homeassistant/components/netgear/device_tracker.py @@ -3,7 +3,7 @@ from __future__ import annotations import logging -from homeassistant.components.device_tracker import SOURCE_TYPE_ROUTER +from homeassistant.components.device_tracker import SourceType from homeassistant.components.device_tracker.config_entry import ScannerEntity from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant, callback @@ -79,9 +79,9 @@ class NetgearScannerEntity(NetgearBaseEntity, ScannerEntity): return self._active @property - def source_type(self) -> str: + def source_type(self) -> SourceType: """Return the source type.""" - return SOURCE_TYPE_ROUTER + return SourceType.ROUTER @property def ip_address(self) -> str: diff --git a/homeassistant/components/nmap_tracker/device_tracker.py b/homeassistant/components/nmap_tracker/device_tracker.py index 36a461c4891..afb931b82dd 100644 --- a/homeassistant/components/nmap_tracker/device_tracker.py +++ b/homeassistant/components/nmap_tracker/device_tracker.py @@ -4,7 +4,7 @@ from __future__ import annotations import logging from typing import Any -from homeassistant.components.device_tracker import SOURCE_TYPE_ROUTER +from homeassistant.components.device_tracker import SourceType from homeassistant.components.device_tracker.config_entry import ScannerEntity from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant, callback @@ -93,9 +93,9 @@ class NmapTrackerEntity(ScannerEntity): return short_hostname(self._device.hostname) @property - def source_type(self) -> str: + def source_type(self) -> SourceType: """Return tracker source type.""" - return SOURCE_TYPE_ROUTER + return SourceType.ROUTER @property def should_poll(self) -> bool: diff --git a/homeassistant/components/owntracks/device_tracker.py b/homeassistant/components/owntracks/device_tracker.py index 92f34617462..5119168e7ae 100644 --- a/homeassistant/components/owntracks/device_tracker.py +++ b/homeassistant/components/owntracks/device_tracker.py @@ -3,7 +3,7 @@ from homeassistant.components.device_tracker.config_entry import TrackerEntity from homeassistant.components.device_tracker.const import ( ATTR_SOURCE_TYPE, DOMAIN, - SOURCE_TYPE_GPS, + SourceType, ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( @@ -115,9 +115,9 @@ class OwnTracksEntity(TrackerEntity, RestoreEntity): return self._data.get("host_name") @property - def source_type(self): + def source_type(self) -> SourceType: """Return the source type, eg gps or router, of the device.""" - return self._data.get("source_type", SOURCE_TYPE_GPS) + return self._data.get("source_type", SourceType.GPS) @property def device_info(self) -> DeviceInfo: diff --git a/homeassistant/components/owntracks/messages.py b/homeassistant/components/owntracks/messages.py index 4f17c8a5375..cd474054029 100644 --- a/homeassistant/components/owntracks/messages.py +++ b/homeassistant/components/owntracks/messages.py @@ -6,10 +6,7 @@ from nacl.encoding import Base64Encoder from nacl.secret import SecretBox from homeassistant.components import zone as zone_comp -from homeassistant.components.device_tracker import ( - SOURCE_TYPE_BLUETOOTH_LE, - SOURCE_TYPE_GPS, -) +from homeassistant.components.device_tracker import SourceType from homeassistant.const import ATTR_LATITUDE, ATTR_LONGITUDE, STATE_HOME from homeassistant.util import decorator, slugify @@ -84,9 +81,9 @@ def _parse_see_args(message, subscribe_topic): kwargs["attributes"]["battery_status"] = message["bs"] if "t" in message: if message["t"] in ("c", "u"): - kwargs["source_type"] = SOURCE_TYPE_GPS + kwargs["source_type"] = SourceType.GPS if message["t"] == "b": - kwargs["source_type"] = SOURCE_TYPE_BLUETOOTH_LE + kwargs["source_type"] = SourceType.BLUETOOTH_LE return dev_id, kwargs diff --git a/homeassistant/components/person/__init__.py b/homeassistant/components/person/__init__.py index 12ee0da3b82..85a6cf6135e 100644 --- a/homeassistant/components/person/__init__.py +++ b/homeassistant/components/person/__init__.py @@ -11,7 +11,7 @@ from homeassistant.components import persistent_notification, websocket_api from homeassistant.components.device_tracker import ( ATTR_SOURCE_TYPE, DOMAIN as DEVICE_TRACKER_DOMAIN, - SOURCE_TYPE_GPS, + SourceType, ) from homeassistant.const import ( ATTR_EDITABLE, @@ -469,7 +469,7 @@ class Person(RestoreEntity): if not state or state.state in IGNORE_STATES: continue - if state.attributes.get(ATTR_SOURCE_TYPE) == SOURCE_TYPE_GPS: + if state.attributes.get(ATTR_SOURCE_TYPE) == SourceType.GPS: latest_gps = _get_latest(latest_gps, state) elif state.state == STATE_HOME: latest_non_gps_home = _get_latest(latest_non_gps_home, state) diff --git a/homeassistant/components/ping/device_tracker.py b/homeassistant/components/ping/device_tracker.py index cbce224a373..52285350cd4 100644 --- a/homeassistant/components/ping/device_tracker.py +++ b/homeassistant/components/ping/device_tracker.py @@ -17,7 +17,7 @@ from homeassistant.components.device_tracker import ( from homeassistant.components.device_tracker.const import ( CONF_SCAN_INTERVAL, SCAN_INTERVAL, - SOURCE_TYPE_ROUTER, + SourceType, ) from homeassistant.core import HomeAssistant import homeassistant.helpers.config_validation as cv @@ -114,7 +114,7 @@ async def async_setup_scanner( ) await asyncio.gather( *( - async_see(dev_id=host.dev_id, source_type=SOURCE_TYPE_ROUTER) + async_see(dev_id=host.dev_id, source_type=SourceType.ROUTER) for idx, host in enumerate(hosts) if results[idx] ) @@ -133,7 +133,7 @@ async def async_setup_scanner( _LOGGER.debug("Multiping responses: %s", responses) await asyncio.gather( *( - async_see(dev_id=dev_id, source_type=SOURCE_TYPE_ROUTER) + async_see(dev_id=dev_id, source_type=SourceType.ROUTER) for idx, dev_id in enumerate(ip_to_dev_id.values()) if responses[idx].is_alive ) diff --git a/homeassistant/components/renault/device_tracker.py b/homeassistant/components/renault/device_tracker.py index 3e9a2608f80..da267277d10 100644 --- a/homeassistant/components/renault/device_tracker.py +++ b/homeassistant/components/renault/device_tracker.py @@ -3,7 +3,7 @@ from __future__ import annotations from renault_api.kamereon.models import KamereonVehicleLocationData -from homeassistant.components.device_tracker import SOURCE_TYPE_GPS +from homeassistant.components.device_tracker import SourceType from homeassistant.components.device_tracker.config_entry import TrackerEntity from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant @@ -46,9 +46,9 @@ class RenaultDeviceTracker( return self.coordinator.data.gpsLongitude if self.coordinator.data else None @property - def source_type(self) -> str: + def source_type(self) -> SourceType: """Return the source type of the device.""" - return SOURCE_TYPE_GPS + return SourceType.GPS DEVICE_TRACKER_TYPES: tuple[RenaultDataEntityDescription, ...] = ( diff --git a/homeassistant/components/ruckus_unleashed/device_tracker.py b/homeassistant/components/ruckus_unleashed/device_tracker.py index 67c86f3bb51..8c3e78ae479 100644 --- a/homeassistant/components/ruckus_unleashed/device_tracker.py +++ b/homeassistant/components/ruckus_unleashed/device_tracker.py @@ -1,7 +1,7 @@ """Support for Ruckus Unleashed devices.""" from __future__ import annotations -from homeassistant.components.device_tracker import SOURCE_TYPE_ROUTER +from homeassistant.components.device_tracker import SourceType from homeassistant.components.device_tracker.config_entry import ScannerEntity from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant, callback @@ -111,6 +111,6 @@ class RuckusUnleashedDevice(CoordinatorEntity, ScannerEntity): return self._mac in self.coordinator.data[API_CLIENTS] @property - def source_type(self) -> str: + def source_type(self) -> SourceType: """Return the source type.""" - return SOURCE_TYPE_ROUTER + return SourceType.ROUTER