mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 20:27:08 +00:00
Use device_tracker SourceType enum [a-g] (#75963)
This commit is contained in:
parent
f068fc8eb7
commit
1a8ccfeb56
@ -1,7 +1,7 @@
|
|||||||
"""Support for ASUSWRT routers."""
|
"""Support for ASUSWRT routers."""
|
||||||
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
|
||||||
@ -69,9 +69,9 @@ class AsusWrtDevice(ScannerEntity):
|
|||||||
return self._device.is_connected
|
return self._device.is_connected
|
||||||
|
|
||||||
@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 hostname(self) -> str | None:
|
def hostname(self) -> str | None:
|
||||||
|
@ -16,7 +16,7 @@ from homeassistant.components.device_tracker import (
|
|||||||
from homeassistant.components.device_tracker.const import (
|
from homeassistant.components.device_tracker.const import (
|
||||||
CONF_TRACK_NEW,
|
CONF_TRACK_NEW,
|
||||||
SCAN_INTERVAL,
|
SCAN_INTERVAL,
|
||||||
SOURCE_TYPE_BLUETOOTH_LE,
|
SourceType,
|
||||||
)
|
)
|
||||||
from homeassistant.components.device_tracker.legacy import (
|
from homeassistant.components.device_tracker.legacy import (
|
||||||
YAML_DEVICES,
|
YAML_DEVICES,
|
||||||
@ -106,7 +106,7 @@ async def async_setup_scanner( # noqa: C901
|
|||||||
await async_see(
|
await async_see(
|
||||||
mac=BLE_PREFIX + address,
|
mac=BLE_PREFIX + address,
|
||||||
host_name=name,
|
host_name=name,
|
||||||
source_type=SOURCE_TYPE_BLUETOOTH_LE,
|
source_type=SourceType.BLUETOOTH_LE,
|
||||||
battery=battery,
|
battery=battery,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ from homeassistant.components.device_tracker.const import (
|
|||||||
CONF_TRACK_NEW,
|
CONF_TRACK_NEW,
|
||||||
DEFAULT_TRACK_NEW,
|
DEFAULT_TRACK_NEW,
|
||||||
SCAN_INTERVAL,
|
SCAN_INTERVAL,
|
||||||
SOURCE_TYPE_BLUETOOTH,
|
SourceType,
|
||||||
)
|
)
|
||||||
from homeassistant.components.device_tracker.legacy import (
|
from homeassistant.components.device_tracker.legacy import (
|
||||||
YAML_DEVICES,
|
YAML_DEVICES,
|
||||||
@ -93,7 +93,7 @@ async def see_device(
|
|||||||
mac=f"{BT_PREFIX}{mac}",
|
mac=f"{BT_PREFIX}{mac}",
|
||||||
host_name=device_name,
|
host_name=device_name,
|
||||||
attributes=attributes,
|
attributes=attributes,
|
||||||
source_type=SOURCE_TYPE_BLUETOOTH,
|
source_type=SourceType.BLUETOOTH,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,11 +2,10 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from typing import Literal
|
|
||||||
|
|
||||||
from bimmer_connected.vehicle import MyBMWVehicle
|
from bimmer_connected.vehicle import MyBMWVehicle
|
||||||
|
|
||||||
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
|
||||||
@ -80,6 +79,6 @@ class BMWDeviceTracker(BMWBaseEntity, TrackerEntity):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def source_type(self) -> Literal["gps"]:
|
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 SOURCE_TYPE_GPS
|
return SourceType.GPS
|
||||||
|
@ -7,7 +7,7 @@ from devolo_plc_api.device import Device
|
|||||||
|
|
||||||
from homeassistant.components.device_tracker import (
|
from homeassistant.components.device_tracker import (
|
||||||
DOMAIN as DEVICE_TRACKER_DOMAIN,
|
DOMAIN as DEVICE_TRACKER_DOMAIN,
|
||||||
SOURCE_TYPE_ROUTER,
|
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
|
||||||
@ -149,9 +149,9 @@ class DevoloScannerEntity(CoordinatorEntity, ScannerEntity):
|
|||||||
return self._mac
|
return self._mac
|
||||||
|
|
||||||
@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 unique_id(self) -> str:
|
def unique_id(self) -> str:
|
||||||
|
@ -31,7 +31,7 @@ from homeassistant.components.device_tracker.const import (
|
|||||||
ATTR_SOURCE_TYPE,
|
ATTR_SOURCE_TYPE,
|
||||||
CONNECTED_DEVICE_REGISTERED,
|
CONNECTED_DEVICE_REGISTERED,
|
||||||
DOMAIN as DEVICE_TRACKER_DOMAIN,
|
DOMAIN as DEVICE_TRACKER_DOMAIN,
|
||||||
SOURCE_TYPE_ROUTER,
|
SourceType,
|
||||||
)
|
)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
EVENT_HOMEASSISTANT_STARTED,
|
EVENT_HOMEASSISTANT_STARTED,
|
||||||
@ -318,7 +318,7 @@ class DeviceTrackerWatcher(WatcherBase):
|
|||||||
|
|
||||||
attributes = state.attributes
|
attributes = state.attributes
|
||||||
|
|
||||||
if attributes.get(ATTR_SOURCE_TYPE) != SOURCE_TYPE_ROUTER:
|
if attributes.get(ATTR_SOURCE_TYPE) != SourceType.ROUTER:
|
||||||
return
|
return
|
||||||
|
|
||||||
ip_address = attributes.get(ATTR_IP)
|
ip_address = attributes.get(ATTR_IP)
|
||||||
|
@ -4,7 +4,7 @@ from __future__ import annotations
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
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
|
||||||
@ -98,9 +98,9 @@ class FreeboxDevice(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 icon(self) -> str:
|
def icon(self) -> str:
|
||||||
|
@ -4,7 +4,7 @@ from __future__ import annotations
|
|||||||
import datetime
|
import datetime
|
||||||
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
|
||||||
@ -118,6 +118,6 @@ class FritzBoxTracker(FritzDeviceBase, ScannerEntity):
|
|||||||
return attrs
|
return attrs
|
||||||
|
|
||||||
@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
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
"""Support for the Geofency device tracker platform."""
|
"""Support for the Geofency device tracker platform."""
|
||||||
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.const import ATTR_LATITUDE, ATTR_LONGITUDE
|
from homeassistant.const import ATTR_LATITUDE, ATTR_LONGITUDE
|
||||||
@ -96,9 +96,9 @@ class GeofencyEntity(TrackerEntity, RestoreEntity):
|
|||||||
return DeviceInfo(identifiers={(GF_DOMAIN, self._unique_id)}, name=self._name)
|
return DeviceInfo(identifiers={(GF_DOMAIN, self._unique_id)}, name=self._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 SOURCE_TYPE_GPS
|
return SourceType.GPS
|
||||||
|
|
||||||
async def async_added_to_hass(self):
|
async def async_added_to_hass(self):
|
||||||
"""Register state update callback."""
|
"""Register state update callback."""
|
||||||
|
@ -10,8 +10,8 @@ import voluptuous as vol
|
|||||||
|
|
||||||
from homeassistant.components.device_tracker import (
|
from homeassistant.components.device_tracker import (
|
||||||
PLATFORM_SCHEMA as PLATFORM_SCHEMA_BASE,
|
PLATFORM_SCHEMA as PLATFORM_SCHEMA_BASE,
|
||||||
SOURCE_TYPE_GPS,
|
|
||||||
SeeCallback,
|
SeeCallback,
|
||||||
|
SourceType,
|
||||||
)
|
)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_BATTERY_CHARGING,
|
ATTR_BATTERY_CHARGING,
|
||||||
@ -129,7 +129,7 @@ class GoogleMapsScanner:
|
|||||||
dev_id=dev_id,
|
dev_id=dev_id,
|
||||||
gps=(person.latitude, person.longitude),
|
gps=(person.latitude, person.longitude),
|
||||||
picture=person.picture_url,
|
picture=person.picture_url,
|
||||||
source_type=SOURCE_TYPE_GPS,
|
source_type=SourceType.GPS,
|
||||||
gps_accuracy=person.accuracy,
|
gps_accuracy=person.accuracy,
|
||||||
attributes=attrs,
|
attributes=attrs,
|
||||||
)
|
)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
"""Support for the GPSLogger device tracking."""
|
"""Support for the GPSLogger device tracking."""
|
||||||
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.const import (
|
from homeassistant.const import (
|
||||||
@ -118,9 +118,9 @@ class GPSLoggerEntity(TrackerEntity, RestoreEntity):
|
|||||||
return DeviceInfo(identifiers={(GPL_DOMAIN, self._unique_id)}, name=self._name)
|
return DeviceInfo(identifiers={(GPL_DOMAIN, self._unique_id)}, name=self._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 SOURCE_TYPE_GPS
|
return SourceType.GPS
|
||||||
|
|
||||||
async def async_added_to_hass(self):
|
async def async_added_to_hass(self):
|
||||||
"""Register state update callback."""
|
"""Register state update callback."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user