Use _attr_should_poll in components [u-z] (#77371)

This commit is contained in:
epenet 2022-08-26 21:22:27 +02:00 committed by GitHub
parent dff9baf880
commit d8b2563b3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 25 additions and 65 deletions

View File

@ -19,6 +19,8 @@ _LOGGER = logging.getLogger(__name__)
class UniFiBase(Entity):
"""UniFi entity base class."""
_attr_should_poll = False
DOMAIN = ""
TYPE = ""
@ -93,8 +95,3 @@ class UniFiBase(Entity):
er.async_get(self.hass).async_remove(self.entity_id)
else:
await self.async_remove(force_remove=True)
@property
def should_poll(self) -> bool:
"""No polling needed."""
return False

View File

@ -152,6 +152,8 @@ async def async_setup_platform(
class UniversalMediaPlayer(MediaPlayerEntity):
"""Representation of an universal media player."""
_attr_should_poll = False
def __init__(
self,
hass,
@ -274,11 +276,6 @@ class UniversalMediaPlayer(MediaPlayerEntity):
DOMAIN, service_name, service_data, blocking=True, context=self._context
)
@property
def should_poll(self):
"""No polling needed."""
return False
@property
def device_class(self) -> str | None:
"""Return the class of this device."""

View File

@ -68,6 +68,8 @@ async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->
class UpbEntity(Entity):
"""Base class for all UPB entities."""
_attr_should_poll = False
def __init__(self, element, unique_id, upb):
"""Initialize the base of all UPB devices."""
self._upb = upb
@ -80,11 +82,6 @@ class UpbEntity(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):
"""Return the default attributes of the element."""

View File

@ -304,6 +304,8 @@ class UtilitySensorExtraStoredData(SensorExtraStoredData):
class UtilityMeterSensor(RestoreSensor):
"""Representation of an utility meter sensor."""
_attr_should_poll = False
def __init__(
self,
*,
@ -581,11 +583,6 @@ class UtilityMeterSensor(RestoreSensor):
"""Return the unit the value is expressed in."""
return self._unit_of_measurement
@property
def should_poll(self):
"""No polling needed."""
return False
@property
def extra_state_attributes(self):
"""Return the state attributes of the sensor."""

View File

@ -88,6 +88,8 @@ class VeluxModule:
class VeluxEntity(Entity):
"""Abstraction for al Velux entities."""
_attr_should_poll = False
def __init__(self, node):
"""Initialize the Velux device."""
self.node = node
@ -117,8 +119,3 @@ class VeluxEntity(Entity):
if not self.node.name:
return "#" + str(self.node.node_id)
return self.node.name
@property
def should_poll(self):
"""No polling needed within Velux."""
return False

View File

@ -76,6 +76,8 @@ async def async_setup_platform(
class W800rf32BinarySensor(BinarySensorEntity):
"""A representation of a w800rf32 binary sensor."""
_attr_should_poll = False
def __init__(self, device_id, name, device_class=None, off_delay=None):
"""Initialize the w800rf32 sensor."""
self._signal = W800RF32_DEVICE.format(device_id)
@ -96,11 +98,6 @@ class W800rf32BinarySensor(BinarySensorEntity):
"""Return the device name."""
return self._name
@property
def should_poll(self):
"""No polling needed."""
return False
@property
def device_class(self):
"""Return the sensor class."""

View File

@ -96,6 +96,8 @@ def setup_platform(
class WaterFurnaceSensor(SensorEntity):
"""Implementing the Waterfurnace sensor."""
_attr_should_poll = False
def __init__(self, client, config):
"""Initialize the sensor."""
self.client = client
@ -131,11 +133,6 @@ class WaterFurnaceSensor(SensorEntity):
"""Return the units of measurement."""
return self._unit_of_measurement
@property
def should_poll(self):
"""Return the polling state."""
return False
async def async_added_to_hass(self):
"""Register callbacks."""
self.async_on_remove(

View File

@ -138,6 +138,8 @@ class WiffiIntegrationApi:
class WiffiEntity(Entity):
"""Common functionality for all wiffi entities."""
_attr_should_poll = False
def __init__(self, device, metric, options):
"""Initialize the base elements of a wiffi entity."""
self._id = generate_unique_id(device, metric)
@ -170,11 +172,6 @@ class WiffiEntity(Entity):
)
)
@property
def should_poll(self):
"""Disable polling because data driven ."""
return False
@property
def device_info(self):
"""Return wiffi device info which is shared between all entities of a device."""

View File

@ -912,6 +912,8 @@ async def async_get_entity_id(
class BaseWithingsSensor(Entity):
"""Base class for withings sensors."""
_attr_should_poll = False
def __init__(self, data_manager: DataManager, attribute: WithingsAttribute) -> None:
"""Initialize the Withings sensor."""
self._data_manager = data_manager
@ -922,11 +924,6 @@ class BaseWithingsSensor(Entity):
self._unique_id = get_attribute_unique_id(self._attribute, self._user_id)
self._state_data: Any | None = None
@property
def should_poll(self) -> bool:
"""Return False to indicate HA should not poll for changes."""
return False
@property
def name(self) -> str:
"""Return the name of the sensor."""

View File

@ -83,6 +83,8 @@ def get_user_gamercard(api, xuid):
class XboxSensor(SensorEntity):
"""A class for the Xbox account."""
_attr_should_poll = False
def __init__(self, api, xuid, gamercard, interval):
"""Initialize the sensor."""
self._state = None
@ -100,11 +102,6 @@ class XboxSensor(SensorEntity):
"""Return the name of the sensor."""
return self._gamertag
@property
def should_poll(self):
"""Return False as this entity has custom polling."""
return False
@property
def native_value(self):
"""Return the state of the sensor."""

View File

@ -181,6 +181,8 @@ async def async_setup_platform(
class XiaomiMiioRemote(RemoteEntity):
"""Representation of a Xiaomi Miio Remote device."""
_attr_should_poll = False
def __init__(self, friendly_name, device, unique_id, slot, timeout, commands):
"""Initialize the remote."""
self._name = friendly_name
@ -225,11 +227,6 @@ class XiaomiMiioRemote(RemoteEntity):
except DeviceException:
return False
@property
def should_poll(self):
"""We should not be polled for device up state."""
return False
async def async_turn_on(self, **kwargs):
"""Turn the device on."""
_LOGGER.error(

View File

@ -79,6 +79,8 @@ async def async_setup_entry(
class MusicCastMediaPlayer(MusicCastDeviceEntity, MediaPlayerEntity):
"""The musiccast media player."""
_attr_should_poll = False
def __init__(self, zone_id, name, entry_id, coordinator):
"""Initialize the musiccast device."""
self._player_state = STATE_PLAYING
@ -119,11 +121,6 @@ class MusicCastMediaPlayer(MusicCastDeviceEntity, MediaPlayerEntity):
self.update_all_mc_entities
)
@property
def should_poll(self):
"""Push an update after each command."""
return False
@property
def ip_address(self):
"""Return the ip address of the musiccast device."""

View File

@ -124,6 +124,7 @@ class ZhongHongClimate(ClimateEntity):
HVACMode.FAN_ONLY,
HVACMode.OFF,
]
_attr_should_poll = False
_attr_supported_features = (
ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.FAN_MODE
)
@ -160,11 +161,6 @@ class ZhongHongClimate(ClimateEntity):
self._target_temperature = self._device.target_temperature
self.schedule_update_ha_state()
@property
def should_poll(self):
"""Return the polling state."""
return False
@property
def name(self):
"""Return the name of the thermostat, if any."""