Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make device_tracker fallback defaults cached_property #121260

Merged
merged 1 commit into from
Jul 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions homeassistant/components/device_tracker/config_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

import asyncio
from functools import cached_property
from typing import final

from homeassistant.components import zone
Expand Down Expand Up @@ -168,7 +169,7 @@ class BaseTrackerEntity(Entity):
_attr_device_info: None = None
_attr_entity_category = EntityCategory.DIAGNOSTIC

@property
@cached_property
def battery_level(self) -> int | None:
"""Return the battery level of the device.

Expand All @@ -195,7 +196,7 @@ def state_attributes(self) -> dict[str, StateType]:
class TrackerEntity(BaseTrackerEntity):
"""Base class for a tracked device."""

@property
@cached_property
def should_poll(self) -> bool:
"""No polling for entities that have location pushed."""
return False
Expand All @@ -205,25 +206,25 @@ def force_update(self) -> bool:
"""All updates need to be written to the state machine if we're not polling."""
return not self.should_poll

@property
@cached_property
def location_accuracy(self) -> int:
"""Return the location accuracy of the device.

Value in meters.
"""
return 0

@property
@cached_property
def location_name(self) -> str | None:
"""Return a location name for the current location of the device."""
return None

@property
@cached_property
def latitude(self) -> float | None:
"""Return latitude value of the device."""
return None

@property
@cached_property
def longitude(self) -> float | None:
"""Return longitude value of the device."""
return None
Expand Down Expand Up @@ -266,17 +267,17 @@ def state_attributes(self) -> dict[str, StateType]:
class ScannerEntity(BaseTrackerEntity):
"""Base class for a tracked device that is on a scanned network."""

@property
@cached_property
def ip_address(self) -> str | None:
"""Return the primary ip address of the device."""
return None

@property
@cached_property
def mac_address(self) -> str | None:
"""Return the mac address of the device."""
return None

@property
@cached_property
def hostname(self) -> str | None:
"""Return hostname of the device."""
return None
Expand Down