Use _attr_should_poll in components [o-r] (#77364)

This commit is contained in:
epenet 2022-08-26 21:41:41 +02:00 committed by GitHub
parent 4142530368
commit d32f3e359f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 34 additions and 98 deletions

View file

@ -83,6 +83,8 @@ async def async_setup_entry(
class OpenThermBinarySensor(BinarySensorEntity): class OpenThermBinarySensor(BinarySensorEntity):
"""Represent an OpenTherm Gateway binary sensor.""" """Represent an OpenTherm Gateway binary sensor."""
_attr_should_poll = False
def __init__(self, gw_dev, var, source, device_class, friendly_name_format): def __init__(self, gw_dev, var, source, device_class, friendly_name_format):
"""Initialize the binary sensor.""" """Initialize the binary sensor."""
self.entity_id = async_generate_entity_id( self.entity_id = async_generate_entity_id(
@ -162,11 +164,6 @@ class OpenThermBinarySensor(BinarySensorEntity):
"""Return the class of this device.""" """Return the class of this device."""
return self._device_class return self._device_class
@property
def should_poll(self):
"""Return False because entity pushes its state."""
return False
class DeprecatedOpenThermBinarySensor(OpenThermBinarySensor): class DeprecatedOpenThermBinarySensor(OpenThermBinarySensor):
"""Represent a deprecated OpenTherm Gateway Binary Sensor.""" """Represent a deprecated OpenTherm Gateway Binary Sensor."""

View file

@ -62,6 +62,7 @@ async def async_setup_entry(
class OpenThermClimate(ClimateEntity): class OpenThermClimate(ClimateEntity):
"""Representation of a climate device.""" """Representation of a climate device."""
_attr_should_poll = False
_attr_supported_features = ( _attr_supported_features = (
ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE
) )
@ -201,11 +202,6 @@ class OpenThermClimate(ClimateEntity):
return PRECISION_HALVES return PRECISION_HALVES
return PRECISION_WHOLE return PRECISION_WHOLE
@property
def should_poll(self):
"""Disable polling for this entity."""
return False
@property @property
def temperature_unit(self): def temperature_unit(self):
"""Return the unit of measurement used by the platform.""" """Return the unit of measurement used by the platform."""

View file

@ -86,6 +86,8 @@ async def async_setup_entry(
class OpenThermSensor(SensorEntity): class OpenThermSensor(SensorEntity):
"""Representation of an OpenTherm Gateway sensor.""" """Representation of an OpenTherm Gateway sensor."""
_attr_should_poll = False
def __init__(self, gw_dev, var, source, device_class, unit, friendly_name_format): def __init__(self, gw_dev, var, source, device_class, unit, friendly_name_format):
"""Initialize the OpenTherm Gateway sensor.""" """Initialize the OpenTherm Gateway sensor."""
self.entity_id = async_generate_entity_id( self.entity_id = async_generate_entity_id(
@ -171,11 +173,6 @@ class OpenThermSensor(SensorEntity):
"""Return the unit of measurement.""" """Return the unit of measurement."""
return self._unit return self._unit
@property
def should_poll(self):
"""Return False because entity pushes its state."""
return False
class DeprecatedOpenThermSensor(OpenThermSensor): class DeprecatedOpenThermSensor(OpenThermSensor):
"""Represent a deprecated OpenTherm Gateway Sensor.""" """Represent a deprecated OpenTherm Gateway Sensor."""

View file

@ -44,6 +44,8 @@ async def async_setup_platform(
class TOTPSensor(SensorEntity): class TOTPSensor(SensorEntity):
"""Representation of a TOTP sensor.""" """Representation of a TOTP sensor."""
_attr_should_poll = False
def __init__(self, name, token): def __init__(self, name, token):
"""Initialize the sensor.""" """Initialize the sensor."""
self._name = name self._name = name
@ -75,11 +77,6 @@ class TOTPSensor(SensorEntity):
"""Return the state of the sensor.""" """Return the state of the sensor."""
return self._state return self._state
@property
def should_poll(self):
"""No polling needed."""
return False
@property @property
def icon(self): def icon(self):
"""Return the icon to use in the frontend.""" """Return the icon to use in the frontend."""

View file

@ -356,6 +356,8 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
class Person(RestoreEntity): class Person(RestoreEntity):
"""Represent a tracked person.""" """Represent a tracked person."""
_attr_should_poll = False
def __init__(self, config): def __init__(self, config):
"""Set up person.""" """Set up person."""
self._config = config self._config = config
@ -384,14 +386,6 @@ class Person(RestoreEntity):
"""Return entity picture.""" """Return entity picture."""
return self._config.get(CONF_PICTURE) return self._config.get(CONF_PICTURE)
@property
def should_poll(self):
"""Return True if entity has to be polled for state.
False if entity pushes its state to HA.
"""
return False
@property @property
def state(self): def state(self):
"""Return the state of the person.""" """Return the state of the person."""

View file

@ -56,6 +56,8 @@ SWITCHES_SCHEMA = vol.Schema(
class PilightBaseDevice(RestoreEntity): class PilightBaseDevice(RestoreEntity):
"""Base class for pilight switches and lights.""" """Base class for pilight switches and lights."""
_attr_should_poll = False
def __init__(self, hass, name, config): def __init__(self, hass, name, config):
"""Initialize a device.""" """Initialize a device."""
self._hass = hass self._hass = hass
@ -95,11 +97,6 @@ class PilightBaseDevice(RestoreEntity):
"""Get the name of the switch.""" """Get the name of the switch."""
return self._name return self._name
@property
def should_poll(self):
"""No polling needed, state set when correct code is received."""
return False
@property @property
def assumed_state(self): def assumed_state(self):
"""Return True if unable to access real state of the entity.""" """Return True if unable to access real state of the entity."""

View file

@ -51,6 +51,8 @@ def setup_platform(
class PilightSensor(SensorEntity): class PilightSensor(SensorEntity):
"""Representation of a sensor that can be updated using Pilight.""" """Representation of a sensor that can be updated using Pilight."""
_attr_should_poll = False
def __init__(self, hass, name, variable, payload, unit_of_measurement): def __init__(self, hass, name, variable, payload, unit_of_measurement):
"""Initialize the sensor.""" """Initialize the sensor."""
self._state = None self._state = None
@ -62,11 +64,6 @@ class PilightSensor(SensorEntity):
hass.bus.listen(pilight.EVENT, self._handle_code) hass.bus.listen(pilight.EVENT, self._handle_code)
@property
def should_poll(self):
"""No polling needed."""
return False
@property @property
def name(self): def name(self):
"""Return the name of the sensor.""" """Return the name of the sensor."""

View file

@ -19,6 +19,8 @@ from .const import (
class PlaatoEntity(entity.Entity): class PlaatoEntity(entity.Entity):
"""Representation of a Plaato Entity.""" """Representation of a Plaato Entity."""
_attr_should_poll = False
def __init__(self, data, sensor_type, coordinator=None): def __init__(self, data, sensor_type, coordinator=None):
"""Initialize the sensor.""" """Initialize the sensor."""
self._coordinator = coordinator self._coordinator = coordinator
@ -83,11 +85,6 @@ class PlaatoEntity(entity.Entity):
return self._coordinator.last_update_success return self._coordinator.last_update_success
return True return True
@property
def should_poll(self):
"""Return the polling state."""
return False
async def async_added_to_hass(self): async def async_added_to_hass(self):
"""When entity is added to hass.""" """When entity is added to hass."""
if self._coordinator is not None: if self._coordinator is not None:

View file

@ -130,6 +130,8 @@ class Plant(Entity):
configurable min and max values. configurable min and max values.
""" """
_attr_should_poll = False
READINGS = { READINGS = {
READING_BATTERY: { READING_BATTERY: {
ATTR_UNIT_OF_MEASUREMENT: PERCENTAGE, ATTR_UNIT_OF_MEASUREMENT: PERCENTAGE,
@ -323,11 +325,6 @@ class Plant(Entity):
_LOGGER.debug("Initializing from database completed") _LOGGER.debug("Initializing from database completed")
@property
def should_poll(self):
"""No polling needed."""
return False
@property @property
def name(self): def name(self):
"""Return the name of the sensor.""" """Return the name of the sensor."""

View file

@ -65,6 +65,8 @@ async def async_setup_entry(
class PlumLight(LightEntity): class PlumLight(LightEntity):
"""Representation of a Plum Lightpad dimmer.""" """Representation of a Plum Lightpad dimmer."""
_attr_should_poll = False
def __init__(self, load): def __init__(self, load):
"""Initialize the light.""" """Initialize the light."""
self._load = load self._load = load
@ -79,11 +81,6 @@ class PlumLight(LightEntity):
self._brightness = event["level"] self._brightness = event["level"]
self.schedule_update_ha_state() self.schedule_update_ha_state()
@property
def should_poll(self):
"""No polling needed."""
return False
@property @property
def unique_id(self): def unique_id(self):
"""Combine logical load ID with .light to guarantee it is unique.""" """Combine logical load ID with .light to guarantee it is unique."""
@ -142,6 +139,7 @@ class GlowRing(LightEntity):
"""Representation of a Plum Lightpad dimmer glow ring.""" """Representation of a Plum Lightpad dimmer glow ring."""
_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}
def __init__(self, lightpad): def __init__(self, lightpad):
@ -178,11 +176,6 @@ class GlowRing(LightEntity):
"""Return the hue and saturation color value [float, float].""" """Return the hue and saturation color value [float, float]."""
return color_util.color_RGB_to_hs(self._red, self._green, self._blue) return color_util.color_RGB_to_hs(self._red, self._green, self._blue)
@property
def should_poll(self):
"""No polling needed."""
return False
@property @property
def unique_id(self): def unique_id(self):
"""Combine LightPad ID with .glow to guarantee it is unique.""" """Combine LightPad ID with .glow to guarantee it is unique."""

View file

@ -256,6 +256,8 @@ class MinutPointClient:
class MinutPointEntity(Entity): class MinutPointEntity(Entity):
"""Base Entity used by the sensors.""" """Base Entity used by the sensors."""
_attr_should_poll = False
def __init__(self, point_client, device_id, device_class): def __init__(self, point_client, device_id, device_class):
"""Initialize the entity.""" """Initialize the entity."""
self._async_unsub_dispatcher_connect = None self._async_unsub_dispatcher_connect = None
@ -347,11 +349,6 @@ class MinutPointEntity(Entity):
last_update = parse_datetime(self.device.last_update) last_update = parse_datetime(self.device.last_update)
return last_update return last_update
@property
def should_poll(self):
"""No polling needed for point."""
return False
@property @property
def unique_id(self): def unique_id(self):
"""Return the unique id of the sensor.""" """Return the unique id of the sensor."""

View file

@ -72,6 +72,8 @@ CONFIG_SCHEMA = vol.Schema(
class QSEntity(Entity): class QSEntity(Entity):
"""Qwikswitch Entity base.""" """Qwikswitch Entity base."""
_attr_should_poll = False
def __init__(self, qsid, name): def __init__(self, qsid, name):
"""Initialize the QSEntity.""" """Initialize the QSEntity."""
self._name = name self._name = name
@ -82,11 +84,6 @@ class QSEntity(Entity):
"""Return the name of the sensor.""" """Return the name of the sensor."""
return self._name return self._name
@property
def should_poll(self):
"""QS sensors gets packets in update_packet."""
return False
@property @property
def unique_id(self): def unique_id(self):
"""Return a unique identifier for this sensor.""" """Return a unique identifier for this sensor."""

View file

@ -96,6 +96,8 @@ def setup_platform(
class RaspyRFMSwitch(SwitchEntity): class RaspyRFMSwitch(SwitchEntity):
"""Representation of a RaspyRFM switch.""" """Representation of a RaspyRFM switch."""
_attr_should_poll = False
def __init__(self, raspyrfm_client, name: str, gateway, controlunit): def __init__(self, raspyrfm_client, name: str, gateway, controlunit):
"""Initialize the switch.""" """Initialize the switch."""
self._raspyrfm_client = raspyrfm_client self._raspyrfm_client = raspyrfm_client
@ -111,11 +113,6 @@ class RaspyRFMSwitch(SwitchEntity):
"""Return the name of the device if any.""" """Return the name of the device if any."""
return self._name return self._name
@property
def should_poll(self):
"""Return True if polling should be used."""
return False
@property @property
def assumed_state(self): def assumed_state(self):
"""Return True when the current state can not be queried.""" """Return True when the current state can not be queried."""

View file

@ -66,6 +66,8 @@ def setup_platform(
class RemoteRPiGPIOBinarySensor(BinarySensorEntity): class RemoteRPiGPIOBinarySensor(BinarySensorEntity):
"""Represent a binary sensor that uses a Remote Raspberry Pi GPIO.""" """Represent a binary sensor that uses a Remote Raspberry Pi GPIO."""
_attr_should_poll = False
def __init__(self, name, sensor, invert_logic): def __init__(self, name, sensor, invert_logic):
"""Initialize the RPi binary sensor.""" """Initialize the RPi binary sensor."""
self._name = name self._name = name
@ -84,11 +86,6 @@ class RemoteRPiGPIOBinarySensor(BinarySensorEntity):
self._sensor.when_deactivated = read_gpio self._sensor.when_deactivated = read_gpio
self._sensor.when_activated = read_gpio self._sensor.when_activated = read_gpio
@property
def should_poll(self):
"""No polling needed."""
return False
@property @property
def name(self): def name(self):
"""Return the name of the sensor.""" """Return the name of the sensor."""

View file

@ -52,6 +52,8 @@ def setup_platform(
class RemoteRPiGPIOSwitch(SwitchEntity): class RemoteRPiGPIOSwitch(SwitchEntity):
"""Representation of a Remote Raspberry Pi GPIO.""" """Representation of a Remote Raspberry Pi GPIO."""
_attr_should_poll = False
def __init__(self, name, led): def __init__(self, name, led):
"""Initialize the pin.""" """Initialize the pin."""
self._name = name or DEVICE_DEFAULT_NAME self._name = name or DEVICE_DEFAULT_NAME
@ -63,11 +65,6 @@ class RemoteRPiGPIOSwitch(SwitchEntity):
"""Return the name of the switch.""" """Return the name of the switch."""
return self._name return self._name
@property
def should_poll(self):
"""No polling needed."""
return False
@property @property
def assumed_state(self): def assumed_state(self):
"""If unable to access real state of the entity.""" """If unable to access real state of the entity."""

View file

@ -60,6 +60,8 @@ STATE_MAP = {
class IRobotEntity(Entity): class IRobotEntity(Entity):
"""Base class for iRobot Entities.""" """Base class for iRobot Entities."""
_attr_should_poll = False
def __init__(self, roomba, blid): def __init__(self, roomba, blid):
"""Initialize the iRobot handler.""" """Initialize the iRobot handler."""
self.vacuum = roomba self.vacuum = roomba
@ -69,11 +71,6 @@ class IRobotEntity(Entity):
self._version = self.vacuum_state.get("softwareVer") self._version = self.vacuum_state.get("softwareVer")
self._sku = self.vacuum_state.get("sku") self._sku = self.vacuum_state.get("sku")
@property
def should_poll(self):
"""Disable polling."""
return False
@property @property
def robot_unique_id(self): def robot_unique_id(self):
"""Return the uniqueid of the vacuum cleaner.""" """Return the uniqueid of the vacuum cleaner."""

View file

@ -76,6 +76,7 @@ async def async_setup_entry(
class RoonDevice(MediaPlayerEntity): class RoonDevice(MediaPlayerEntity):
"""Representation of an Roon device.""" """Representation of an Roon device."""
_attr_should_poll = False
_attr_supported_features = ( _attr_supported_features = (
MediaPlayerEntityFeature.BROWSE_MEDIA MediaPlayerEntityFeature.BROWSE_MEDIA
| MediaPlayerEntityFeature.GROUPING | MediaPlayerEntityFeature.GROUPING
@ -295,11 +296,6 @@ class RoonDevice(MediaPlayerEntity):
"""Return the id of this roon client.""" """Return the id of this roon client."""
return self._unique_id return self._unique_id
@property
def should_poll(self):
"""Return True if entity has to be polled for state."""
return False
@property @property
def zone_id(self): def zone_id(self):
"""Return current session Id.""" """Return current session Id."""

View file

@ -70,6 +70,7 @@ async def async_setup_platform(
class RussoundZoneDevice(MediaPlayerEntity): class RussoundZoneDevice(MediaPlayerEntity):
"""Representation of a Russound Zone.""" """Representation of a Russound Zone."""
_attr_should_poll = False
_attr_supported_features = ( _attr_supported_features = (
MediaPlayerEntityFeature.VOLUME_MUTE MediaPlayerEntityFeature.VOLUME_MUTE
| MediaPlayerEntityFeature.VOLUME_SET | MediaPlayerEntityFeature.VOLUME_SET
@ -119,11 +120,6 @@ class RussoundZoneDevice(MediaPlayerEntity):
self._russ.add_zone_callback(self._zone_callback_handler) self._russ.add_zone_callback(self._zone_callback_handler)
self._russ.add_source_callback(self._source_callback_handler) self._russ.add_source_callback(self._source_callback_handler)
@property
def should_poll(self):
"""No polling needed."""
return False
@property @property
def name(self): def name(self):
"""Return the name of the zone.""" """Return the name of the zone."""