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

pull/77389/head
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):
"""Implementation of a Kaittera air quality sensor."""
_attr_should_poll = False
def __init__(self, api, name, device_id):
"""Initialize the sensor."""
self._api = api
@ -50,11 +52,6 @@ class KaiterraAirQuality(AirQualityEntity):
def _device(self):
return self._api.data.get(self._device_id, {})
@property
def should_poll(self):
"""Return that the sensor should not be polled."""
return False
@property
def available(self):
"""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):
"""Representation of network device."""
_attr_should_poll = False
def __init__(self, device: Device, router: KeeneticRouter) -> None:
"""Initialize the tracked device."""
self._device = device
@ -94,11 +96,6 @@ class KeeneticTracker(ScannerEntity):
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
def is_connected(self):
"""Return true if the device is connected to the network."""

View File

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

View File

@ -37,6 +37,8 @@ async def async_setup_entry(
class KonnectedBinarySensor(BinarySensorEntity):
"""Representation of a Konnected binary sensor."""
_attr_should_poll = False
def __init__(self, device_id, zone_num, data):
"""Initialize the Konnected binary sensor."""
self._data = data
@ -62,11 +64,6 @@ class KonnectedBinarySensor(BinarySensorEntity):
"""Return the state of the sensor."""
return self._state
@property
def should_poll(self):
"""No polling needed."""
return False
@property
def device_class(self):
"""Return the device class."""

View File

@ -237,6 +237,8 @@ def _async_fire_send_keys_event(
class LcnEntity(Entity):
"""Parent class for all entities associated with the LCN component."""
_attr_should_poll = False
def __init__(
self, config: ConfigType, entry_id: str, device_connection: DeviceConnectionType
) -> 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:
"""Run when entity about to be added to hass."""
if not self.device_connection.is_group:

View File

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

View File

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

View File

@ -59,6 +59,7 @@ class LW12WiFi(LightEntity):
"""LW-12 WiFi LED Controller."""
_attr_color_mode = ColorMode.HS
_attr_should_poll = False
_attr_supported_color_modes = {ColorMode.HS}
_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
@property
def should_poll(self) -> bool:
"""Return False to not poll the state of this entity."""
return False
def turn_on(self, **kwargs):
"""Instruct the light to turn on."""
self._light.light_on()

View File

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

View File

@ -207,6 +207,8 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
class MicrosoftFaceGroupEntity(Entity):
"""Person-Group state/data Entity."""
_attr_should_poll = False
def __init__(self, hass, api, g_id, name):
"""Initialize person/group entity."""
self.hass = hass
@ -229,11 +231,6 @@ class MicrosoftFaceGroupEntity(Entity):
"""Return the state of the entity."""
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
def extra_state_attributes(self):
"""Return device specific state attributes."""

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -348,6 +348,8 @@ class NestLegacyDevice:
class NestSensorDevice(Entity):
"""Representation of a Nest sensor."""
_attr_should_poll = False
def __init__(self, structure, device, variable):
"""Initialize the sensor."""
self.structure = structure
@ -370,11 +372,6 @@ class NestSensorDevice(Entity):
"""Return the name of the nest, if any."""
return self._name
@property
def should_poll(self):
"""Do not need poll thanks using Nest streaming API."""
return False
@property
def unique_id(self):
"""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):
"""Representation of a Nest thermostat."""
_attr_should_poll = False
def __init__(self, structure, device, temp_unit):
"""Initialize the thermostat."""
self._unit = temp_unit
@ -136,11 +138,6 @@ class NestThermostat(ClimateEntity):
self._min_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):
"""Register update signal handler."""

View File

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

View File

@ -81,6 +81,8 @@ def setup_platform(
class NumatoGpioBinarySensor(BinarySensorEntity):
"""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):
"""Initialize the Numato GPIO based binary sensor object."""
self._name = name or DEVICE_DEFAULT_NAME
@ -106,11 +108,6 @@ class NumatoGpioBinarySensor(BinarySensorEntity):
self._state = level
self.async_write_ha_state()
@property
def should_poll(self):
"""No polling needed."""
return False
@property
def name(self):
"""Return the name of the sensor."""

View File

@ -67,6 +67,8 @@ def setup_platform(
class NumatoGpioSwitch(SwitchEntity):
"""Representation of a Numato USB GPIO switch port."""
_attr_should_poll = False
def __init__(self, name, device_id, port, invert_logic, api):
"""Initialize the port."""
self._name = name or DEVICE_DEFAULT_NAME
@ -81,11 +83,6 @@ class NumatoGpioSwitch(SwitchEntity):
"""Return the name of the switch."""
return self._name
@property
def should_poll(self):
"""No polling needed."""
return False
@property
def is_on(self):
"""Return true if port is turned on."""

View File

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

View File

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