mirror of
https://github.com/home-assistant/core.git
synced 2025-05-22 14:57:14 +00:00
Improve type hints in icloud (#77531)
This commit is contained in:
parent
a1374963d1
commit
7f55e26cd1
@ -6,7 +6,7 @@ from typing import Any
|
|||||||
from homeassistant.components.device_tracker import AsyncSeeCallback, SourceType
|
from homeassistant.components.device_tracker import AsyncSeeCallback, SourceType
|
||||||
from homeassistant.components.device_tracker.config_entry import TrackerEntity
|
from homeassistant.components.device_tracker.config_entry import TrackerEntity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import CALLBACK_TYPE, HomeAssistant, callback
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
from homeassistant.helpers.entity import DeviceInfo
|
from homeassistant.helpers.entity import DeviceInfo
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
@ -72,7 +72,7 @@ class IcloudTrackerEntity(TrackerEntity):
|
|||||||
"""Set up the iCloud tracker entity."""
|
"""Set up the iCloud tracker entity."""
|
||||||
self._account = account
|
self._account = account
|
||||||
self._device = device
|
self._device = device
|
||||||
self._unsub_dispatcher = None
|
self._unsub_dispatcher: CALLBACK_TYPE | None = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self) -> str:
|
def unique_id(self) -> str:
|
||||||
@ -130,14 +130,15 @@ class IcloudTrackerEntity(TrackerEntity):
|
|||||||
name=self._device.name,
|
name=self._device.name,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_added_to_hass(self):
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Register state update callback."""
|
"""Register state update callback."""
|
||||||
self._unsub_dispatcher = async_dispatcher_connect(
|
self._unsub_dispatcher = async_dispatcher_connect(
|
||||||
self.hass, self._account.signal_device_update, self.async_write_ha_state
|
self.hass, self._account.signal_device_update, self.async_write_ha_state
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_will_remove_from_hass(self):
|
async def async_will_remove_from_hass(self) -> None:
|
||||||
"""Clean up after entity before removal."""
|
"""Clean up after entity before removal."""
|
||||||
|
if self._unsub_dispatcher:
|
||||||
self._unsub_dispatcher()
|
self._unsub_dispatcher()
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ from typing import Any
|
|||||||
from homeassistant.components.sensor import SensorDeviceClass, SensorEntity
|
from homeassistant.components.sensor import SensorDeviceClass, SensorEntity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import PERCENTAGE
|
from homeassistant.const import PERCENTAGE
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import CALLBACK_TYPE, HomeAssistant, callback
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
from homeassistant.helpers.entity import DeviceInfo
|
from homeassistant.helpers.entity import DeviceInfo
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
@ -62,7 +62,7 @@ class IcloudDeviceBatterySensor(SensorEntity):
|
|||||||
"""Initialize the battery sensor."""
|
"""Initialize the battery sensor."""
|
||||||
self._account = account
|
self._account = account
|
||||||
self._device = device
|
self._device = device
|
||||||
self._unsub_dispatcher = None
|
self._unsub_dispatcher: CALLBACK_TYPE | None = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self) -> str:
|
def unique_id(self) -> str:
|
||||||
@ -103,12 +103,13 @@ class IcloudDeviceBatterySensor(SensorEntity):
|
|||||||
name=self._device.name,
|
name=self._device.name,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_added_to_hass(self):
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Register state update callback."""
|
"""Register state update callback."""
|
||||||
self._unsub_dispatcher = async_dispatcher_connect(
|
self._unsub_dispatcher = async_dispatcher_connect(
|
||||||
self.hass, self._account.signal_device_update, self.async_write_ha_state
|
self.hass, self._account.signal_device_update, self.async_write_ha_state
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_will_remove_from_hass(self):
|
async def async_will_remove_from_hass(self) -> None:
|
||||||
"""Clean up after entity before removal."""
|
"""Clean up after entity before removal."""
|
||||||
|
if self._unsub_dispatcher:
|
||||||
self._unsub_dispatcher()
|
self._unsub_dispatcher()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user