Use device_tracker SourceType enum [s-z] (#75966)

This commit is contained in:
Marc Mueller 2022-07-31 14:01:18 +02:00 committed by GitHub
parent 7b1463e03d
commit c9ddb10024
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 23 additions and 26 deletions

View File

@ -1,6 +1,6 @@
"""StarLine device tracker.""" """StarLine device tracker."""
from homeassistant.components.device_tracker.config_entry import TrackerEntity from homeassistant.components.device_tracker.config_entry import TrackerEntity
from homeassistant.components.device_tracker.const import SOURCE_TYPE_GPS from homeassistant.components.device_tracker.const import SourceType
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -56,9 +56,9 @@ class StarlineDeviceTracker(StarlineEntity, TrackerEntity, RestoreEntity):
return self._device.position["y"] return self._device.position["y"]
@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
@property @property
def icon(self): def icon(self):

View File

@ -7,7 +7,7 @@ from pytile.tile import Tile
from homeassistant.components.device_tracker import AsyncSeeCallback from homeassistant.components.device_tracker import AsyncSeeCallback
from homeassistant.components.device_tracker.config_entry import TrackerEntity from homeassistant.components.device_tracker.config_entry import TrackerEntity
from homeassistant.components.device_tracker.const import SOURCE_TYPE_GPS from homeassistant.components.device_tracker.const import SourceType
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
@ -122,9 +122,9 @@ class TileDeviceTracker(CoordinatorEntity, TrackerEntity):
return self._tile.longitude return self._tile.longitude
@property @property
def source_type(self) -> str: 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
@callback @callback
def _handle_coordinator_update(self) -> None: def _handle_coordinator_update(self) -> None:

View File

@ -19,8 +19,8 @@ import voluptuous as vol
from homeassistant.components.device_tracker import ( from homeassistant.components.device_tracker import (
CONF_SCAN_INTERVAL, CONF_SCAN_INTERVAL,
PLATFORM_SCHEMA as PARENT_PLATFORM_SCHEMA, PLATFORM_SCHEMA as PARENT_PLATFORM_SCHEMA,
SOURCE_TYPE_GPS,
AsyncSeeCallback, AsyncSeeCallback,
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
@ -407,9 +407,9 @@ class TraccarEntity(TrackerEntity, RestoreEntity):
return {"name": self._name, "identifiers": {(DOMAIN, self._unique_id)}} return {"name": self._name, "identifiers": {(DOMAIN, self._unique_id)}}
@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."""

View File

@ -3,10 +3,7 @@ from __future__ import annotations
from typing import Any from typing import Any
from homeassistant.components.device_tracker import ( from homeassistant.components.device_tracker import SourceType
SOURCE_TYPE_BLUETOOTH,
SOURCE_TYPE_GPS,
)
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, callback from homeassistant.core import HomeAssistant, callback
@ -56,11 +53,11 @@ class TractiveDeviceTracker(TractiveEntity, TrackerEntity):
self._attr_unique_id = item.trackable["_id"] self._attr_unique_id = item.trackable["_id"]
@property @property
def source_type(self) -> str: 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."""
if self._source_type == "PHONE": if self._source_type == "PHONE":
return SOURCE_TYPE_BLUETOOTH return SourceType.BLUETOOTH
return SOURCE_TYPE_GPS return SourceType.GPS
@property @property
def latitude(self) -> float: def latitude(self) -> float:

View File

@ -19,7 +19,7 @@ from aiounifi.events import (
from homeassistant.components.device_tracker import DOMAIN from homeassistant.components.device_tracker import DOMAIN
from homeassistant.components.device_tracker.config_entry import ScannerEntity from homeassistant.components.device_tracker.config_entry import ScannerEntity
from homeassistant.components.device_tracker.const import SOURCE_TYPE_ROUTER from homeassistant.components.device_tracker.const import SourceType
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.dispatcher import async_dispatcher_connect
@ -276,9 +276,9 @@ class UniFiClientTracker(UniFiClientBase, ScannerEntity):
return self._is_connected return self._is_connected
@property @property
def source_type(self): def source_type(self) -> SourceType:
"""Return the source type of the client.""" """Return the source type of the client."""
return SOURCE_TYPE_ROUTER return SourceType.ROUTER
@property @property
def unique_id(self) -> str: def unique_id(self) -> str:
@ -406,9 +406,9 @@ class UniFiDeviceTracker(UniFiBase, ScannerEntity):
return self._is_connected return self._is_connected
@property @property
def source_type(self): def source_type(self) -> SourceType:
"""Return the source type of the device.""" """Return the source type of the device."""
return SOURCE_TYPE_ROUTER return SourceType.ROUTER
@property @property
def name(self) -> str: def name(self) -> str:

View File

@ -1,7 +1,7 @@
"""Support for tracking a Volvo.""" """Support for tracking a Volvo."""
from __future__ import annotations from __future__ import annotations
from homeassistant.components.device_tracker import SOURCE_TYPE_GPS, AsyncSeeCallback from homeassistant.components.device_tracker import AsyncSeeCallback, SourceType
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
@ -31,7 +31,7 @@ async def async_setup_scanner(
await async_see( await async_see(
dev_id=dev_id, dev_id=dev_id,
host_name=host_name, host_name=host_name,
source_type=SOURCE_TYPE_GPS, source_type=SourceType.GPS,
gps=instrument.state, gps=instrument.state,
icon="mdi:car", icon="mdi:car",
) )

View File

@ -4,7 +4,7 @@ from __future__ import annotations
import functools import functools
import time import time
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.const import Platform from homeassistant.const import Platform
@ -85,9 +85,9 @@ class ZHADeviceScannerEntity(ScannerEntity, ZhaEntity):
return self._connected return self._connected
@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_ROUTER return SourceType.ROUTER
@callback @callback
def async_battery_percentage_remaining_updated(self, attr_id, attr_name, value): def async_battery_percentage_remaining_updated(self, attr_id, attr_name, value):