Use shorthand attributes in vodafone_station device tracker (#126747)

pull/126915/head
epenet 2024-09-27 14:48:30 +02:00 committed by GitHub
parent a6b629c392
commit e1314b6cda
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 23 deletions

View File

@ -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