1
mirror of https://github.com/home-assistant/core synced 2024-07-12 07:21:24 +02:00

Improve type hint in acmeda base entity (#77171)

This commit is contained in:
epenet 2022-08-26 10:48:31 +02:00 committed by GitHub
parent 8f9ff0f88e
commit 6c4290e418
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,4 +1,6 @@
"""Base class for Acmeda Roller Blinds."""
from __future__ import annotations
import aiopulse
from homeassistant.core import callback
@ -11,11 +13,13 @@ from .const import ACMEDA_ENTITY_REMOVE, DOMAIN, LOGGER
class AcmedaBase(entity.Entity):
"""Base representation of an Acmeda roller."""
_attr_should_poll = False
def __init__(self, roller: aiopulse.Roller) -> None:
"""Initialize the roller."""
self.roller = roller
async def async_remove_and_unregister(self):
async def async_remove_and_unregister(self) -> None:
"""Unregister from entity and device registry and call entity remove function."""
LOGGER.error("Removing %s %s", self.__class__.__name__, self.unique_id)
@ -25,14 +29,18 @@ class AcmedaBase(entity.Entity):
dev_registry = dr.async_get(self.hass)
device = dev_registry.async_get_device(identifiers={(DOMAIN, self.unique_id)})
if device is not None:
if (
device is not None
and self.registry_entry is not None
and self.registry_entry.config_entry_id is not None
):
dev_registry.async_update_device(
device.id, remove_config_entry_id=self.registry_entry.config_entry_id
)
await self.async_remove(force_remove=True)
async def async_added_to_hass(self):
async def async_added_to_hass(self) -> None:
"""Entity has been added to hass."""
self.roller.callback_subscribe(self.notify_update)
@ -44,33 +52,28 @@ class AcmedaBase(entity.Entity):
)
)
async def async_will_remove_from_hass(self):
async def async_will_remove_from_hass(self) -> None:
"""Entity being removed from hass."""
self.roller.callback_unsubscribe(self.notify_update)
@callback
def notify_update(self):
def notify_update(self) -> None:
"""Write updated device state information."""
LOGGER.debug("Device update notification received: %s", self.name)
self.async_write_ha_state()
@property
def should_poll(self):
"""Report that Acmeda entities do not need polling."""
return False
@property
def unique_id(self):
def unique_id(self) -> str:
"""Return the unique ID of this roller."""
return self.roller.id
@property
def device_id(self):
def device_id(self) -> str:
"""Return the ID of this roller."""
return self.roller.id
@property
def name(self):
def name(self) -> str | None:
"""Return the name of roller."""
return self.roller.name