Improve type hints in icloud (#77531)

pull/77561/head
epenet 2022-08-30 20:55:27 +02:00 committed by GitHub
parent a1374963d1
commit 7f55e26cd1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 10 deletions

View File

@ -6,7 +6,7 @@ from typing import Any
from homeassistant.components.device_tracker import AsyncSeeCallback, SourceType
from homeassistant.components.device_tracker.config_entry import TrackerEntity
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.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -72,7 +72,7 @@ class IcloudTrackerEntity(TrackerEntity):
"""Set up the iCloud tracker entity."""
self._account = account
self._device = device
self._unsub_dispatcher = None
self._unsub_dispatcher: CALLBACK_TYPE | None = None
@property
def unique_id(self) -> str:
@ -130,15 +130,16 @@ class IcloudTrackerEntity(TrackerEntity):
name=self._device.name,
)
async def async_added_to_hass(self):
async def async_added_to_hass(self) -> None:
"""Register state update callback."""
self._unsub_dispatcher = async_dispatcher_connect(
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."""
self._unsub_dispatcher()
if self._unsub_dispatcher:
self._unsub_dispatcher()
def icon_for_icloud_device(icloud_device: IcloudDevice) -> str:

View File

@ -6,7 +6,7 @@ from typing import Any
from homeassistant.components.sensor import SensorDeviceClass, SensorEntity
from homeassistant.config_entries import ConfigEntry
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.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -62,7 +62,7 @@ class IcloudDeviceBatterySensor(SensorEntity):
"""Initialize the battery sensor."""
self._account = account
self._device = device
self._unsub_dispatcher = None
self._unsub_dispatcher: CALLBACK_TYPE | None = None
@property
def unique_id(self) -> str:
@ -103,12 +103,13 @@ class IcloudDeviceBatterySensor(SensorEntity):
name=self._device.name,
)
async def async_added_to_hass(self):
async def async_added_to_hass(self) -> None:
"""Register state update callback."""
self._unsub_dispatcher = async_dispatcher_connect(
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."""
self._unsub_dispatcher()
if self._unsub_dispatcher:
self._unsub_dispatcher()