mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Use shorthand attributes in vodafone_station device tracker (#126747)
This commit is contained in:
parent
a6b629c392
commit
e1314b6cda
@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from aiovodafone import VodafoneStationDevice
|
|
||||||
|
|
||||||
from homeassistant.components.device_tracker import ScannerEntity
|
from homeassistant.components.device_tracker import ScannerEntity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
@ -63,6 +61,7 @@ class VodafoneStationTracker(CoordinatorEntity[VodafoneStationRouter], ScannerEn
|
|||||||
"""Representation of a Vodafone Station device."""
|
"""Representation of a Vodafone Station device."""
|
||||||
|
|
||||||
_attr_translation_key = "device_tracker"
|
_attr_translation_key = "device_tracker"
|
||||||
|
mac_address: str
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, coordinator: VodafoneStationRouter, device_info: VodafoneStationDeviceInfo
|
self, coordinator: VodafoneStationRouter, device_info: VodafoneStationDeviceInfo
|
||||||
@ -70,38 +69,22 @@ class VodafoneStationTracker(CoordinatorEntity[VodafoneStationRouter], ScannerEn
|
|||||||
"""Initialize a Vodafone Station device."""
|
"""Initialize a Vodafone Station device."""
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
self._coordinator = coordinator
|
self._coordinator = coordinator
|
||||||
device = device_info.device
|
mac = device_info.device.mac
|
||||||
mac = device.mac
|
self._attr_mac_address = mac
|
||||||
self._device_mac = mac
|
|
||||||
self._attr_unique_id = mac
|
self._attr_unique_id = mac
|
||||||
self._attr_name = device.name or mac.replace(":", "_")
|
self._attr_hostname = device_info.device.name or mac.replace(":", "_")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _device_info(self) -> VodafoneStationDeviceInfo:
|
def _device_info(self) -> VodafoneStationDeviceInfo:
|
||||||
"""Return fresh data for the device."""
|
"""Return fresh data for the device."""
|
||||||
return self.coordinator.data.devices[self._device_mac]
|
return self.coordinator.data.devices[self.mac_address]
|
||||||
|
|
||||||
@property
|
|
||||||
def _device(self) -> VodafoneStationDevice:
|
|
||||||
"""Return fresh data for the device."""
|
|
||||||
return self.coordinator.data.devices[self._device_mac].device
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_connected(self) -> bool:
|
def is_connected(self) -> bool:
|
||||||
"""Return true if the device is connected to the network."""
|
"""Return true if the device is connected to the network."""
|
||||||
return self._device_info.home
|
return self._device_info.home
|
||||||
|
|
||||||
@property
|
|
||||||
def hostname(self) -> str | None:
|
|
||||||
"""Return the hostname of device."""
|
|
||||||
return self._attr_name
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def ip_address(self) -> str | None:
|
def ip_address(self) -> str | None:
|
||||||
"""Return the primary ip address of the device."""
|
"""Return the primary ip address of the device."""
|
||||||
return self._device.ip_address
|
return self._device_info.device.ip_address
|
||||||
|
|
||||||
@property
|
|
||||||
def mac_address(self) -> str:
|
|
||||||
"""Return the mac address of the device."""
|
|
||||||
return self._device_mac
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user