Use device_tracker SourceType enum [a-g] (#75963)

This commit is contained in:
Marc Mueller 2022-07-31 15:51:04 +02:00 committed by GitHub
parent f068fc8eb7
commit 1a8ccfeb56
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 29 additions and 30 deletions

View file

@ -1,7 +1,7 @@
"""Support for ASUSWRT routers."""
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
@ -69,9 +69,9 @@ class AsusWrtDevice(ScannerEntity):
return self._device.is_connected
@property
def source_type(self) -> str:
def source_type(self) -> SourceType:
"""Return the source type."""
return SOURCE_TYPE_ROUTER
return SourceType.ROUTER
@property
def hostname(self) -> str | None:

View file

@ -16,7 +16,7 @@ from homeassistant.components.device_tracker import (
from homeassistant.components.device_tracker.const import (
CONF_TRACK_NEW,
SCAN_INTERVAL,
SOURCE_TYPE_BLUETOOTH_LE,
SourceType,
)
from homeassistant.components.device_tracker.legacy import (
YAML_DEVICES,
@ -106,7 +106,7 @@ async def async_setup_scanner( # noqa: C901
await async_see(
mac=BLE_PREFIX + address,
host_name=name,
source_type=SOURCE_TYPE_BLUETOOTH_LE,
source_type=SourceType.BLUETOOTH_LE,
battery=battery,
)

View file

@ -19,7 +19,7 @@ from homeassistant.components.device_tracker.const import (
CONF_TRACK_NEW,
DEFAULT_TRACK_NEW,
SCAN_INTERVAL,
SOURCE_TYPE_BLUETOOTH,
SourceType,
)
from homeassistant.components.device_tracker.legacy import (
YAML_DEVICES,
@ -93,7 +93,7 @@ async def see_device(
mac=f"{BT_PREFIX}{mac}",
host_name=device_name,
attributes=attributes,
source_type=SOURCE_TYPE_BLUETOOTH,
source_type=SourceType.BLUETOOTH,
)

View file

@ -2,11 +2,10 @@
from __future__ import annotations
import logging
from typing import Literal
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.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
@ -80,6 +79,6 @@ class BMWDeviceTracker(BMWBaseEntity, TrackerEntity):
)
@property
def source_type(self) -> Literal["gps"]:
def source_type(self) -> SourceType:
"""Return the source type, eg gps or router, of the device."""
return SOURCE_TYPE_GPS
return SourceType.GPS

View file

@ -7,7 +7,7 @@ from devolo_plc_api.device import Device
from homeassistant.components.device_tracker import (
DOMAIN as DEVICE_TRACKER_DOMAIN,
SOURCE_TYPE_ROUTER,
SourceType,
)
from homeassistant.components.device_tracker.config_entry import ScannerEntity
from homeassistant.config_entries import ConfigEntry
@ -149,9 +149,9 @@ class DevoloScannerEntity(CoordinatorEntity, ScannerEntity):
return self._mac
@property
def source_type(self) -> str:
def source_type(self) -> SourceType:
"""Return tracker source type."""
return SOURCE_TYPE_ROUTER
return SourceType.ROUTER
@property
def unique_id(self) -> str:

View file

@ -31,7 +31,7 @@ from homeassistant.components.device_tracker.const import (
ATTR_SOURCE_TYPE,
CONNECTED_DEVICE_REGISTERED,
DOMAIN as DEVICE_TRACKER_DOMAIN,
SOURCE_TYPE_ROUTER,
SourceType,
)
from homeassistant.const import (
EVENT_HOMEASSISTANT_STARTED,
@ -318,7 +318,7 @@ class DeviceTrackerWatcher(WatcherBase):
attributes = state.attributes
if attributes.get(ATTR_SOURCE_TYPE) != SOURCE_TYPE_ROUTER:
if attributes.get(ATTR_SOURCE_TYPE) != SourceType.ROUTER:
return
ip_address = attributes.get(ATTR_IP)

View file

@ -4,7 +4,7 @@ from __future__ import annotations
from datetime import datetime
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
@ -98,9 +98,9 @@ class FreeboxDevice(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 icon(self) -> str:

View file

@ -4,7 +4,7 @@ from __future__ import annotations
import datetime
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
@ -118,6 +118,6 @@ class FritzBoxTracker(FritzDeviceBase, ScannerEntity):
return attrs
@property
def source_type(self) -> str:
def source_type(self) -> SourceType:
"""Return tracker source type."""
return SOURCE_TYPE_ROUTER
return SourceType.ROUTER

View file

@ -1,5 +1,5 @@
"""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.config_entries import ConfigEntry
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)
@property
def source_type(self):
def source_type(self) -> SourceType:
"""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):
"""Register state update callback."""

View file

@ -10,8 +10,8 @@ import voluptuous as vol
from homeassistant.components.device_tracker import (
PLATFORM_SCHEMA as PLATFORM_SCHEMA_BASE,
SOURCE_TYPE_GPS,
SeeCallback,
SourceType,
)
from homeassistant.const import (
ATTR_BATTERY_CHARGING,
@ -129,7 +129,7 @@ class GoogleMapsScanner:
dev_id=dev_id,
gps=(person.latitude, person.longitude),
picture=person.picture_url,
source_type=SOURCE_TYPE_GPS,
source_type=SourceType.GPS,
gps_accuracy=person.accuracy,
attributes=attrs,
)

View file

@ -1,5 +1,5 @@
"""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.config_entries import ConfigEntry
from homeassistant.const import (
@ -118,9 +118,9 @@ class GPSLoggerEntity(TrackerEntity, RestoreEntity):
return DeviceInfo(identifiers={(GPL_DOMAIN, self._unique_id)}, name=self._name)
@property
def source_type(self):
def source_type(self) -> SourceType:
"""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):
"""Register state update callback."""