Use _attr_should_poll in components [a-g] (#77268)

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

View File

@ -173,6 +173,8 @@ class CounterStorageCollection(collection.StorageCollection):
class Counter(RestoreEntity):
"""Representation of a counter."""
_attr_should_poll: bool = False
def __init__(self, config: dict) -> None:
"""Initialize a counter."""
self._config: dict = config
@ -187,11 +189,6 @@ class Counter(RestoreEntity):
counter.entity_id = ENTITY_ID_FORMAT.format(config[CONF_ID])
return counter
@property
def should_poll(self) -> bool:
"""If entity should be polled."""
return False
@property
def name(self) -> str | None:
"""Return name of the counter."""

View File

@ -368,6 +368,8 @@ class EDL21:
class EDL21Entity(SensorEntity):
"""Entity reading values from EDL21 telegram."""
_attr_should_poll = False
def __init__(self, electricity_id, obis, name, entity_description, telegram):
"""Initialize an EDL21Entity."""
self._electricity_id = electricity_id
@ -416,11 +418,6 @@ class EDL21Entity(SensorEntity):
if self._async_remove_dispatcher:
self._async_remove_dispatcher()
@property
def should_poll(self) -> bool:
"""Do not poll."""
return False
@property
def unique_id(self) -> str:
"""Return a unique ID."""

View File

@ -444,6 +444,7 @@ class ElkEntity(Entity):
"""Base class for all Elk entities."""
_attr_has_entity_name = True
_attr_should_poll = False
def __init__(self, element: Element, elk: Elk, elk_data: dict[str, Any]) -> None:
"""Initialize the base of all Elk devices."""
@ -472,11 +473,6 @@ class ElkEntity(Entity):
"""Return unique id of the element."""
return self._unique_id
@property
def should_poll(self) -> bool:
"""Don't poll this device."""
return False
@property
def extra_state_attributes(self) -> dict[str, Any]:
"""Return the default attributes of the element."""

View File

@ -248,6 +248,8 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
class EnvisalinkDevice(Entity):
"""Representation of an Envisalink device."""
_attr_should_poll = False
def __init__(self, name, info, controller):
"""Initialize the device."""
self._controller = controller
@ -258,8 +260,3 @@ class EnvisalinkDevice(Entity):
def name(self):
"""Return the name of the device."""
return self._name
@property
def should_poll(self):
"""No polling needed."""
return False

View File

@ -675,6 +675,8 @@ ENTITY_CATEGORIES: EsphomeEnumMapper[
class EsphomeEntity(Entity, Generic[_InfoT, _StateT]):
"""Define a base esphome entity."""
_attr_should_poll = False
def __init__(
self,
entry_data: RuntimeEntryData,
@ -804,11 +806,6 @@ class EsphomeEntity(Entity, Generic[_InfoT, _StateT]):
return cast(str, ICON_SCHEMA(self._static_info.icon))
@property
def should_poll(self) -> bool:
"""Disable polling."""
return False
@property
def entity_registry_enabled_default(self) -> bool:
"""Return if the entity should be enabled when first added to the entity registry."""

View File

@ -167,6 +167,8 @@ class FFmpegManager:
class FFmpegBase(Entity):
"""Interface object for FFmpeg."""
_attr_should_poll = False
def __init__(self, initial_state=True):
"""Initialize ffmpeg base object."""
self.ffmpeg = None
@ -201,11 +203,6 @@ class FFmpegBase(Entity):
"""Return True if entity is available."""
return self.ffmpeg.is_running
@property
def should_poll(self):
"""Return True if entity has to be polled for state."""
return False
async def _async_start_ffmpeg(self, entity_ids):
"""Start a FFmpeg process.

View File

@ -540,6 +540,8 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
class FibaroDevice(Entity):
"""Representation of a Fibaro device entity."""
_attr_should_poll = False
def __init__(self, fibaro_device):
"""Initialize the device."""
self.fibaro_device = fibaro_device
@ -634,11 +636,6 @@ class FibaroDevice(Entity):
return True
return False
@property
def should_poll(self):
"""Get polling requirement from fibaro device."""
return False
@property
def extra_state_attributes(self):
"""Return the state attributes of the device."""

View File

@ -26,6 +26,8 @@ async def async_setup_entry(
class IncidentsSensor(RestoreEntity, SensorEntity):
"""Representation of FireServiceRota incidents sensor."""
_attr_should_poll = False
def __init__(self, client):
"""Initialize."""
self._client = client
@ -60,11 +62,6 @@ class IncidentsSensor(RestoreEntity, SensorEntity):
"""Return the unique ID of the sensor."""
return self._unique_id
@property
def should_poll(self) -> bool:
"""No polling needed."""
return False
@property
def extra_state_attributes(self) -> dict[str, Any]:
"""Return available attributes for sensor."""

View File

@ -27,6 +27,8 @@ async def async_setup_entry(
class ResponseSwitch(SwitchEntity):
"""Representation of an FireServiceRota switch."""
_attr_should_poll = False
def __init__(self, coordinator, client, entry):
"""Initialize."""
self._coordinator = coordinator
@ -63,11 +65,6 @@ class ResponseSwitch(SwitchEntity):
"""Return the unique ID for this switch."""
return self._unique_id
@property
def should_poll(self) -> bool:
"""No polling needed."""
return False
@property
def available(self) -> bool:
"""Return if switch is available."""

View File

@ -31,6 +31,8 @@ class FirmataEntity:
class FirmataPinEntity(FirmataEntity):
"""Representation of a Firmata pin entity."""
_attr_should_poll = False
def __init__(
self,
api: FirmataBoardPin,
@ -50,11 +52,6 @@ class FirmataPinEntity(FirmataEntity):
"""Get the name of the pin."""
return self._name
@property
def should_poll(self) -> bool:
"""No polling needed."""
return False
@property
def unique_id(self) -> str:
"""Return a unique identifier for this device."""

View File

@ -130,6 +130,8 @@ async def update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
class ForkedDaapdZone(MediaPlayerEntity):
"""Representation of a forked-daapd output."""
_attr_should_poll = False
def __init__(self, api, output, entry_id):
"""Initialize the ForkedDaapd Zone."""
self._api = api
@ -164,11 +166,6 @@ class ForkedDaapdZone(MediaPlayerEntity):
"""Return unique ID."""
return f"{self._entry_id}-{self._output_id}"
@property
def should_poll(self) -> bool:
"""Entity pushes its state to HA."""
return False
async def async_toggle(self) -> None:
"""Toggle the power on the zone."""
if self.state == STATE_OFF:
@ -235,6 +232,8 @@ class ForkedDaapdZone(MediaPlayerEntity):
class ForkedDaapdMaster(MediaPlayerEntity):
"""Representation of the main forked-daapd device."""
_attr_should_poll = False
def __init__(
self, clientsession, api, ip_address, api_port, api_password, config_entry
):
@ -412,11 +411,6 @@ class ForkedDaapdMaster(MediaPlayerEntity):
"""Return unique ID."""
return self._config_entry.entry_id
@property
def should_poll(self) -> bool:
"""Entity pushes its state to HA."""
return False
@property
def available(self) -> bool:
"""Return whether the master is available."""

View File

@ -55,6 +55,8 @@ def add_entities(
class FreeboxDevice(ScannerEntity):
"""Representation of a Freebox device."""
_attr_should_poll = False
def __init__(self, router: FreeboxRouter, device: dict[str, Any]) -> None:
"""Initialize a Freebox device."""
self._router = router
@ -112,11 +114,6 @@ class FreeboxDevice(ScannerEntity):
"""Return the attributes."""
return self._attrs
@property
def should_poll(self) -> bool:
"""No polling needed."""
return False
@callback
def async_on_demand_update(self):
"""Update state."""

View File

@ -41,6 +41,8 @@ async def async_setup_entry(
class GdacsSensor(SensorEntity):
"""This is a status sensor for the GDACS integration."""
_attr_should_poll = False
def __init__(self, config_entry_id, config_unique_id, config_title, manager):
"""Initialize entity."""
self._config_entry_id = config_entry_id
@ -79,11 +81,6 @@ class GdacsSensor(SensorEntity):
_LOGGER.debug("Received status update for %s", self._config_entry_id)
self.async_schedule_update_ha_state(True)
@property
def should_poll(self):
"""No polling needed for GDACS status sensor."""
return False
async def async_update(self):
"""Update this entity from the data held in the feed manager."""
_LOGGER.debug("Updating %s", self._config_entry_id)

View File

@ -112,6 +112,8 @@ async def async_setup_platform(
class GenericHygrostat(HumidifierEntity, RestoreEntity):
"""Representation of a Generic Hygrostat device."""
_attr_should_poll = False
def __init__(
self,
name,
@ -218,11 +220,6 @@ class GenericHygrostat(HumidifierEntity, RestoreEntity):
return {ATTR_SAVED_HUMIDITY: self._saved_target_humidity}
return None
@property
def should_poll(self):
"""Return the polling state."""
return False
@property
def name(self):
"""Return the name of the hygrostat."""

View File

@ -165,6 +165,8 @@ async def async_setup_platform(
class GenericThermostat(ClimateEntity, RestoreEntity):
"""Representation of a Generic Thermostat device."""
_attr_should_poll = False
def __init__(
self,
name,
@ -300,11 +302,6 @@ class GenericThermostat(ClimateEntity, RestoreEntity):
if not self._hvac_mode:
self._hvac_mode = HVACMode.OFF
@property
def should_poll(self):
"""Return the polling state."""
return False
@property
def name(self):
"""Return the name of the thermostat."""

View File

@ -221,6 +221,8 @@ class GeniusBroker:
class GeniusEntity(Entity):
"""Base for all Genius Hub entities."""
_attr_should_poll = False
def __init__(self) -> None:
"""Initialize the entity."""
self._unique_id: str | None = None
@ -238,11 +240,6 @@ class GeniusEntity(Entity):
"""Return a unique ID."""
return self._unique_id
@property
def should_poll(self) -> bool:
"""Return False as geniushub entities should not be polled."""
return False
class GeniusDevice(GeniusEntity):
"""Base for all Genius Hub devices."""

View File

@ -42,6 +42,8 @@ async def async_setup_entry(
class GeonetnzQuakesSensor(SensorEntity):
"""This is a status sensor for the GeoNet NZ Quakes integration."""
_attr_should_poll = False
def __init__(self, config_entry_id, config_unique_id, config_title, manager):
"""Initialize entity."""
self._config_entry_id = config_entry_id
@ -80,11 +82,6 @@ class GeonetnzQuakesSensor(SensorEntity):
_LOGGER.debug("Received status update for %s", self._config_entry_id)
self.async_schedule_update_ha_state(True)
@property
def should_poll(self):
"""No polling needed for GeoNet NZ Quakes status sensor."""
return False
async def async_update(self):
"""Update this entity from the data held in the feed manager."""
_LOGGER.debug("Updating %s", self._config_entry_id)

View File

@ -61,6 +61,8 @@ async def async_setup_entry(
class GeonetnzVolcanoSensor(SensorEntity):
"""This represents an external event with GeoNet NZ Volcano feed data."""
_attr_should_poll = False
def __init__(self, config_entry_id, feed_manager, external_id, unit_system):
"""Initialize entity with data from feed entry."""
self._config_entry_id = config_entry_id
@ -97,11 +99,6 @@ class GeonetnzVolcanoSensor(SensorEntity):
"""Call update method."""
self.async_schedule_update_ha_state(True)
@property
def should_poll(self):
"""No polling needed for GeoNet NZ Volcano feed location events."""
return False
async def async_update(self):
"""Update this entity from the data held in the feed manager."""
_LOGGER.debug("Updating %s", self._external_id)