Use shorthand attributes in vodafone_station device tracker (#126747)
parent
a6b629c392
commit
e1314b6cda
|
@ -2,8 +2,6 @@
|
|||
|
||||
from __future__ import annotations
|
||||
|
||||
from aiovodafone import VodafoneStationDevice
|
||||
|
||||
from homeassistant.components.device_tracker import ScannerEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
|
@ -63,6 +61,7 @@ class VodafoneStationTracker(CoordinatorEntity[VodafoneStationRouter], ScannerEn
|
|||
"""Representation of a Vodafone Station device."""
|
||||
|
||||
_attr_translation_key = "device_tracker"
|
||||
mac_address: str
|
||||
|
||||
def __init__(
|
||||
self, coordinator: VodafoneStationRouter, device_info: VodafoneStationDeviceInfo
|
||||
|
@ -70,38 +69,22 @@ class VodafoneStationTracker(CoordinatorEntity[VodafoneStationRouter], ScannerEn
|
|||
"""Initialize a Vodafone Station device."""
|
||||
super().__init__(coordinator)
|
||||
self._coordinator = coordinator
|
||||
device = device_info.device
|
||||
mac = device.mac
|
||||
self._device_mac = mac
|
||||
mac = device_info.device.mac
|
||||
self._attr_mac_address = 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
|
||||
def _device_info(self) -> VodafoneStationDeviceInfo:
|
||||
"""Return fresh data for the device."""
|
||||
return self.coordinator.data.devices[self._device_mac]
|
||||
|
||||
@property
|
||||
def _device(self) -> VodafoneStationDevice:
|
||||
"""Return fresh data for the device."""
|
||||
return self.coordinator.data.devices[self._device_mac].device
|
||||
return self.coordinator.data.devices[self.mac_address]
|
||||
|
||||
@property
|
||||
def is_connected(self) -> bool:
|
||||
"""Return true if the device is connected to the network."""
|
||||
return self._device_info.home
|
||||
|
||||
@property
|
||||
def hostname(self) -> str | None:
|
||||
"""Return the hostname of device."""
|
||||
return self._attr_name
|
||||
|
||||
@property
|
||||
def ip_address(self) -> str | None:
|
||||
"""Return the primary ip address of the device."""
|
||||
return self._device.ip_address
|
||||
|
||||
@property
|
||||
def mac_address(self) -> str:
|
||||
"""Return the mac address of the device."""
|
||||
return self._device_mac
|
||||
return self._device_info.device.ip_address
|
||||
|
|
Loading…
Reference in New Issue