From e1314b6cda5ec6820896425af44fdf3c94c4fd41 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Fri, 27 Sep 2024 14:48:30 +0200 Subject: [PATCH] Use shorthand attributes in vodafone_station device tracker (#126747) --- .../vodafone_station/device_tracker.py | 29 ++++--------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/homeassistant/components/vodafone_station/device_tracker.py b/homeassistant/components/vodafone_station/device_tracker.py index 004614f578d..3e4d7763bff 100644 --- a/homeassistant/components/vodafone_station/device_tracker.py +++ b/homeassistant/components/vodafone_station/device_tracker.py @@ -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