From 7ead5c44eada5caa36cd72fe14737b6deeefe3eb Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Thu, 31 Aug 2023 12:37:21 +0200 Subject: [PATCH] Use shorthand attributes in iCloud (#99390) * Use shorthand attributes in iCloud * Use shorthand attributes in iCloud --- .../components/icloud/device_tracker.py | 6 +---- homeassistant/components/icloud/sensor.py | 24 +++++++------------ 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/homeassistant/components/icloud/device_tracker.py b/homeassistant/components/icloud/device_tracker.py index 0bd1dfb44a9..8513b47be2a 100644 --- a/homeassistant/components/icloud/device_tracker.py +++ b/homeassistant/components/icloud/device_tracker.py @@ -64,11 +64,7 @@ class IcloudTrackerEntity(TrackerEntity): self._account = account self._device = device self._unsub_dispatcher: CALLBACK_TYPE | None = None - - @property - def unique_id(self) -> str: - """Return a unique ID.""" - return self._device.unique_id + self._attr_unique_id = device.unique_id @property def location_accuracy(self): diff --git a/homeassistant/components/icloud/sensor.py b/homeassistant/components/icloud/sensor.py index e92a9ae4a8d..320c3f9f240 100644 --- a/homeassistant/components/icloud/sensor.py +++ b/homeassistant/components/icloud/sensor.py @@ -63,11 +63,14 @@ class IcloudDeviceBatterySensor(SensorEntity): self._account = account self._device = device self._unsub_dispatcher: CALLBACK_TYPE | None = None - - @property - def unique_id(self) -> str: - """Return a unique ID.""" - return f"{self._device.unique_id}_battery" + self._attr_unique_id = f"{device.unique_id}_battery" + self._attr_device_info = DeviceInfo( + configuration_url="https://icloud.com/", + identifiers={(DOMAIN, device.unique_id)}, + manufacturer="Apple", + model=device.device_model, + name=device.name, + ) @property def native_value(self) -> int | None: @@ -87,17 +90,6 @@ class IcloudDeviceBatterySensor(SensorEntity): """Return default attributes for the iCloud device entity.""" return self._device.extra_state_attributes - @property - def device_info(self) -> DeviceInfo: - """Return the device information.""" - return DeviceInfo( - configuration_url="https://icloud.com/", - identifiers={(DOMAIN, self._device.unique_id)}, - manufacturer="Apple", - model=self._device.device_model, - name=self._device.name, - ) - async def async_added_to_hass(self) -> None: """Register state update callback.""" self._unsub_dispatcher = async_dispatcher_connect(