Use _attr_should_poll in components [h-i] (#77270)

This commit is contained in:
epenet 2022-08-26 10:20:38 +02:00 committed by GitHub
parent a46c25d2c8
commit 2a8109304f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 38 additions and 120 deletions

View File

@ -117,6 +117,8 @@ def log_command_error(
class HeosMediaPlayer(MediaPlayerEntity): class HeosMediaPlayer(MediaPlayerEntity):
"""The HEOS player.""" """The HEOS player."""
_attr_should_poll = False
def __init__(self, player): def __init__(self, player):
"""Initialize.""" """Initialize."""
self._media_position_updated_at = None self._media_position_updated_at = None
@ -402,11 +404,6 @@ class HeosMediaPlayer(MediaPlayerEntity):
"""Return the name of the device.""" """Return the name of the device."""
return self._player.name return self._player.name
@property
def should_poll(self) -> bool:
"""No polling needed for this device."""
return False
@property @property
def shuffle(self) -> bool: def shuffle(self) -> bool:
"""Boolean if shuffle is enabled.""" """Boolean if shuffle is enabled."""

View File

@ -199,6 +199,8 @@ class HikvisionData:
class HikvisionBinarySensor(BinarySensorEntity): class HikvisionBinarySensor(BinarySensorEntity):
"""Representation of a Hikvision binary sensor.""" """Representation of a Hikvision binary sensor."""
_attr_should_poll = False
def __init__(self, hass, sensor, channel, cam, delay): def __init__(self, hass, sensor, channel, cam, delay):
"""Initialize the binary_sensor.""" """Initialize the binary_sensor."""
self._hass = hass self._hass = hass
@ -255,11 +257,6 @@ class HikvisionBinarySensor(BinarySensorEntity):
# Sensor must be unknown to us, add as generic # Sensor must be unknown to us, add as generic
return None return None
@property
def should_poll(self):
"""No polling needed."""
return False
@property @property
def extra_state_attributes(self): def extra_state_attributes(self):
"""Return the state attributes.""" """Return the state attributes."""

View File

@ -138,6 +138,8 @@ class SW16Device(Entity):
Contains the common logic for HLK-SW16 entities. Contains the common logic for HLK-SW16 entities.
""" """
_attr_should_poll = False
def __init__(self, device_port, entry_id, client): def __init__(self, device_port, entry_id, client):
"""Initialize the device.""" """Initialize the device."""
# HLK-SW16 specific attributes for every component type # HLK-SW16 specific attributes for every component type
@ -159,11 +161,6 @@ class SW16Device(Entity):
self._is_on = event self._is_on = event
self.async_write_ha_state() self.async_write_ha_state()
@property
def should_poll(self):
"""No polling needed."""
return False
@property @property
def name(self): def name(self):
"""Return a name for the device.""" """Return a name for the device."""

View File

@ -15,6 +15,8 @@ _LOGGER = logging.getLogger(__name__)
class HomeConnectEntity(Entity): class HomeConnectEntity(Entity):
"""Generic Home Connect entity (base class).""" """Generic Home Connect entity (base class)."""
_attr_should_poll = False
def __init__(self, device: HomeConnectDevice, desc: str) -> None: def __init__(self, device: HomeConnectDevice, desc: str) -> None:
"""Initialize the entity.""" """Initialize the entity."""
self.device = device self.device = device
@ -35,11 +37,6 @@ class HomeConnectEntity(Entity):
if ha_id == self.device.appliance.haId: if ha_id == self.device.appliance.haId:
self.async_entity_update() self.async_entity_update()
@property
def should_poll(self):
"""No polling needed."""
return False
@property @property
def name(self): def name(self):
"""Return the name of the node (used for Entity_ID).""" """Return the name of the node (used for Entity_ID)."""

View File

@ -35,6 +35,7 @@ class HMDevice(Entity):
_homematic: HMConnection _homematic: HMConnection
_hmdevice: HMGeneric _hmdevice: HMGeneric
_attr_should_poll = False
def __init__( def __init__(
self, self,
@ -69,11 +70,6 @@ class HMDevice(Entity):
"""Return unique ID. HomeMatic entity IDs are unique by default.""" """Return unique ID. HomeMatic entity IDs are unique by default."""
return self._unique_id.replace(" ", "_") return self._unique_id.replace(" ", "_")
@property
def should_poll(self):
"""Return false. HomeMatic states are pushed by the XML-RPC Server."""
return False
@property @property
def name(self): def name(self):
"""Return the name of the device.""" """Return the name of the device."""
@ -213,6 +209,8 @@ class HMDevice(Entity):
class HMHub(Entity): class HMHub(Entity):
"""The HomeMatic hub. (CCU2/HomeGear).""" """The HomeMatic hub. (CCU2/HomeGear)."""
_attr_should_poll = False
def __init__(self, hass, homematic, name): def __init__(self, hass, homematic, name):
"""Initialize HomeMatic hub.""" """Initialize HomeMatic hub."""
self.hass = hass self.hass = hass
@ -234,11 +232,6 @@ class HMHub(Entity):
"""Return the name of the device.""" """Return the name of the device."""
return self._name return self._name
@property
def should_poll(self):
"""Return false. HomeMatic Hub object updates variables."""
return False
@property @property
def state(self): def state(self):
"""Return the state of the entity.""" """Return the state of the entity."""

View File

@ -41,6 +41,7 @@ async def async_setup_entry(
class HomematicipAlarmControlPanelEntity(AlarmControlPanelEntity): class HomematicipAlarmControlPanelEntity(AlarmControlPanelEntity):
"""Representation of the HomematicIP alarm control panel.""" """Representation of the HomematicIP alarm control panel."""
_attr_should_poll = False
_attr_supported_features = ( _attr_supported_features = (
AlarmControlPanelEntityFeature.ARM_HOME AlarmControlPanelEntityFeature.ARM_HOME
| AlarmControlPanelEntityFeature.ARM_AWAY | AlarmControlPanelEntityFeature.ARM_AWAY
@ -120,11 +121,6 @@ class HomematicipAlarmControlPanelEntity(AlarmControlPanelEntity):
name = f"{self._home.name} {name}" name = f"{self._home.name} {name}"
return name return name
@property
def should_poll(self) -> bool:
"""No polling needed."""
return False
@property @property
def available(self) -> bool: def available(self) -> bool:
"""Return if alarm control panel is available.""" """Return if alarm control panel is available."""

View File

@ -72,6 +72,8 @@ GROUP_ATTRIBUTES = {
class HomematicipGenericEntity(Entity): class HomematicipGenericEntity(Entity):
"""Representation of the HomematicIP generic entity.""" """Representation of the HomematicIP generic entity."""
_attr_should_poll = False
def __init__( def __init__(
self, self,
hap: HomematicipHAP, hap: HomematicipHAP,
@ -201,11 +203,6 @@ class HomematicipGenericEntity(Entity):
return name return name
@property
def should_poll(self) -> bool:
"""No polling needed."""
return False
@property @property
def available(self) -> bool: def available(self) -> bool:
"""Return if entity is available.""" """Return if entity is available."""

View File

@ -588,6 +588,7 @@ class HuaweiLteBaseEntity(Entity):
_available: bool = field(default=True, init=False) _available: bool = field(default=True, init=False)
_unsub_handlers: list[Callable] = field(default_factory=list, init=False) _unsub_handlers: list[Callable] = field(default_factory=list, init=False)
_attr_has_entity_name: bool = field(default=True, init=False) _attr_has_entity_name: bool = field(default=True, init=False)
_attr_should_poll = False
@property @property
def _device_unique_id(self) -> str: def _device_unique_id(self) -> str:
@ -604,11 +605,6 @@ class HuaweiLteBaseEntity(Entity):
"""Return whether the entity is available.""" """Return whether the entity is available."""
return self._available return self._available
@property
def should_poll(self) -> bool:
"""Huawei LTE entities report their state without polling."""
return False
async def async_update(self) -> None: async def async_update(self) -> None:
"""Update state.""" """Update state."""
raise NotImplementedError raise NotImplementedError

View File

@ -125,6 +125,7 @@ class HyperionBaseLight(LightEntity):
"""A Hyperion light base class.""" """A Hyperion light base class."""
_attr_color_mode = ColorMode.HS _attr_color_mode = ColorMode.HS
_attr_should_poll = False
_attr_supported_color_modes = {ColorMode.HS} _attr_supported_color_modes = {ColorMode.HS}
_attr_supported_features = LightEntityFeature.EFFECT _attr_supported_features = LightEntityFeature.EFFECT
@ -178,11 +179,6 @@ class HyperionBaseLight(LightEntity):
"""Whether or not the entity is enabled by default.""" """Whether or not the entity is enabled by default."""
return True return True
@property
def should_poll(self) -> bool:
"""Return whether or not this entity should be polled."""
return False
@property @property
def name(self) -> str: def name(self) -> str:
"""Return the name of the light.""" """Return the name of the light."""

View File

@ -127,6 +127,7 @@ class HyperionComponentSwitch(SwitchEntity):
"""ComponentBinarySwitch switch class.""" """ComponentBinarySwitch switch class."""
_attr_entity_category = EntityCategory.CONFIG _attr_entity_category = EntityCategory.CONFIG
_attr_should_poll = False
def __init__( def __init__(
self, self,
@ -149,11 +150,6 @@ class HyperionComponentSwitch(SwitchEntity):
f"{KEY_COMPONENTS}-{KEY_UPDATE}": self._update_components f"{KEY_COMPONENTS}-{KEY_UPDATE}": self._update_components
} }
@property
def should_poll(self) -> bool:
"""Return whether or not this entity should be polled."""
return False
@property @property
def entity_registry_enabled_default(self) -> bool: def entity_registry_enabled_default(self) -> bool:
"""Whether or not the entity is enabled by default.""" """Whether or not the entity is enabled by default."""

View File

@ -194,6 +194,8 @@ class AqualinkEntity(Entity):
class. class.
""" """
_attr_should_poll = False
def __init__(self, dev: AqualinkDevice) -> None: def __init__(self, dev: AqualinkDevice) -> None:
"""Initialize the entity.""" """Initialize the entity."""
self.dev = dev self.dev = dev
@ -204,15 +206,6 @@ class AqualinkEntity(Entity):
async_dispatcher_connect(self.hass, DOMAIN, self.async_write_ha_state) async_dispatcher_connect(self.hass, DOMAIN, self.async_write_ha_state)
) )
@property
def should_poll(self) -> bool:
"""Return False as entities shouldn't be polled.
Entities are checked periodically as the integration runs periodic
updates on a timer.
"""
return False
@property @property
def unique_id(self) -> str: def unique_id(self) -> str:
"""Return a unique identifier for this entity.""" """Return a unique identifier for this entity."""

View File

@ -56,6 +56,7 @@ class IcloudDeviceBatterySensor(SensorEntity):
_attr_device_class = SensorDeviceClass.BATTERY _attr_device_class = SensorDeviceClass.BATTERY
_attr_native_unit_of_measurement = PERCENTAGE _attr_native_unit_of_measurement = PERCENTAGE
_attr_should_poll = False
def __init__(self, account: IcloudAccount, device: IcloudDevice) -> None: def __init__(self, account: IcloudAccount, device: IcloudDevice) -> None:
"""Initialize the battery sensor.""" """Initialize the battery sensor."""
@ -102,11 +103,6 @@ class IcloudDeviceBatterySensor(SensorEntity):
name=self._device.name, name=self._device.name,
) )
@property
def should_poll(self) -> bool:
"""No polling needed."""
return False
async def async_added_to_hass(self): async def async_added_to_hass(self):
"""Register state update callback.""" """Register state update callback."""
self._unsub_dispatcher = async_dispatcher_connect( self._unsub_dispatcher = async_dispatcher_connect(

View File

@ -18,6 +18,8 @@ class IHCDevice(Entity):
Derived classes must implement the on_ihc_change method Derived classes must implement the on_ihc_change method
""" """
_attr_should_poll = False
def __init__( def __init__(
self, self,
ihc_controller: IHCController, ihc_controller: IHCController,
@ -56,11 +58,6 @@ class IHCDevice(Entity):
_LOGGER.debug("Adding IHC entity notify event: %s", self.ihc_id) _LOGGER.debug("Adding IHC entity notify event: %s", self.ihc_id)
self.ihc_controller.add_notify_event(self.ihc_id, self.on_ihc_change, True) self.ihc_controller.add_notify_event(self.ihc_id, self.on_ihc_change, True)
@property
def should_poll(self) -> bool:
"""No polling needed for IHC devices."""
return False
@property @property
def name(self): def name(self):
"""Return the device name.""" """Return the device name."""

View File

@ -91,6 +91,8 @@ class IncomfortEntity(Entity):
class IncomfortChild(IncomfortEntity): class IncomfortChild(IncomfortEntity):
"""Base class for all InComfort entities (excluding the boiler).""" """Base class for all InComfort entities (excluding the boiler)."""
_attr_should_poll = False
async def async_added_to_hass(self) -> None: async def async_added_to_hass(self) -> None:
"""Set up a listener when this entity is added to HA.""" """Set up a listener when this entity is added to HA."""
self.async_on_remove(async_dispatcher_connect(self.hass, DOMAIN, self._refresh)) self.async_on_remove(async_dispatcher_connect(self.hass, DOMAIN, self._refresh))
@ -98,8 +100,3 @@ class IncomfortChild(IncomfortEntity):
@callback @callback
def _refresh(self) -> None: def _refresh(self) -> None:
self.async_schedule_update_ha_state(force_refresh=True) self.async_schedule_update_ha_state(force_refresh=True)
@property
def should_poll(self) -> bool:
"""Return False as this device should never be polled."""
return False

View File

@ -234,6 +234,8 @@ class DateTimeStorageCollection(collection.StorageCollection):
class InputDatetime(RestoreEntity): class InputDatetime(RestoreEntity):
"""Representation of a datetime input.""" """Representation of a datetime input."""
_attr_should_poll = False
def __init__(self, config: dict) -> None: def __init__(self, config: dict) -> None:
"""Initialize a select input.""" """Initialize a select input."""
self._config = config self._config = config
@ -303,11 +305,6 @@ class InputDatetime(RestoreEntity):
tzinfo=dt_util.DEFAULT_TIME_ZONE tzinfo=dt_util.DEFAULT_TIME_ZONE
) )
@property
def should_poll(self):
"""If entity should be polled."""
return False
@property @property
def name(self): def name(self):
"""Return the name of the select input.""" """Return the name of the select input."""

View File

@ -205,6 +205,8 @@ class NumberStorageCollection(collection.StorageCollection):
class InputNumber(RestoreEntity): class InputNumber(RestoreEntity):
"""Representation of a slider.""" """Representation of a slider."""
_attr_should_poll = False
def __init__(self, config: dict) -> None: def __init__(self, config: dict) -> None:
"""Initialize an input number.""" """Initialize an input number."""
self._config = config self._config = config
@ -219,11 +221,6 @@ class InputNumber(RestoreEntity):
input_num.editable = False input_num.editable = False
return input_num return input_num
@property
def should_poll(self):
"""If entity should be polled."""
return False
@property @property
def _minimum(self) -> float: def _minimum(self) -> float:
"""Return minimum allowed value.""" """Return minimum allowed value."""

View File

@ -198,6 +198,8 @@ class InputTextStorageCollection(collection.StorageCollection):
class InputText(RestoreEntity): class InputText(RestoreEntity):
"""Represent a text box.""" """Represent a text box."""
_attr_should_poll = False
def __init__(self, config: dict) -> None: def __init__(self, config: dict) -> None:
"""Initialize a text input.""" """Initialize a text input."""
self._config = config self._config = config
@ -212,11 +214,6 @@ class InputText(RestoreEntity):
input_text.editable = False input_text.editable = False
return input_text return input_text
@property
def should_poll(self):
"""If entity should be polled."""
return False
@property @property
def name(self): def name(self):
"""Return the name of the text input entity.""" """Return the name of the text input entity."""

View File

@ -28,6 +28,8 @@ _LOGGER = logging.getLogger(__name__)
class InsteonEntity(Entity): class InsteonEntity(Entity):
"""INSTEON abstract base entity.""" """INSTEON abstract base entity."""
_attr_should_poll = False
def __init__(self, device, group): def __init__(self, device, group):
"""Initialize the INSTEON binary sensor.""" """Initialize the INSTEON binary sensor."""
self._insteon_device_group = device.groups[group] self._insteon_device_group = device.groups[group]
@ -37,11 +39,6 @@ class InsteonEntity(Entity):
"""Return the hash of the Insteon Entity.""" """Return the hash of the Insteon Entity."""
return hash(self._insteon_device) return hash(self._insteon_device)
@property
def should_poll(self):
"""No polling needed."""
return False
@property @property
def address(self): def address(self):
"""Return the address of the node.""" """Return the address of the node."""

View File

@ -143,6 +143,8 @@ async def async_setup_platform(
class IntesisAC(ClimateEntity): class IntesisAC(ClimateEntity):
"""Represents an Intesishome air conditioning device.""" """Represents an Intesishome air conditioning device."""
_attr_should_poll = False
def __init__(self, ih_device_id, ih_device, controller): def __init__(self, ih_device_id, ih_device, controller):
"""Initialize the thermostat.""" """Initialize the thermostat."""
self._controller = controller self._controller = controller
@ -410,11 +412,6 @@ class IntesisAC(ClimateEntity):
"""Return the maximum temperature for the current mode of operation.""" """Return the maximum temperature for the current mode of operation."""
return self._max_temp return self._max_temp
@property
def should_poll(self):
"""Poll for updates if pyIntesisHome doesn't have a socket open."""
return False
@property @property
def fan_mode(self): def fan_mode(self):
"""Return whether the fan is on.""" """Return whether the fan is on."""

View File

@ -126,6 +126,8 @@ def _return_on_connection_error(ret=None):
class ControllerDevice(ClimateEntity): class ControllerDevice(ClimateEntity):
"""Representation of iZone Controller.""" """Representation of iZone Controller."""
_attr_should_poll = False
def __init__(self, controller: Controller) -> None: def __init__(self, controller: Controller) -> None:
"""Initialise ControllerDevice.""" """Initialise ControllerDevice."""
self._controller = controller self._controller = controller
@ -250,14 +252,6 @@ class ControllerDevice(ClimateEntity):
"""Return the name of the entity.""" """Return the name of the entity."""
return f"iZone Controller {self._controller.device_uid}" return f"iZone Controller {self._controller.device_uid}"
@property
def should_poll(self) -> bool:
"""Return True if entity has to be polled for state.
False if entity pushes its state to HA.
"""
return False
@property @property
def temperature_unit(self) -> str: def temperature_unit(self) -> str:
"""Return the unit of measurement which this thermostat uses.""" """Return the unit of measurement which this thermostat uses."""
@ -448,6 +442,8 @@ class ControllerDevice(ClimateEntity):
class ZoneDevice(ClimateEntity): class ZoneDevice(ClimateEntity):
"""Representation of iZone Zone.""" """Representation of iZone Zone."""
_attr_should_poll = False
def __init__(self, controller: ControllerDevice, zone: Zone) -> None: def __init__(self, controller: ControllerDevice, zone: Zone) -> None:
"""Initialise ZoneDevice.""" """Initialise ZoneDevice."""
self._controller = controller self._controller = controller
@ -525,14 +521,6 @@ class ZoneDevice(ClimateEntity):
"""Return the name of the entity.""" """Return the name of the entity."""
return self._name return self._name
@property
def should_poll(self) -> bool:
"""Return True if entity has to be polled for state.
False if entity pushes its state to HA.
"""
return False
@property # type: ignore[misc] @property # type: ignore[misc]
@_return_on_connection_error(0) @_return_on_connection_error(0)
def supported_features(self): def supported_features(self):