From 6c4290e418d4064c6cf80f4a3e32fa503627f3cc Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Fri, 26 Aug 2022 10:48:31 +0200 Subject: [PATCH] Improve type hint in acmeda base entity (#77171) --- homeassistant/components/acmeda/base.py | 29 ++++++++++++++----------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/homeassistant/components/acmeda/base.py b/homeassistant/components/acmeda/base.py index e9ffb94c6c67..dd1ab78345f5 100644 --- a/homeassistant/components/acmeda/base.py +++ b/homeassistant/components/acmeda/base.py @@ -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