mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Use device_tracker SourceType enum [n-r] (#75965)
This commit is contained in:
parent
c9ddb10024
commit
450b7cd644
@ -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:
|
||||
|
@ -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:
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
)
|
||||
|
@ -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, ...] = (
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user