From c427eb4624bbc2d5cd92a39729430f050439ef89 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Thu, 28 Jul 2022 21:05:02 +0200 Subject: [PATCH] Use device_tracker SourceType enum [n-r] --- 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 0f7f5cffb100c..cd648990e05d6 100644 --- a/homeassistant/components/netgear/device_tracker.py +++ b/homeassistant/components/netgear/device_tracker.py @@ -3,7 +3,7 @@ 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 @@ def is_connected(self) -> bool: 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 36a461c489109..afb931b82dd50 100644 --- a/homeassistant/components/nmap_tracker/device_tracker.py +++ b/homeassistant/components/nmap_tracker/device_tracker.py @@ -4,7 +4,7 @@ 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 @@ def hostname(self) -> str | None: 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 92f3461746206..5119168e7aee5 100644 --- a/homeassistant/components/owntracks/device_tracker.py +++ b/homeassistant/components/owntracks/device_tracker.py @@ -3,7 +3,7 @@ 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 @@ def name(self): 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 4f17c8a53755c..cd4740540294f 100644 --- a/homeassistant/components/owntracks/messages.py +++ b/homeassistant/components/owntracks/messages.py @@ -6,10 +6,7 @@ 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 12ee0da3b829b..85a6cf6135e2a 100644 --- a/homeassistant/components/person/__init__.py +++ b/homeassistant/components/person/__init__.py @@ -11,7 +11,7 @@ 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 @@ def _update_state(self): 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 cbce224a373bb..52285350cd4d5 100644 --- a/homeassistant/components/ping/device_tracker.py +++ b/homeassistant/components/ping/device_tracker.py @@ -17,7 +17,7 @@ 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_update(now): ) 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_update(now): _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 3e9a2608f8020..da267277d106e 100644 --- a/homeassistant/components/renault/device_tracker.py +++ b/homeassistant/components/renault/device_tracker.py @@ -3,7 +3,7 @@ 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 @@ def longitude(self) -> float | None: 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 67c86f3bb516b..8c3e78ae479e0 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 @@ def is_connected(self) -> bool: 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