mirror of
https://github.com/home-assistant/core.git
synced 2025-08-02 12:15:08 +02:00
Mark device_tracker methods and properties as mandatory in pylint plugin (#145309)
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import Any
|
from typing import TYPE_CHECKING, Any
|
||||||
|
|
||||||
from homeassistant.components.device_tracker import TrackerEntity
|
from homeassistant.components.device_tracker import TrackerEntity
|
||||||
from homeassistant.core import CALLBACK_TYPE, HomeAssistant, callback
|
from homeassistant.core import CALLBACK_TYPE, HomeAssistant, callback
|
||||||
@@ -69,18 +69,24 @@ class IcloudTrackerEntity(TrackerEntity):
|
|||||||
self._attr_unique_id = device.unique_id
|
self._attr_unique_id = device.unique_id
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def location_accuracy(self):
|
def location_accuracy(self) -> float:
|
||||||
"""Return the location accuracy of the device."""
|
"""Return the location accuracy of the device."""
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
assert self._device.location is not None
|
||||||
return self._device.location[DEVICE_LOCATION_HORIZONTAL_ACCURACY]
|
return self._device.location[DEVICE_LOCATION_HORIZONTAL_ACCURACY]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def latitude(self):
|
def latitude(self) -> float:
|
||||||
"""Return latitude value of the device."""
|
"""Return latitude value of the device."""
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
assert self._device.location is not None
|
||||||
return self._device.location[DEVICE_LOCATION_LATITUDE]
|
return self._device.location[DEVICE_LOCATION_LATITUDE]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def longitude(self):
|
def longitude(self) -> float:
|
||||||
"""Return longitude value of the device."""
|
"""Return longitude value of the device."""
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
assert self._device.location is not None
|
||||||
return self._device.location[DEVICE_LOCATION_LONGITUDE]
|
return self._device.location[DEVICE_LOCATION_LONGITUDE]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@@ -1,5 +1,7 @@
|
|||||||
"""Device tracker for Mobile app."""
|
"""Device tracker for Mobile app."""
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from homeassistant.components.device_tracker import (
|
from homeassistant.components.device_tracker import (
|
||||||
ATTR_BATTERY,
|
ATTR_BATTERY,
|
||||||
ATTR_GPS,
|
ATTR_GPS,
|
||||||
@@ -15,6 +17,7 @@ from homeassistant.const import (
|
|||||||
ATTR_LONGITUDE,
|
ATTR_LONGITUDE,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
|
from homeassistant.helpers.device_registry import DeviceInfo
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||||
from homeassistant.helpers.restore_state import RestoreEntity
|
from homeassistant.helpers.restore_state import RestoreEntity
|
||||||
@@ -52,17 +55,17 @@ class MobileAppEntity(TrackerEntity, RestoreEntity):
|
|||||||
self._dispatch_unsub = None
|
self._dispatch_unsub = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self):
|
def unique_id(self) -> str:
|
||||||
"""Return the unique ID."""
|
"""Return the unique ID."""
|
||||||
return self._entry.data[ATTR_DEVICE_ID]
|
return self._entry.data[ATTR_DEVICE_ID]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def battery_level(self):
|
def battery_level(self) -> int | None:
|
||||||
"""Return the battery level of the device."""
|
"""Return the battery level of the device."""
|
||||||
return self._data.get(ATTR_BATTERY)
|
return self._data.get(ATTR_BATTERY)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self):
|
def extra_state_attributes(self) -> dict[str, Any]:
|
||||||
"""Return device specific attributes."""
|
"""Return device specific attributes."""
|
||||||
attrs = {}
|
attrs = {}
|
||||||
for key in ATTR_KEYS:
|
for key in ATTR_KEYS:
|
||||||
@@ -72,12 +75,12 @@ class MobileAppEntity(TrackerEntity, RestoreEntity):
|
|||||||
return attrs
|
return attrs
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def location_accuracy(self):
|
def location_accuracy(self) -> float:
|
||||||
"""Return the gps accuracy of the device."""
|
"""Return the gps accuracy of the device."""
|
||||||
return self._data.get(ATTR_GPS_ACCURACY)
|
return self._data.get(ATTR_GPS_ACCURACY, 0)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def latitude(self):
|
def latitude(self) -> float | None:
|
||||||
"""Return latitude value of the device."""
|
"""Return latitude value of the device."""
|
||||||
if (gps := self._data.get(ATTR_GPS)) is None:
|
if (gps := self._data.get(ATTR_GPS)) is None:
|
||||||
return None
|
return None
|
||||||
@@ -85,7 +88,7 @@ class MobileAppEntity(TrackerEntity, RestoreEntity):
|
|||||||
return gps[0]
|
return gps[0]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def longitude(self):
|
def longitude(self) -> float | None:
|
||||||
"""Return longitude value of the device."""
|
"""Return longitude value of the device."""
|
||||||
if (gps := self._data.get(ATTR_GPS)) is None:
|
if (gps := self._data.get(ATTR_GPS)) is None:
|
||||||
return None
|
return None
|
||||||
@@ -93,19 +96,19 @@ class MobileAppEntity(TrackerEntity, RestoreEntity):
|
|||||||
return gps[1]
|
return gps[1]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def location_name(self):
|
def location_name(self) -> str | None:
|
||||||
"""Return a location name for the current location of the device."""
|
"""Return a location name for the current location of the device."""
|
||||||
if location_name := self._data.get(ATTR_LOCATION_NAME):
|
if location_name := self._data.get(ATTR_LOCATION_NAME):
|
||||||
return location_name
|
return location_name
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self) -> str:
|
||||||
"""Return the name of the device."""
|
"""Return the name of the device."""
|
||||||
return self._entry.data[ATTR_DEVICE_NAME]
|
return self._entry.data[ATTR_DEVICE_NAME]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_info(self):
|
def device_info(self) -> DeviceInfo:
|
||||||
"""Return the device info."""
|
"""Return the device info."""
|
||||||
return device_info(self._entry.data)
|
return device_info(self._entry.data)
|
||||||
|
|
||||||
|
@@ -1,5 +1,7 @@
|
|||||||
"""Device tracker platform that adds support for OwnTracks over MQTT."""
|
"""Device tracker platform that adds support for OwnTracks over MQTT."""
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from homeassistant.components.device_tracker import (
|
from homeassistant.components.device_tracker import (
|
||||||
ATTR_SOURCE_TYPE,
|
ATTR_SOURCE_TYPE,
|
||||||
DOMAIN as DEVICE_TRACKER_DOMAIN,
|
DOMAIN as DEVICE_TRACKER_DOMAIN,
|
||||||
@@ -64,34 +66,34 @@ class OwnTracksEntity(TrackerEntity, RestoreEntity):
|
|||||||
_attr_has_entity_name = True
|
_attr_has_entity_name = True
|
||||||
_attr_name = None
|
_attr_name = None
|
||||||
|
|
||||||
def __init__(self, dev_id, data=None):
|
def __init__(self, dev_id: str, data: dict[str, Any] | None = None) -> None:
|
||||||
"""Set up OwnTracks entity."""
|
"""Set up OwnTracks entity."""
|
||||||
self._dev_id = dev_id
|
self._dev_id = dev_id
|
||||||
self._data = data or {}
|
self._data = data or {}
|
||||||
self.entity_id = f"{DEVICE_TRACKER_DOMAIN}.{dev_id}"
|
self.entity_id = f"{DEVICE_TRACKER_DOMAIN}.{dev_id}"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self):
|
def unique_id(self) -> str:
|
||||||
"""Return the unique ID."""
|
"""Return the unique ID."""
|
||||||
return self._dev_id
|
return self._dev_id
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def battery_level(self):
|
def battery_level(self) -> int | None:
|
||||||
"""Return the battery level of the device."""
|
"""Return the battery level of the device."""
|
||||||
return self._data.get("battery")
|
return self._data.get("battery")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self):
|
def extra_state_attributes(self) -> dict[str, Any] | None:
|
||||||
"""Return device specific attributes."""
|
"""Return device specific attributes."""
|
||||||
return self._data.get("attributes")
|
return self._data.get("attributes")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def location_accuracy(self):
|
def location_accuracy(self) -> float:
|
||||||
"""Return the gps accuracy of the device."""
|
"""Return the gps accuracy of the device."""
|
||||||
return self._data.get("gps_accuracy")
|
return self._data.get("gps_accuracy", 0)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def latitude(self):
|
def latitude(self) -> float | None:
|
||||||
"""Return latitude value of the device."""
|
"""Return latitude value of the device."""
|
||||||
# Check with "get" instead of "in" because value can be None
|
# Check with "get" instead of "in" because value can be None
|
||||||
if self._data.get("gps"):
|
if self._data.get("gps"):
|
||||||
@@ -100,7 +102,7 @@ class OwnTracksEntity(TrackerEntity, RestoreEntity):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def longitude(self):
|
def longitude(self) -> float | None:
|
||||||
"""Return longitude value of the device."""
|
"""Return longitude value of the device."""
|
||||||
# Check with "get" instead of "in" because value can be None
|
# Check with "get" instead of "in" because value can be None
|
||||||
if self._data.get("gps"):
|
if self._data.get("gps"):
|
||||||
@@ -109,7 +111,7 @@ class OwnTracksEntity(TrackerEntity, RestoreEntity):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def location_name(self):
|
def location_name(self) -> str | None:
|
||||||
"""Return a location name for the current location of the device."""
|
"""Return a location name for the current location of the device."""
|
||||||
return self._data.get("location_name")
|
return self._data.get("location_name")
|
||||||
|
|
||||||
|
@@ -1,5 +1,7 @@
|
|||||||
"""StarLine device tracker."""
|
"""StarLine device tracker."""
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from homeassistant.components.device_tracker import 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
|
||||||
@@ -35,26 +37,26 @@ class StarlineDeviceTracker(StarlineEntity, TrackerEntity, RestoreEntity):
|
|||||||
super().__init__(account, device, "location")
|
super().__init__(account, device, "location")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self):
|
def extra_state_attributes(self) -> dict[str, Any]:
|
||||||
"""Return device specific attributes."""
|
"""Return device specific attributes."""
|
||||||
return self._account.gps_attrs(self._device)
|
return self._account.gps_attrs(self._device)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def battery_level(self):
|
def battery_level(self) -> int | None:
|
||||||
"""Return the battery level of the device."""
|
"""Return the battery level of the device."""
|
||||||
return self._device.battery_level
|
return self._device.battery_level
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def location_accuracy(self):
|
def location_accuracy(self) -> float:
|
||||||
"""Return the gps accuracy of the device."""
|
"""Return the gps accuracy of the device."""
|
||||||
return self._device.position.get("r", 0)
|
return self._device.position.get("r", 0)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def latitude(self):
|
def latitude(self) -> float:
|
||||||
"""Return latitude value of the device."""
|
"""Return latitude value of the device."""
|
||||||
return self._device.position["x"]
|
return self._device.position["x"]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def longitude(self):
|
def longitude(self) -> float:
|
||||||
"""Return longitude value of the device."""
|
"""Return longitude value of the device."""
|
||||||
return self._device.position["y"]
|
return self._device.position["y"]
|
||||||
|
@@ -1484,6 +1484,7 @@ _INHERITANCE_MATCH: dict[str, list[ClassTypeHintMatch]] = {
|
|||||||
TypeHintMatch(
|
TypeHintMatch(
|
||||||
function_name="source_type",
|
function_name="source_type",
|
||||||
return_type="SourceType",
|
return_type="SourceType",
|
||||||
|
mandatory=True,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@@ -1493,10 +1494,12 @@ _INHERITANCE_MATCH: dict[str, list[ClassTypeHintMatch]] = {
|
|||||||
TypeHintMatch(
|
TypeHintMatch(
|
||||||
function_name="force_update",
|
function_name="force_update",
|
||||||
return_type="bool",
|
return_type="bool",
|
||||||
|
mandatory=True,
|
||||||
),
|
),
|
||||||
TypeHintMatch(
|
TypeHintMatch(
|
||||||
function_name="location_accuracy",
|
function_name="location_accuracy",
|
||||||
return_type="float",
|
return_type="float",
|
||||||
|
mandatory=True,
|
||||||
),
|
),
|
||||||
TypeHintMatch(
|
TypeHintMatch(
|
||||||
function_name="location_name",
|
function_name="location_name",
|
||||||
@@ -1534,10 +1537,12 @@ _INHERITANCE_MATCH: dict[str, list[ClassTypeHintMatch]] = {
|
|||||||
TypeHintMatch(
|
TypeHintMatch(
|
||||||
function_name="state",
|
function_name="state",
|
||||||
return_type="str",
|
return_type="str",
|
||||||
|
mandatory=True,
|
||||||
),
|
),
|
||||||
TypeHintMatch(
|
TypeHintMatch(
|
||||||
function_name="is_connected",
|
function_name="is_connected",
|
||||||
return_type="bool",
|
return_type="bool",
|
||||||
|
mandatory=True,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
Reference in New Issue
Block a user