Use _attr_should_poll in components [s-t] (#77368)
* Use _attr_should_poll in components [s-t] * Adjust touchline Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
c916fcb2c6
commit
2b9116f1f8
22 changed files with 42 additions and 120 deletions
|
@ -176,6 +176,8 @@ def async_track_time_interval_backoff(hass, action) -> CALLBACK_TYPE:
|
|||
class SAJsensor(SensorEntity):
|
||||
"""Representation of a SAJ sensor."""
|
||||
|
||||
_attr_should_poll = False
|
||||
|
||||
def __init__(self, serialnumber, pysaj_sensor, inverter_name=None):
|
||||
"""Initialize the SAJ sensor."""
|
||||
self._sensor = pysaj_sensor
|
||||
|
@ -216,11 +218,6 @@ class SAJsensor(SensorEntity):
|
|||
if self.native_unit_of_measurement in (TEMP_CELSIUS, TEMP_FAHRENHEIT):
|
||||
return SensorDeviceClass.TEMPERATURE
|
||||
|
||||
@property
|
||||
def should_poll(self) -> bool:
|
||||
"""SAJ sensors are updated & don't poll."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def per_day_basis(self) -> bool:
|
||||
"""Return if the sensors value is on daily basis or not."""
|
||||
|
|
|
@ -60,6 +60,8 @@ async def async_setup_platform(
|
|||
class SatelIntegraBinarySensor(BinarySensorEntity):
|
||||
"""Representation of an Satel Integra binary sensor."""
|
||||
|
||||
_attr_should_poll = False
|
||||
|
||||
def __init__(
|
||||
self, controller, device_number, device_name, zone_type, react_to_signal
|
||||
):
|
||||
|
@ -100,11 +102,6 @@ class SatelIntegraBinarySensor(BinarySensorEntity):
|
|||
if self._zone_type is BinarySensorDeviceClass.SMOKE:
|
||||
return "mdi:fire"
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""No polling needed."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
"""Return true if sensor is on."""
|
||||
|
|
|
@ -51,6 +51,8 @@ async def async_setup_platform(
|
|||
class SatelIntegraSwitch(SwitchEntity):
|
||||
"""Representation of an Satel switch."""
|
||||
|
||||
_attr_should_poll = False
|
||||
|
||||
def __init__(self, controller, device_number, device_name, code):
|
||||
"""Initialize the binary_sensor."""
|
||||
self._device_number = device_number
|
||||
|
@ -104,8 +106,3 @@ class SatelIntegraSwitch(SwitchEntity):
|
|||
def name(self):
|
||||
"""Return the name of the switch."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""Don't poll."""
|
||||
return False
|
||||
|
|
|
@ -59,6 +59,8 @@ def setup_platform(
|
|||
class SCSGateCover(CoverEntity):
|
||||
"""Representation of SCSGate cover."""
|
||||
|
||||
_attr_should_poll = False
|
||||
|
||||
def __init__(self, scs_id, name, logger, scsgate):
|
||||
"""Initialize the cover."""
|
||||
self._scs_id = scs_id
|
||||
|
@ -71,11 +73,6 @@ class SCSGateCover(CoverEntity):
|
|||
"""Return the SCSGate ID."""
|
||||
return self._scs_id
|
||||
|
||||
@property
|
||||
def should_poll(self) -> bool:
|
||||
"""No polling needed."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
"""Return the name of the cover."""
|
||||
|
|
|
@ -91,6 +91,8 @@ def _setup_scenario_switches(logger, config, scsgate, hass):
|
|||
class SCSGateSwitch(SwitchEntity):
|
||||
"""Representation of a SCSGate switch."""
|
||||
|
||||
_attr_should_poll = False
|
||||
|
||||
def __init__(self, scs_id, name, logger, scsgate):
|
||||
"""Initialize the switch."""
|
||||
self._name = name
|
||||
|
@ -104,11 +106,6 @@ class SCSGateSwitch(SwitchEntity):
|
|||
"""Return the SCS ID."""
|
||||
return self._scs_id
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""No polling needed."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the device if any."""
|
||||
|
|
|
@ -73,6 +73,8 @@ def sense_to_mdi(sense_icon):
|
|||
class SenseDevice(BinarySensorEntity):
|
||||
"""Implementation of a Sense energy device binary sensor."""
|
||||
|
||||
_attr_should_poll = False
|
||||
|
||||
def __init__(self, sense_devices_data, device, sense_monitor_id):
|
||||
"""Initialize the Sense binary sensor."""
|
||||
self._name = device["name"]
|
||||
|
@ -124,11 +126,6 @@ class SenseDevice(BinarySensorEntity):
|
|||
"""Return the device class of the binary sensor."""
|
||||
return BinarySensorDeviceClass.POWER
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""Return the deviceshould not poll for updates."""
|
||||
return False
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
"""Register callbacks."""
|
||||
self.async_on_remove(
|
||||
|
|
|
@ -113,6 +113,8 @@ async def async_setup_platform(
|
|||
class SerialSensor(SensorEntity):
|
||||
"""Representation of a Serial sensor."""
|
||||
|
||||
_attr_should_poll = False
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
name,
|
||||
|
@ -242,11 +244,6 @@ class SerialSensor(SensorEntity):
|
|||
"""Return the name of the sensor."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""No polling needed."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def extra_state_attributes(self):
|
||||
"""Return the attributes of the entity (if any JSON present)."""
|
||||
|
|
|
@ -86,6 +86,7 @@ def setup_platform(
|
|||
class SighthoundEntity(ImageProcessingEntity):
|
||||
"""Create a sighthound entity."""
|
||||
|
||||
_attr_should_poll = False
|
||||
_attr_unit_of_measurement = ATTR_PEOPLE
|
||||
|
||||
def __init__(
|
||||
|
@ -167,11 +168,6 @@ class SighthoundEntity(ImageProcessingEntity):
|
|||
"""Return the name of the sensor."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""Return the polling state."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
"""Return the state of the entity."""
|
||||
|
|
|
@ -405,6 +405,8 @@ class DeviceBroker:
|
|||
class SmartThingsEntity(Entity):
|
||||
"""Defines a SmartThings entity."""
|
||||
|
||||
_attr_should_poll = False
|
||||
|
||||
def __init__(self, device: DeviceEntity) -> None:
|
||||
"""Initialize the instance."""
|
||||
self._device = device
|
||||
|
@ -443,11 +445,6 @@ class SmartThingsEntity(Entity):
|
|||
"""Return the name of the device."""
|
||||
return self._device.label
|
||||
|
||||
@property
|
||||
def should_poll(self) -> bool:
|
||||
"""No polling needed for this device."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def unique_id(self) -> str:
|
||||
"""Return a unique ID."""
|
||||
|
|
|
@ -116,6 +116,7 @@ async def handle_set_latency(entity, service_call):
|
|||
class SnapcastGroupDevice(MediaPlayerEntity):
|
||||
"""Representation of a Snapcast group device."""
|
||||
|
||||
_attr_should_poll = False
|
||||
_attr_supported_features = (
|
||||
MediaPlayerEntityFeature.VOLUME_MUTE
|
||||
| MediaPlayerEntityFeature.VOLUME_SET
|
||||
|
@ -173,11 +174,6 @@ class SnapcastGroupDevice(MediaPlayerEntity):
|
|||
name = f"{self._group.friendly_name} {GROUP_SUFFIX}"
|
||||
return {"friendly_name": name}
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""Do not poll for state."""
|
||||
return False
|
||||
|
||||
async def async_select_source(self, source):
|
||||
"""Set input source."""
|
||||
streams = self._group.streams_by_name()
|
||||
|
@ -208,6 +204,7 @@ class SnapcastGroupDevice(MediaPlayerEntity):
|
|||
class SnapcastClientDevice(MediaPlayerEntity):
|
||||
"""Representation of a Snapcast client device."""
|
||||
|
||||
_attr_should_poll = False
|
||||
_attr_supported_features = (
|
||||
MediaPlayerEntityFeature.VOLUME_MUTE
|
||||
| MediaPlayerEntityFeature.VOLUME_SET
|
||||
|
@ -276,11 +273,6 @@ class SnapcastClientDevice(MediaPlayerEntity):
|
|||
state_attrs["friendly_name"] = name
|
||||
return state_attrs
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""Do not poll for state."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def latency(self):
|
||||
"""Latency for Client."""
|
||||
|
|
|
@ -89,6 +89,7 @@ async def async_setup_entry(
|
|||
class SongpalEntity(MediaPlayerEntity):
|
||||
"""Class representing a Songpal device."""
|
||||
|
||||
_attr_should_poll = False
|
||||
_attr_supported_features = (
|
||||
MediaPlayerEntityFeature.VOLUME_SET
|
||||
| MediaPlayerEntityFeature.VOLUME_STEP
|
||||
|
@ -118,11 +119,6 @@ class SongpalEntity(MediaPlayerEntity):
|
|||
self._active_source = None
|
||||
self._sources = {}
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""Return True if the device should be polled."""
|
||||
return False
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
"""Run when entity is added to hass."""
|
||||
await self.async_activate_websocket()
|
||||
|
|
|
@ -83,6 +83,8 @@ async def async_setup_entry(
|
|||
class SrpEntity(SensorEntity):
|
||||
"""Implementation of a Srp Energy Usage sensor."""
|
||||
|
||||
_attr_should_poll = False
|
||||
|
||||
def __init__(self, coordinator):
|
||||
"""Initialize the SrpEntity class."""
|
||||
self._name = SENSOR_NAME
|
||||
|
@ -125,11 +127,6 @@ class SrpEntity(SensorEntity):
|
|||
return f"{self.coordinator.data:.2f}"
|
||||
return None
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""No need to poll. Coordinator notifies entity of updates."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def extra_state_attributes(self):
|
||||
"""Return the state attributes."""
|
||||
|
|
|
@ -11,6 +11,8 @@ from .account import StarlineAccount, StarlineDevice
|
|||
class StarlineEntity(Entity):
|
||||
"""StarLine base entity class."""
|
||||
|
||||
_attr_should_poll = False
|
||||
|
||||
def __init__(
|
||||
self, account: StarlineAccount, device: StarlineDevice, key: str, name: str
|
||||
) -> None:
|
||||
|
@ -21,11 +23,6 @@ class StarlineEntity(Entity):
|
|||
self._name = name
|
||||
self._unsubscribe_api: Callable | None = None
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""No polling needed."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def available(self):
|
||||
"""Return True if entity is available."""
|
||||
|
|
|
@ -57,6 +57,8 @@ async def async_setup_entry(
|
|||
class FolderSensor(SensorEntity):
|
||||
"""A Syncthing folder sensor."""
|
||||
|
||||
_attr_should_poll = False
|
||||
|
||||
STATE_ATTRIBUTES = {
|
||||
"errors": "errors",
|
||||
"globalBytes": "global_bytes",
|
||||
|
@ -131,11 +133,6 @@ class FolderSensor(SensorEntity):
|
|||
"""Return the state attributes."""
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""Return the polling requirement for this sensor."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return device information."""
|
||||
|
|
|
@ -7,6 +7,8 @@ from .const import DEFAULT_NAME, DOMAIN, TADO_HOME, TADO_ZONE
|
|||
class TadoDeviceEntity(Entity):
|
||||
"""Base implementation for Tado device."""
|
||||
|
||||
_attr_should_poll = False
|
||||
|
||||
def __init__(self, device_info):
|
||||
"""Initialize a Tado device."""
|
||||
super().__init__()
|
||||
|
@ -27,11 +29,6 @@ class TadoDeviceEntity(Entity):
|
|||
via_device=(DOMAIN, self._device_info["serialNo"]),
|
||||
)
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""Do not poll."""
|
||||
return False
|
||||
|
||||
|
||||
class TadoHomeEntity(Entity):
|
||||
"""Base implementation for Tado home."""
|
||||
|
@ -57,6 +54,8 @@ class TadoHomeEntity(Entity):
|
|||
class TadoZoneEntity(Entity):
|
||||
"""Base implementation for Tado zone."""
|
||||
|
||||
_attr_should_poll = False
|
||||
|
||||
def __init__(self, zone_name, home_id, zone_id):
|
||||
"""Initialize a Tado zone."""
|
||||
super().__init__()
|
||||
|
@ -75,8 +74,3 @@ class TadoZoneEntity(Entity):
|
|||
model=TADO_ZONE,
|
||||
suggested_area=self.zone_name,
|
||||
)
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""Do not poll."""
|
||||
return False
|
||||
|
|
|
@ -25,6 +25,8 @@ ATTR_LAST_UPDATED = "time_last_updated"
|
|||
class TelldusLiveEntity(Entity):
|
||||
"""Base class for all Telldus Live entities."""
|
||||
|
||||
_attr_should_poll = False
|
||||
|
||||
def __init__(self, client, device_id):
|
||||
"""Initialize the entity."""
|
||||
self._id = device_id
|
||||
|
@ -66,11 +68,6 @@ class TelldusLiveEntity(Entity):
|
|||
"""Return the state of the device."""
|
||||
return self.device.state
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""Return the polling state."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def assumed_state(self):
|
||||
"""Return true if unable to access real state of entity."""
|
||||
|
|
|
@ -112,6 +112,8 @@ async def async_setup_platform(
|
|||
class ThresholdSensor(BinarySensorEntity):
|
||||
"""Representation of a Threshold sensor."""
|
||||
|
||||
_attr_should_poll = False
|
||||
|
||||
def __init__(
|
||||
self, hass, entity_id, name, lower, upper, hysteresis, device_class, unique_id
|
||||
):
|
||||
|
@ -168,11 +170,6 @@ class ThresholdSensor(BinarySensorEntity):
|
|||
"""Return true if sensor is on."""
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""No polling needed."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def device_class(self):
|
||||
"""Return the sensor class of the sensor."""
|
||||
|
|
|
@ -98,6 +98,8 @@ def _is_sun_event(sun_event):
|
|||
class TodSensor(BinarySensorEntity):
|
||||
"""Time of the Day Sensor."""
|
||||
|
||||
_attr_should_poll = False
|
||||
|
||||
def __init__(self, name, after, after_offset, before, before_offset, unique_id):
|
||||
"""Init the ToD Sensor..."""
|
||||
self._attr_unique_id = unique_id
|
||||
|
@ -109,11 +111,6 @@ class TodSensor(BinarySensorEntity):
|
|||
self._after = after
|
||||
self._unsub_update: Callable[[], None] = None
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""Sensor does not need to be polled."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the sensor."""
|
||||
|
|
|
@ -84,11 +84,6 @@ class Touchline(ClimateEntity):
|
|||
(self.unit.get_operation_mode(), self.unit.get_week_program())
|
||||
)
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""Return the polling state."""
|
||||
return True
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the climate device."""
|
||||
|
|
|
@ -49,6 +49,8 @@ async def async_setup_entry(
|
|||
class TransmissionSensor(SensorEntity):
|
||||
"""A base class for all Transmission sensors."""
|
||||
|
||||
_attr_should_poll = False
|
||||
|
||||
def __init__(self, tm_client, client_name, sensor_name, sub_type=None):
|
||||
"""Initialize the sensor."""
|
||||
self._tm_client: TransmissionClient = tm_client
|
||||
|
@ -72,11 +74,6 @@ class TransmissionSensor(SensorEntity):
|
|||
"""Return the state of the sensor."""
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""Return the polling requirement for this sensor."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def available(self):
|
||||
"""Could the device be accessed during the last update call."""
|
||||
|
|
|
@ -33,6 +33,8 @@ async def async_setup_entry(
|
|||
class TransmissionSwitch(SwitchEntity):
|
||||
"""Representation of a Transmission switch."""
|
||||
|
||||
_attr_should_poll = False
|
||||
|
||||
def __init__(self, switch_type, switch_name, tm_client, name):
|
||||
"""Initialize the Transmission switch."""
|
||||
self._name = switch_name
|
||||
|
@ -53,11 +55,6 @@ class TransmissionSwitch(SwitchEntity):
|
|||
"""Return the unique id of the entity."""
|
||||
return f"{self._tm_client.api.host}-{self.name}"
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""Poll for status regularly."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
"""Return true if device is on."""
|
||||
|
|
|
@ -112,6 +112,8 @@ def setup_platform(
|
|||
class SensorTrend(BinarySensorEntity):
|
||||
"""Representation of a trend Sensor."""
|
||||
|
||||
_attr_should_poll = False
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
hass,
|
||||
|
@ -167,11 +169,6 @@ class SensorTrend(BinarySensorEntity):
|
|||
ATTR_SAMPLE_DURATION: self._sample_duration,
|
||||
}
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""No polling needed."""
|
||||
return False
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
"""Complete device setup after being added to hass."""
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue