mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +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
|
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.components.device_tracker.config_entry import ScannerEntity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
@ -79,9 +79,9 @@ class NetgearScannerEntity(NetgearBaseEntity, ScannerEntity):
|
|||||||
return self._active
|
return self._active
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def source_type(self) -> str:
|
def source_type(self) -> SourceType:
|
||||||
"""Return the source type."""
|
"""Return the source type."""
|
||||||
return SOURCE_TYPE_ROUTER
|
return SourceType.ROUTER
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def ip_address(self) -> str:
|
def ip_address(self) -> str:
|
||||||
|
@ -4,7 +4,7 @@ from __future__ import annotations
|
|||||||
import logging
|
import logging
|
||||||
from typing import Any
|
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.components.device_tracker.config_entry import ScannerEntity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
@ -93,9 +93,9 @@ class NmapTrackerEntity(ScannerEntity):
|
|||||||
return short_hostname(self._device.hostname)
|
return short_hostname(self._device.hostname)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def source_type(self) -> str:
|
def source_type(self) -> SourceType:
|
||||||
"""Return tracker source type."""
|
"""Return tracker source type."""
|
||||||
return SOURCE_TYPE_ROUTER
|
return SourceType.ROUTER
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def should_poll(self) -> bool:
|
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 (
|
from homeassistant.components.device_tracker.const import (
|
||||||
ATTR_SOURCE_TYPE,
|
ATTR_SOURCE_TYPE,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
SOURCE_TYPE_GPS,
|
SourceType,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
@ -115,9 +115,9 @@ class OwnTracksEntity(TrackerEntity, RestoreEntity):
|
|||||||
return self._data.get("host_name")
|
return self._data.get("host_name")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def source_type(self):
|
def source_type(self) -> SourceType:
|
||||||
"""Return the source type, eg gps or router, of the device."""
|
"""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
|
@property
|
||||||
def device_info(self) -> DeviceInfo:
|
def device_info(self) -> DeviceInfo:
|
||||||
|
@ -6,10 +6,7 @@ from nacl.encoding import Base64Encoder
|
|||||||
from nacl.secret import SecretBox
|
from nacl.secret import SecretBox
|
||||||
|
|
||||||
from homeassistant.components import zone as zone_comp
|
from homeassistant.components import zone as zone_comp
|
||||||
from homeassistant.components.device_tracker import (
|
from homeassistant.components.device_tracker import SourceType
|
||||||
SOURCE_TYPE_BLUETOOTH_LE,
|
|
||||||
SOURCE_TYPE_GPS,
|
|
||||||
)
|
|
||||||
from homeassistant.const import ATTR_LATITUDE, ATTR_LONGITUDE, STATE_HOME
|
from homeassistant.const import ATTR_LATITUDE, ATTR_LONGITUDE, STATE_HOME
|
||||||
from homeassistant.util import decorator, slugify
|
from homeassistant.util import decorator, slugify
|
||||||
|
|
||||||
@ -84,9 +81,9 @@ def _parse_see_args(message, subscribe_topic):
|
|||||||
kwargs["attributes"]["battery_status"] = message["bs"]
|
kwargs["attributes"]["battery_status"] = message["bs"]
|
||||||
if "t" in message:
|
if "t" in message:
|
||||||
if message["t"] in ("c", "u"):
|
if message["t"] in ("c", "u"):
|
||||||
kwargs["source_type"] = SOURCE_TYPE_GPS
|
kwargs["source_type"] = SourceType.GPS
|
||||||
if message["t"] == "b":
|
if message["t"] == "b":
|
||||||
kwargs["source_type"] = SOURCE_TYPE_BLUETOOTH_LE
|
kwargs["source_type"] = SourceType.BLUETOOTH_LE
|
||||||
|
|
||||||
return dev_id, kwargs
|
return dev_id, kwargs
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ from homeassistant.components import persistent_notification, websocket_api
|
|||||||
from homeassistant.components.device_tracker import (
|
from homeassistant.components.device_tracker import (
|
||||||
ATTR_SOURCE_TYPE,
|
ATTR_SOURCE_TYPE,
|
||||||
DOMAIN as DEVICE_TRACKER_DOMAIN,
|
DOMAIN as DEVICE_TRACKER_DOMAIN,
|
||||||
SOURCE_TYPE_GPS,
|
SourceType,
|
||||||
)
|
)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_EDITABLE,
|
ATTR_EDITABLE,
|
||||||
@ -469,7 +469,7 @@ class Person(RestoreEntity):
|
|||||||
if not state or state.state in IGNORE_STATES:
|
if not state or state.state in IGNORE_STATES:
|
||||||
continue
|
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)
|
latest_gps = _get_latest(latest_gps, state)
|
||||||
elif state.state == STATE_HOME:
|
elif state.state == STATE_HOME:
|
||||||
latest_non_gps_home = _get_latest(latest_non_gps_home, state)
|
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 (
|
from homeassistant.components.device_tracker.const import (
|
||||||
CONF_SCAN_INTERVAL,
|
CONF_SCAN_INTERVAL,
|
||||||
SCAN_INTERVAL,
|
SCAN_INTERVAL,
|
||||||
SOURCE_TYPE_ROUTER,
|
SourceType,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
@ -114,7 +114,7 @@ async def async_setup_scanner(
|
|||||||
)
|
)
|
||||||
await asyncio.gather(
|
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)
|
for idx, host in enumerate(hosts)
|
||||||
if results[idx]
|
if results[idx]
|
||||||
)
|
)
|
||||||
@ -133,7 +133,7 @@ async def async_setup_scanner(
|
|||||||
_LOGGER.debug("Multiping responses: %s", responses)
|
_LOGGER.debug("Multiping responses: %s", responses)
|
||||||
await asyncio.gather(
|
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())
|
for idx, dev_id in enumerate(ip_to_dev_id.values())
|
||||||
if responses[idx].is_alive
|
if responses[idx].is_alive
|
||||||
)
|
)
|
||||||
|
@ -3,7 +3,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from renault_api.kamereon.models import KamereonVehicleLocationData
|
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.components.device_tracker.config_entry import TrackerEntity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
@ -46,9 +46,9 @@ class RenaultDeviceTracker(
|
|||||||
return self.coordinator.data.gpsLongitude if self.coordinator.data else None
|
return self.coordinator.data.gpsLongitude if self.coordinator.data else None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def source_type(self) -> str:
|
def source_type(self) -> SourceType:
|
||||||
"""Return the source type of the device."""
|
"""Return the source type of the device."""
|
||||||
return SOURCE_TYPE_GPS
|
return SourceType.GPS
|
||||||
|
|
||||||
|
|
||||||
DEVICE_TRACKER_TYPES: tuple[RenaultDataEntityDescription, ...] = (
|
DEVICE_TRACKER_TYPES: tuple[RenaultDataEntityDescription, ...] = (
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
"""Support for Ruckus Unleashed devices."""
|
"""Support for Ruckus Unleashed devices."""
|
||||||
from __future__ import annotations
|
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.components.device_tracker.config_entry import ScannerEntity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
@ -111,6 +111,6 @@ class RuckusUnleashedDevice(CoordinatorEntity, ScannerEntity):
|
|||||||
return self._mac in self.coordinator.data[API_CLIENTS]
|
return self._mac in self.coordinator.data[API_CLIENTS]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def source_type(self) -> str:
|
def source_type(self) -> SourceType:
|
||||||
"""Return the source type."""
|
"""Return the source type."""
|
||||||
return SOURCE_TYPE_ROUTER
|
return SourceType.ROUTER
|
||||||
|
Loading…
x
Reference in New Issue
Block a user