Set default source_type on TrackerEntity and ScannerEntity (#126648)

* Set default source_type on TrackerEntity and ScannerEntity

* Add samples

* Two more

* Adjust tests
pull/126687/head
epenet 2024-09-24 20:56:01 +02:00 committed by GitHub
parent 9dfabc3fb7
commit 3995d001ec
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 6 additions and 25 deletions

View File

@ -215,6 +215,7 @@ class TrackerEntity(
_attr_location_accuracy: int = 0
_attr_location_name: str | None = None
_attr_longitude: float | None = None
_attr_source_type: SourceType = SourceType.GPS
@cached_property
def should_poll(self) -> bool:
@ -299,6 +300,7 @@ class ScannerEntity(
_attr_hostname: str | None = None
_attr_ip_address: str | None = None
_attr_mac_address: str | None = None
_attr_source_type: SourceType = SourceType.ROUTER
@cached_property
def ip_address(self) -> str | None:

View File

@ -8,7 +8,6 @@ from devolo_plc_api.device_api import ConnectedStationInfo
from homeassistant.components.device_tracker import (
DOMAIN as DEVICE_TRACKER_DOMAIN,
ScannerEntity,
SourceType,
)
from homeassistant.const import STATE_UNKNOWN, UnitOfFrequency
from homeassistant.core import HomeAssistant, callback
@ -89,8 +88,6 @@ class DevoloScannerEntity(
):
"""Representation of a devolo device tracker."""
_attr_source_type = SourceType.ROUTER
def __init__(
self,
coordinator: DataUpdateCoordinator[list[ConnectedStationInfo]],

View File

@ -4,7 +4,7 @@ from __future__ import annotations
from renault_api.kamereon.models import KamereonVehicleLocationData
from homeassistant.components.device_tracker import SourceType, TrackerEntity
from homeassistant.components.device_tracker import TrackerEntity
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -42,11 +42,6 @@ class RenaultDeviceTracker(
"""Return longitude value of the device."""
return self.coordinator.data.gpsLongitude if self.coordinator.data else None
@property
def source_type(self) -> SourceType:
"""Return the source type of the device."""
return SourceType.GPS
DEVICE_TRACKER_TYPES: tuple[RenaultDataEntityDescription, ...] = (
RenaultDataEntityDescription(

View File

@ -4,7 +4,7 @@ from collections.abc import Callable
from dataclasses import dataclass
from typing import Any
from homeassistant.components.device_tracker import SourceType, TrackerEntity
from homeassistant.components.device_tracker import TrackerEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import EntityDescription
@ -55,11 +55,6 @@ class StarlinkDeviceTrackerEntity(StarlinkEntity, TrackerEntity):
entity_description: StarlinkDeviceTrackerEntityDescription
@property
def source_type(self) -> SourceType:
"""Return the source type, eg gps or router, of the device."""
return SourceType.GPS
@property
def latitude(self) -> float | None:
"""Return latitude value of the device."""

View File

@ -21,7 +21,6 @@ from aiounifi.models.event import Event, EventKey
from homeassistant.components.device_tracker import (
DOMAIN as DEVICE_TRACKER_DOMAIN,
ScannerEntity,
SourceType,
)
from homeassistant.core import Event as core_Event, HomeAssistant, callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect
@ -275,11 +274,6 @@ class UnifiScannerEntity(UnifiEntity[HandlerT, ApiItemT], ScannerEntity):
"""Return the mac address of the device."""
return self._obj_id
@cached_property
def source_type(self) -> SourceType:
"""Return the source type, eg gps or router, of the device."""
return SourceType.ROUTER
@cached_property
def unique_id(self) -> str:
"""Return a unique ID."""

View File

@ -505,8 +505,7 @@ async def test_scanner_entity_state(
def test_tracker_entity() -> None:
"""Test coverage for base TrackerEntity class."""
entity = TrackerEntity()
with pytest.raises(NotImplementedError):
assert entity.source_type is None
assert entity.source_type is SourceType.GPS
assert entity.latitude is None
assert entity.longitude is None
assert entity.location_name is None
@ -539,8 +538,7 @@ def test_tracker_entity() -> None:
def test_scanner_entity() -> None:
"""Test coverage for base ScannerEntity entity class."""
entity = ScannerEntity()
with pytest.raises(NotImplementedError):
assert entity.source_type is None
assert entity.source_type is SourceType.ROUTER
with pytest.raises(NotImplementedError):
assert entity.is_connected is None
with pytest.raises(NotImplementedError):