mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Set default source_type on TrackerEntity and ScannerEntity (#126648)
* Set default source_type on TrackerEntity and ScannerEntity * Add samples * Two more * Adjust tests
This commit is contained in:
parent
9dfabc3fb7
commit
3995d001ec
@ -215,6 +215,7 @@ class TrackerEntity(
|
|||||||
_attr_location_accuracy: int = 0
|
_attr_location_accuracy: int = 0
|
||||||
_attr_location_name: str | None = None
|
_attr_location_name: str | None = None
|
||||||
_attr_longitude: float | None = None
|
_attr_longitude: float | None = None
|
||||||
|
_attr_source_type: SourceType = SourceType.GPS
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def should_poll(self) -> bool:
|
def should_poll(self) -> bool:
|
||||||
@ -299,6 +300,7 @@ class ScannerEntity(
|
|||||||
_attr_hostname: str | None = None
|
_attr_hostname: str | None = None
|
||||||
_attr_ip_address: str | None = None
|
_attr_ip_address: str | None = None
|
||||||
_attr_mac_address: str | None = None
|
_attr_mac_address: str | None = None
|
||||||
|
_attr_source_type: SourceType = SourceType.ROUTER
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def ip_address(self) -> str | None:
|
def ip_address(self) -> str | None:
|
||||||
|
@ -8,7 +8,6 @@ from devolo_plc_api.device_api import ConnectedStationInfo
|
|||||||
from homeassistant.components.device_tracker import (
|
from homeassistant.components.device_tracker import (
|
||||||
DOMAIN as DEVICE_TRACKER_DOMAIN,
|
DOMAIN as DEVICE_TRACKER_DOMAIN,
|
||||||
ScannerEntity,
|
ScannerEntity,
|
||||||
SourceType,
|
|
||||||
)
|
)
|
||||||
from homeassistant.const import STATE_UNKNOWN, UnitOfFrequency
|
from homeassistant.const import STATE_UNKNOWN, UnitOfFrequency
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
@ -89,8 +88,6 @@ class DevoloScannerEntity(
|
|||||||
):
|
):
|
||||||
"""Representation of a devolo device tracker."""
|
"""Representation of a devolo device tracker."""
|
||||||
|
|
||||||
_attr_source_type = SourceType.ROUTER
|
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
coordinator: DataUpdateCoordinator[list[ConnectedStationInfo]],
|
coordinator: DataUpdateCoordinator[list[ConnectedStationInfo]],
|
||||||
|
@ -4,7 +4,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from renault_api.kamereon.models import KamereonVehicleLocationData
|
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.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
@ -42,11 +42,6 @@ class RenaultDeviceTracker(
|
|||||||
"""Return longitude value of the device."""
|
"""Return longitude value of the device."""
|
||||||
return self.coordinator.data.gpsLongitude if self.coordinator.data else None
|
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, ...] = (
|
DEVICE_TRACKER_TYPES: tuple[RenaultDataEntityDescription, ...] = (
|
||||||
RenaultDataEntityDescription(
|
RenaultDataEntityDescription(
|
||||||
|
@ -4,7 +4,7 @@ from collections.abc import Callable
|
|||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Any
|
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.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity import EntityDescription
|
from homeassistant.helpers.entity import EntityDescription
|
||||||
@ -55,11 +55,6 @@ class StarlinkDeviceTrackerEntity(StarlinkEntity, TrackerEntity):
|
|||||||
|
|
||||||
entity_description: StarlinkDeviceTrackerEntityDescription
|
entity_description: StarlinkDeviceTrackerEntityDescription
|
||||||
|
|
||||||
@property
|
|
||||||
def source_type(self) -> SourceType:
|
|
||||||
"""Return the source type, eg gps or router, of the device."""
|
|
||||||
return SourceType.GPS
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def latitude(self) -> float | None:
|
def latitude(self) -> float | None:
|
||||||
"""Return latitude value of the device."""
|
"""Return latitude value of the device."""
|
||||||
|
@ -21,7 +21,6 @@ from aiounifi.models.event import Event, EventKey
|
|||||||
from homeassistant.components.device_tracker import (
|
from homeassistant.components.device_tracker import (
|
||||||
DOMAIN as DEVICE_TRACKER_DOMAIN,
|
DOMAIN as DEVICE_TRACKER_DOMAIN,
|
||||||
ScannerEntity,
|
ScannerEntity,
|
||||||
SourceType,
|
|
||||||
)
|
)
|
||||||
from homeassistant.core import Event as core_Event, HomeAssistant, callback
|
from homeassistant.core import Event as core_Event, HomeAssistant, callback
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
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 the mac address of the device."""
|
||||||
return self._obj_id
|
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
|
@cached_property
|
||||||
def unique_id(self) -> str:
|
def unique_id(self) -> str:
|
||||||
"""Return a unique ID."""
|
"""Return a unique ID."""
|
||||||
|
@ -505,8 +505,7 @@ async def test_scanner_entity_state(
|
|||||||
def test_tracker_entity() -> None:
|
def test_tracker_entity() -> None:
|
||||||
"""Test coverage for base TrackerEntity class."""
|
"""Test coverage for base TrackerEntity class."""
|
||||||
entity = TrackerEntity()
|
entity = TrackerEntity()
|
||||||
with pytest.raises(NotImplementedError):
|
assert entity.source_type is SourceType.GPS
|
||||||
assert entity.source_type is None
|
|
||||||
assert entity.latitude is None
|
assert entity.latitude is None
|
||||||
assert entity.longitude is None
|
assert entity.longitude is None
|
||||||
assert entity.location_name is None
|
assert entity.location_name is None
|
||||||
@ -539,8 +538,7 @@ def test_tracker_entity() -> None:
|
|||||||
def test_scanner_entity() -> None:
|
def test_scanner_entity() -> None:
|
||||||
"""Test coverage for base ScannerEntity entity class."""
|
"""Test coverage for base ScannerEntity entity class."""
|
||||||
entity = ScannerEntity()
|
entity = ScannerEntity()
|
||||||
with pytest.raises(NotImplementedError):
|
assert entity.source_type is SourceType.ROUTER
|
||||||
assert entity.source_type is None
|
|
||||||
with pytest.raises(NotImplementedError):
|
with pytest.raises(NotImplementedError):
|
||||||
assert entity.is_connected is None
|
assert entity.is_connected is None
|
||||||
with pytest.raises(NotImplementedError):
|
with pytest.raises(NotImplementedError):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user