From 3995d001ec595f54dd6b26a65ee31e0c94c40f48 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 24 Sep 2024 20:56:01 +0200 Subject: [PATCH] Set default source_type on TrackerEntity and ScannerEntity (#126648) * Set default source_type on TrackerEntity and ScannerEntity * Add samples * Two more * Adjust tests --- homeassistant/components/device_tracker/config_entry.py | 2 ++ .../components/devolo_home_network/device_tracker.py | 3 --- homeassistant/components/renault/device_tracker.py | 7 +------ homeassistant/components/starlink/device_tracker.py | 7 +------ homeassistant/components/unifi/device_tracker.py | 6 ------ tests/components/device_tracker/test_config_entry.py | 6 ++---- 6 files changed, 6 insertions(+), 25 deletions(-) diff --git a/homeassistant/components/device_tracker/config_entry.py b/homeassistant/components/device_tracker/config_entry.py index 505014b3def..306f056dbcc 100644 --- a/homeassistant/components/device_tracker/config_entry.py +++ b/homeassistant/components/device_tracker/config_entry.py @@ -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: diff --git a/homeassistant/components/devolo_home_network/device_tracker.py b/homeassistant/components/devolo_home_network/device_tracker.py index ce644da4e1d..d372ba3d468 100644 --- a/homeassistant/components/devolo_home_network/device_tracker.py +++ b/homeassistant/components/devolo_home_network/device_tracker.py @@ -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]], diff --git a/homeassistant/components/renault/device_tracker.py b/homeassistant/components/renault/device_tracker.py index db889868cae..1fde6c80cd6 100644 --- a/homeassistant/components/renault/device_tracker.py +++ b/homeassistant/components/renault/device_tracker.py @@ -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( diff --git a/homeassistant/components/starlink/device_tracker.py b/homeassistant/components/starlink/device_tracker.py index de9f413778a..13861823722 100644 --- a/homeassistant/components/starlink/device_tracker.py +++ b/homeassistant/components/starlink/device_tracker.py @@ -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.""" diff --git a/homeassistant/components/unifi/device_tracker.py b/homeassistant/components/unifi/device_tracker.py index eff8d9813db..5cdb3488367 100644 --- a/homeassistant/components/unifi/device_tracker.py +++ b/homeassistant/components/unifi/device_tracker.py @@ -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.""" diff --git a/tests/components/device_tracker/test_config_entry.py b/tests/components/device_tracker/test_config_entry.py index 7041b2d59ab..bc721803450 100644 --- a/tests/components/device_tracker/test_config_entry.py +++ b/tests/components/device_tracker/test_config_entry.py @@ -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):