Use _attr_should_poll in components [j-n] (#77357)

This commit is contained in:
epenet 2022-08-26 21:19:37 +02:00 committed by GitHub
parent b36321988f
commit dff9baf880
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 41 additions and 114 deletions

View file

@ -37,6 +37,8 @@ async def async_setup_platform(
class KaiterraAirQuality(AirQualityEntity): class KaiterraAirQuality(AirQualityEntity):
"""Implementation of a Kaittera air quality sensor.""" """Implementation of a Kaittera air quality sensor."""
_attr_should_poll = False
def __init__(self, api, name, device_id): def __init__(self, api, name, device_id):
"""Initialize the sensor.""" """Initialize the sensor."""
self._api = api self._api = api
@ -50,11 +52,6 @@ class KaiterraAirQuality(AirQualityEntity):
def _device(self): def _device(self):
return self._api.data.get(self._device_id, {}) return self._api.data.get(self._device_id, {})
@property
def should_poll(self):
"""Return that the sensor should not be polled."""
return False
@property @property
def available(self): def available(self):
"""Return the availability of the sensor.""" """Return the availability of the sensor."""

View file

@ -86,6 +86,8 @@ def update_items(router: KeeneticRouter, async_add_entities, tracked: set[str]):
class KeeneticTracker(ScannerEntity): class KeeneticTracker(ScannerEntity):
"""Representation of network device.""" """Representation of network device."""
_attr_should_poll = False
def __init__(self, device: Device, router: KeeneticRouter) -> None: def __init__(self, device: Device, router: KeeneticRouter) -> None:
"""Initialize the tracked device.""" """Initialize the tracked device."""
self._device = device self._device = device
@ -94,11 +96,6 @@ class KeeneticTracker(ScannerEntity):
dt_util.utcnow() if device.mac in router.last_devices else None dt_util.utcnow() if device.mac in router.last_devices else None
) )
@property
def should_poll(self) -> bool:
"""Return False since entity pushes its state to HA."""
return False
@property @property
def is_connected(self): def is_connected(self):
"""Return true if the device is connected to the network.""" """Return true if the device is connected to the network."""

View file

@ -34,6 +34,8 @@ def setup_platform(
class KiraReceiver(SensorEntity): class KiraReceiver(SensorEntity):
"""Implementation of a Kira Receiver.""" """Implementation of a Kira Receiver."""
_attr_should_poll = False
def __init__(self, name, kira): def __init__(self, name, kira):
"""Initialize the sensor.""" """Initialize the sensor."""
self._name = name self._name = name
@ -69,11 +71,6 @@ class KiraReceiver(SensorEntity):
"""Return the state attributes of the device.""" """Return the state attributes of the device."""
return {CONF_DEVICE: self._device} return {CONF_DEVICE: self._device}
@property
def should_poll(self) -> bool:
"""Entity should not be polled."""
return False
@property @property
def force_update(self) -> bool: def force_update(self) -> bool:
"""Kira should force updates. Repeated states have meaning.""" """Kira should force updates. Repeated states have meaning."""

View file

@ -37,6 +37,8 @@ async def async_setup_entry(
class KonnectedBinarySensor(BinarySensorEntity): class KonnectedBinarySensor(BinarySensorEntity):
"""Representation of a Konnected binary sensor.""" """Representation of a Konnected binary sensor."""
_attr_should_poll = False
def __init__(self, device_id, zone_num, data): def __init__(self, device_id, zone_num, data):
"""Initialize the Konnected binary sensor.""" """Initialize the Konnected binary sensor."""
self._data = data self._data = data
@ -62,11 +64,6 @@ class KonnectedBinarySensor(BinarySensorEntity):
"""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 device_class(self): def device_class(self):
"""Return the device class.""" """Return the device class."""

View file

@ -237,6 +237,8 @@ def _async_fire_send_keys_event(
class LcnEntity(Entity): class LcnEntity(Entity):
"""Parent class for all entities associated with the LCN component.""" """Parent class for all entities associated with the LCN component."""
_attr_should_poll = False
def __init__( def __init__(
self, config: ConfigType, entry_id: str, device_connection: DeviceConnectionType self, config: ConfigType, entry_id: str, device_connection: DeviceConnectionType
) -> None: ) -> None:
@ -280,11 +282,6 @@ class LcnEntity(Entity):
), ),
} }
@property
def should_poll(self) -> bool:
"""Lcn device entity pushes its state to HA."""
return False
async def async_added_to_hass(self) -> None: async def async_added_to_hass(self) -> None:
"""Run when entity about to be added to hass.""" """Run when entity about to be added to hass."""
if not self.device_connection.is_group: if not self.device_connection.is_group:

View file

@ -35,6 +35,8 @@ async def async_setup_entry(
class LiteJetSwitch(SwitchEntity): class LiteJetSwitch(SwitchEntity):
"""Representation of a single LiteJet switch.""" """Representation of a single LiteJet switch."""
_attr_should_poll = False
def __init__(self, entry_id, lj, i, name): # pylint: disable=invalid-name def __init__(self, entry_id, lj, i, name): # pylint: disable=invalid-name
"""Initialize a LiteJet switch.""" """Initialize a LiteJet switch."""
self._entry_id = entry_id self._entry_id = entry_id
@ -78,11 +80,6 @@ class LiteJetSwitch(SwitchEntity):
"""Return if the switch is pressed.""" """Return if the switch is pressed."""
return self._state return self._state
@property
def should_poll(self):
"""Return that polling is not necessary."""
return False
@property @property
def extra_state_attributes(self): def extra_state_attributes(self):
"""Return the device-specific state attributes.""" """Return the device-specific state attributes."""

View file

@ -116,6 +116,8 @@ def setup(hass: HomeAssistant, base_config: ConfigType) -> bool:
class LutronDevice(Entity): class LutronDevice(Entity):
"""Representation of a Lutron device entity.""" """Representation of a Lutron device entity."""
_attr_should_poll = False
def __init__(self, area_name, lutron_device, controller): def __init__(self, area_name, lutron_device, controller):
"""Initialize the device.""" """Initialize the device."""
self._lutron_device = lutron_device self._lutron_device = lutron_device
@ -135,11 +137,6 @@ class LutronDevice(Entity):
"""Return the name of the device.""" """Return the name of the device."""
return f"{self._area_name} {self._lutron_device.name}" return f"{self._area_name} {self._lutron_device.name}"
@property
def should_poll(self):
"""No polling needed."""
return False
@property @property
def unique_id(self): def unique_id(self):
"""Return a unique ID.""" """Return a unique ID."""

View file

@ -59,6 +59,7 @@ class LW12WiFi(LightEntity):
"""LW-12 WiFi LED Controller.""" """LW-12 WiFi LED Controller."""
_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 | LightEntityFeature.TRANSITION _attr_supported_features = LightEntityFeature.EFFECT | LightEntityFeature.TRANSITION
@ -115,11 +116,6 @@ class LW12WiFi(LightEntity):
"""Return True if unable to access real state of the entity.""" """Return True if unable to access real state of the entity."""
return True return True
@property
def should_poll(self) -> bool:
"""Return False to not poll the state of this entity."""
return False
def turn_on(self, **kwargs): def turn_on(self, **kwargs):
"""Instruct the light to turn on.""" """Instruct the light to turn on."""
self._light.light_on() self._light.light_on()

View file

@ -117,6 +117,7 @@ async def async_setup_platform(
class MediaroomDevice(MediaPlayerEntity): class MediaroomDevice(MediaPlayerEntity):
"""Representation of a Mediaroom set-up-box on the network.""" """Representation of a Mediaroom set-up-box on the network."""
_attr_should_poll = False
_attr_supported_features = ( _attr_supported_features = (
MediaPlayerEntityFeature.PAUSE MediaPlayerEntityFeature.PAUSE
| MediaPlayerEntityFeature.TURN_ON | MediaPlayerEntityFeature.TURN_ON
@ -163,11 +164,6 @@ class MediaroomDevice(MediaPlayerEntity):
else: else:
self._unique_id = None self._unique_id = None
@property
def should_poll(self):
"""No polling needed."""
return False
@property @property
def available(self): def available(self):
"""Return True if entity is available.""" """Return True if entity is available."""

View file

@ -207,6 +207,8 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
class MicrosoftFaceGroupEntity(Entity): class MicrosoftFaceGroupEntity(Entity):
"""Person-Group state/data Entity.""" """Person-Group state/data Entity."""
_attr_should_poll = False
def __init__(self, hass, api, g_id, name): def __init__(self, hass, api, g_id, name):
"""Initialize person/group entity.""" """Initialize person/group entity."""
self.hass = hass self.hass = hass
@ -229,11 +231,6 @@ class MicrosoftFaceGroupEntity(Entity):
"""Return the state of the entity.""" """Return the state of the entity."""
return len(self._api.store[self._id]) return len(self._api.store[self._id])
@property
def should_poll(self):
"""Return True if entity has to be polled for state."""
return False
@property @property
def extra_state_attributes(self): def extra_state_attributes(self):
"""Return device specific state attributes.""" """Return device specific state attributes."""

View file

@ -80,6 +80,8 @@ async def async_setup_platform(
class MoldIndicator(SensorEntity): class MoldIndicator(SensorEntity):
"""Represents a MoldIndication sensor.""" """Represents a MoldIndication sensor."""
_attr_should_poll = False
def __init__( def __init__(
self, self,
name, name,
@ -353,11 +355,6 @@ class MoldIndicator(SensorEntity):
_LOGGER.debug("Mold indicator humidity: %s", self._state) _LOGGER.debug("Mold indicator humidity: %s", self._state)
@property
def should_poll(self):
"""Return the polling state."""
return False
@property @property
def name(self): def name(self):
"""Return the name.""" """Return the name."""

View file

@ -950,6 +950,7 @@ class MqttEntity(
): ):
"""Representation of an MQTT entity.""" """Representation of an MQTT entity."""
_attr_should_poll = False
_entity_id_format: str _entity_id_format: str
def __init__(self, hass, config, config_entry, discovery_data): def __init__(self, hass, config, config_entry, discovery_data):
@ -1076,11 +1077,6 @@ class MqttEntity(
"""Return the name of the device if any.""" """Return the name of the device if any."""
return self._config.get(CONF_NAME) return self._config.get(CONF_NAME)
@property
def should_poll(self):
"""No polling needed."""
return False
@property @property
def unique_id(self): def unique_id(self):
"""Return a unique ID.""" """Return a unique ID."""

View file

@ -217,10 +217,7 @@ def get_mysensors_devices(
class MySensorsEntity(MySensorsDevice, Entity): class MySensorsEntity(MySensorsDevice, Entity):
"""Representation of a MySensors entity.""" """Representation of a MySensors entity."""
@property _attr_should_poll = False
def should_poll(self) -> bool:
"""Return the polling state. The gateway pushes its states."""
return False
@property @property
def available(self) -> bool: def available(self) -> bool:

View file

@ -72,6 +72,8 @@ class MyStromView(HomeAssistantView):
class MyStromBinarySensor(BinarySensorEntity): class MyStromBinarySensor(BinarySensorEntity):
"""Representation of a myStrom button.""" """Representation of a myStrom button."""
_attr_should_poll = False
def __init__(self, button_id): def __init__(self, button_id):
"""Initialize the myStrom Binary sensor.""" """Initialize the myStrom Binary sensor."""
self._button_id = button_id self._button_id = button_id
@ -82,11 +84,6 @@ class MyStromBinarySensor(BinarySensorEntity):
"""Return the name of the sensor.""" """Return the name of the sensor."""
return self._button_id return self._button_id
@property
def should_poll(self):
"""No polling needed."""
return False
@property @property
def is_on(self): def is_on(self):
"""Return true if the binary sensor is on.""" """Return true if the binary sensor is on."""

View file

@ -46,6 +46,8 @@ async def async_setup_platform(
class NessZoneBinarySensor(BinarySensorEntity): class NessZoneBinarySensor(BinarySensorEntity):
"""Representation of an Ness alarm zone as a binary sensor.""" """Representation of an Ness alarm zone as a binary sensor."""
_attr_should_poll = False
def __init__(self, zone_id, name, zone_type): def __init__(self, zone_id, name, zone_type):
"""Initialize the binary_sensor.""" """Initialize the binary_sensor."""
self._zone_id = zone_id self._zone_id = zone_id
@ -66,11 +68,6 @@ class NessZoneBinarySensor(BinarySensorEntity):
"""Return the name of the entity.""" """Return the name of the entity."""
return self._name return self._name
@property
def should_poll(self):
"""No polling needed."""
return False
@property @property
def is_on(self): def is_on(self):
"""Return true if sensor is on.""" """Return true if sensor is on."""

View file

@ -98,6 +98,7 @@ class ThermostatEntity(ClimateEntity):
_attr_min_temp = MIN_TEMP _attr_min_temp = MIN_TEMP
_attr_max_temp = MAX_TEMP _attr_max_temp = MAX_TEMP
_attr_has_entity_name = True _attr_has_entity_name = True
_attr_should_poll = False
def __init__(self, device: Device) -> None: def __init__(self, device: Device) -> None:
"""Initialize ThermostatEntity.""" """Initialize ThermostatEntity."""
@ -105,11 +106,6 @@ class ThermostatEntity(ClimateEntity):
self._device_info = NestDeviceInfo(device) self._device_info = NestDeviceInfo(device)
self._attr_supported_features = 0 self._attr_supported_features = 0
@property
def should_poll(self) -> bool:
"""Disable polling since entities have state pushed via pubsub."""
return False
@property @property
def unique_id(self) -> str | None: def unique_id(self) -> str | None:
"""Return a unique ID.""" """Return a unique ID."""

View file

@ -348,6 +348,8 @@ class NestLegacyDevice:
class NestSensorDevice(Entity): class NestSensorDevice(Entity):
"""Representation of a Nest sensor.""" """Representation of a Nest sensor."""
_attr_should_poll = False
def __init__(self, structure, device, variable): def __init__(self, structure, device, variable):
"""Initialize the sensor.""" """Initialize the sensor."""
self.structure = structure self.structure = structure
@ -370,11 +372,6 @@ class NestSensorDevice(Entity):
"""Return the name of the nest, if any.""" """Return the name of the nest, if any."""
return self._name return self._name
@property
def should_poll(self):
"""Do not need poll thanks using Nest streaming API."""
return False
@property @property
def unique_id(self): def unique_id(self):
"""Return unique id based on device serial and variable.""" """Return unique id based on device serial and variable."""

View file

@ -86,6 +86,8 @@ async def async_setup_legacy_entry(hass, entry, async_add_entities) -> None:
class NestThermostat(ClimateEntity): class NestThermostat(ClimateEntity):
"""Representation of a Nest thermostat.""" """Representation of a Nest thermostat."""
_attr_should_poll = False
def __init__(self, structure, device, temp_unit): def __init__(self, structure, device, temp_unit):
"""Initialize the thermostat.""" """Initialize the thermostat."""
self._unit = temp_unit self._unit = temp_unit
@ -136,11 +138,6 @@ class NestThermostat(ClimateEntity):
self._min_temperature = None self._min_temperature = None
self._max_temperature = None self._max_temperature = None
@property
def should_poll(self):
"""Do not need poll thanks using Nest streaming API."""
return False
async def async_added_to_hass(self): async def async_added_to_hass(self):
"""Register update signal handler.""" """Register update signal handler."""

View file

@ -46,6 +46,8 @@ async def async_setup_entry(
class NmapTrackerEntity(ScannerEntity): class NmapTrackerEntity(ScannerEntity):
"""An Nmap Tracker entity.""" """An Nmap Tracker entity."""
_attr_should_poll = False
def __init__( def __init__(
self, nmap_tracker: NmapDeviceScanner, mac_address: str, active: bool self, nmap_tracker: NmapDeviceScanner, mac_address: str, active: bool
) -> None: ) -> None:
@ -97,11 +99,6 @@ class NmapTrackerEntity(ScannerEntity):
"""Return tracker source type.""" """Return tracker source type."""
return SourceType.ROUTER return SourceType.ROUTER
@property
def should_poll(self) -> bool:
"""No polling needed."""
return False
@property @property
def icon(self) -> str: def icon(self) -> str:
"""Return device icon.""" """Return device icon."""

View file

@ -81,6 +81,8 @@ def setup_platform(
class NumatoGpioBinarySensor(BinarySensorEntity): class NumatoGpioBinarySensor(BinarySensorEntity):
"""Represents a binary sensor (input) port of a Numato GPIO expander.""" """Represents a binary sensor (input) port of a Numato GPIO expander."""
_attr_should_poll = False
def __init__(self, name, device_id, port, invert_logic, api): def __init__(self, name, device_id, port, invert_logic, api):
"""Initialize the Numato GPIO based binary sensor object.""" """Initialize the Numato GPIO based binary sensor object."""
self._name = name or DEVICE_DEFAULT_NAME self._name = name or DEVICE_DEFAULT_NAME
@ -106,11 +108,6 @@ class NumatoGpioBinarySensor(BinarySensorEntity):
self._state = level self._state = level
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 the name of the sensor.""" """Return the name of the sensor."""

View file

@ -67,6 +67,8 @@ def setup_platform(
class NumatoGpioSwitch(SwitchEntity): class NumatoGpioSwitch(SwitchEntity):
"""Representation of a Numato USB GPIO switch port.""" """Representation of a Numato USB GPIO switch port."""
_attr_should_poll = False
def __init__(self, name, device_id, port, invert_logic, api): def __init__(self, name, device_id, port, invert_logic, api):
"""Initialize the port.""" """Initialize the port."""
self._name = name or DEVICE_DEFAULT_NAME self._name = name or DEVICE_DEFAULT_NAME
@ -81,11 +83,6 @@ class NumatoGpioSwitch(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 is_on(self): def is_on(self):
"""Return true if port is turned on.""" """Return true if port is turned on."""

View file

@ -94,6 +94,8 @@ async def async_setup_entry(
class NWSWeather(WeatherEntity): class NWSWeather(WeatherEntity):
"""Representation of a weather condition.""" """Representation of a weather condition."""
_attr_should_poll = False
def __init__(self, entry_data, hass_data, mode, units): def __init__(self, entry_data, hass_data, mode, units):
"""Initialise the platform with a data instance and station name.""" """Initialise the platform with a data instance and station name."""
self.nws = hass_data[NWS_DATA] self.nws = hass_data[NWS_DATA]
@ -133,11 +135,6 @@ class NWSWeather(WeatherEntity):
self.async_write_ha_state() self.async_write_ha_state()
@property
def should_poll(self) -> bool:
"""Entities do not individually poll."""
return False
@property @property
def attribution(self): def attribution(self):
"""Return the attribution.""" """Return the attribution."""

View file

@ -87,6 +87,8 @@ def setup_platform(
class NX584ZoneSensor(BinarySensorEntity): class NX584ZoneSensor(BinarySensorEntity):
"""Representation of a NX584 zone as a sensor.""" """Representation of a NX584 zone as a sensor."""
_attr_should_poll = False
def __init__(self, zone, zone_type): def __init__(self, zone, zone_type):
"""Initialize the nx594 binary sensor.""" """Initialize the nx594 binary sensor."""
self._zone = zone self._zone = zone
@ -97,11 +99,6 @@ class NX584ZoneSensor(BinarySensorEntity):
"""Return the class of this sensor, from DEVICE_CLASSES.""" """Return the class of this sensor, from DEVICE_CLASSES."""
return self._zone_type return self._zone_type
@property
def should_poll(self):
"""No polling needed."""
return False
@property @property
def name(self): def name(self):
"""Return the name of the binary sensor.""" """Return the name of the binary sensor."""