mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 14:17:45 +00:00
Use _attr_should_poll in components [u-z] (#77371)
This commit is contained in:
parent
dff9baf880
commit
d8b2563b3d
@ -19,6 +19,8 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
class UniFiBase(Entity):
|
class UniFiBase(Entity):
|
||||||
"""UniFi entity base class."""
|
"""UniFi entity base class."""
|
||||||
|
|
||||||
|
_attr_should_poll = False
|
||||||
|
|
||||||
DOMAIN = ""
|
DOMAIN = ""
|
||||||
TYPE = ""
|
TYPE = ""
|
||||||
|
|
||||||
@ -93,8 +95,3 @@ class UniFiBase(Entity):
|
|||||||
er.async_get(self.hass).async_remove(self.entity_id)
|
er.async_get(self.hass).async_remove(self.entity_id)
|
||||||
else:
|
else:
|
||||||
await self.async_remove(force_remove=True)
|
await self.async_remove(force_remove=True)
|
||||||
|
|
||||||
@property
|
|
||||||
def should_poll(self) -> bool:
|
|
||||||
"""No polling needed."""
|
|
||||||
return False
|
|
||||||
|
@ -152,6 +152,8 @@ async def async_setup_platform(
|
|||||||
class UniversalMediaPlayer(MediaPlayerEntity):
|
class UniversalMediaPlayer(MediaPlayerEntity):
|
||||||
"""Representation of an universal media player."""
|
"""Representation of an universal media player."""
|
||||||
|
|
||||||
|
_attr_should_poll = False
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
hass,
|
hass,
|
||||||
@ -274,11 +276,6 @@ class UniversalMediaPlayer(MediaPlayerEntity):
|
|||||||
DOMAIN, service_name, service_data, blocking=True, context=self._context
|
DOMAIN, service_name, service_data, blocking=True, context=self._context
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
|
||||||
def should_poll(self):
|
|
||||||
"""No polling needed."""
|
|
||||||
return False
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_class(self) -> str | None:
|
def device_class(self) -> str | None:
|
||||||
"""Return the class of this device."""
|
"""Return the class of this device."""
|
||||||
|
@ -68,6 +68,8 @@ async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->
|
|||||||
class UpbEntity(Entity):
|
class UpbEntity(Entity):
|
||||||
"""Base class for all UPB entities."""
|
"""Base class for all UPB entities."""
|
||||||
|
|
||||||
|
_attr_should_poll = False
|
||||||
|
|
||||||
def __init__(self, element, unique_id, upb):
|
def __init__(self, element, unique_id, upb):
|
||||||
"""Initialize the base of all UPB devices."""
|
"""Initialize the base of all UPB devices."""
|
||||||
self._upb = upb
|
self._upb = upb
|
||||||
@ -80,11 +82,6 @@ class UpbEntity(Entity):
|
|||||||
"""Return unique id of the element."""
|
"""Return unique id of the element."""
|
||||||
return self._unique_id
|
return self._unique_id
|
||||||
|
|
||||||
@property
|
|
||||||
def should_poll(self) -> bool:
|
|
||||||
"""Don't poll this device."""
|
|
||||||
return False
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self):
|
def extra_state_attributes(self):
|
||||||
"""Return the default attributes of the element."""
|
"""Return the default attributes of the element."""
|
||||||
|
@ -304,6 +304,8 @@ class UtilitySensorExtraStoredData(SensorExtraStoredData):
|
|||||||
class UtilityMeterSensor(RestoreSensor):
|
class UtilityMeterSensor(RestoreSensor):
|
||||||
"""Representation of an utility meter sensor."""
|
"""Representation of an utility meter sensor."""
|
||||||
|
|
||||||
|
_attr_should_poll = False
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
*,
|
*,
|
||||||
@ -581,11 +583,6 @@ class UtilityMeterSensor(RestoreSensor):
|
|||||||
"""Return the unit the value is expressed in."""
|
"""Return the unit the value is expressed in."""
|
||||||
return self._unit_of_measurement
|
return self._unit_of_measurement
|
||||||
|
|
||||||
@property
|
|
||||||
def should_poll(self):
|
|
||||||
"""No polling needed."""
|
|
||||||
return False
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self):
|
def extra_state_attributes(self):
|
||||||
"""Return the state attributes of the sensor."""
|
"""Return the state attributes of the sensor."""
|
||||||
|
@ -88,6 +88,8 @@ class VeluxModule:
|
|||||||
class VeluxEntity(Entity):
|
class VeluxEntity(Entity):
|
||||||
"""Abstraction for al Velux entities."""
|
"""Abstraction for al Velux entities."""
|
||||||
|
|
||||||
|
_attr_should_poll = False
|
||||||
|
|
||||||
def __init__(self, node):
|
def __init__(self, node):
|
||||||
"""Initialize the Velux device."""
|
"""Initialize the Velux device."""
|
||||||
self.node = node
|
self.node = node
|
||||||
@ -117,8 +119,3 @@ class VeluxEntity(Entity):
|
|||||||
if not self.node.name:
|
if not self.node.name:
|
||||||
return "#" + str(self.node.node_id)
|
return "#" + str(self.node.node_id)
|
||||||
return self.node.name
|
return self.node.name
|
||||||
|
|
||||||
@property
|
|
||||||
def should_poll(self):
|
|
||||||
"""No polling needed within Velux."""
|
|
||||||
return False
|
|
||||||
|
@ -76,6 +76,8 @@ async def async_setup_platform(
|
|||||||
class W800rf32BinarySensor(BinarySensorEntity):
|
class W800rf32BinarySensor(BinarySensorEntity):
|
||||||
"""A representation of a w800rf32 binary sensor."""
|
"""A representation of a w800rf32 binary sensor."""
|
||||||
|
|
||||||
|
_attr_should_poll = False
|
||||||
|
|
||||||
def __init__(self, device_id, name, device_class=None, off_delay=None):
|
def __init__(self, device_id, name, device_class=None, off_delay=None):
|
||||||
"""Initialize the w800rf32 sensor."""
|
"""Initialize the w800rf32 sensor."""
|
||||||
self._signal = W800RF32_DEVICE.format(device_id)
|
self._signal = W800RF32_DEVICE.format(device_id)
|
||||||
@ -96,11 +98,6 @@ class W800rf32BinarySensor(BinarySensorEntity):
|
|||||||
"""Return the device name."""
|
"""Return the device name."""
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
@property
|
|
||||||
def should_poll(self):
|
|
||||||
"""No polling needed."""
|
|
||||||
return False
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_class(self):
|
def device_class(self):
|
||||||
"""Return the sensor class."""
|
"""Return the sensor class."""
|
||||||
|
@ -96,6 +96,8 @@ def setup_platform(
|
|||||||
class WaterFurnaceSensor(SensorEntity):
|
class WaterFurnaceSensor(SensorEntity):
|
||||||
"""Implementing the Waterfurnace sensor."""
|
"""Implementing the Waterfurnace sensor."""
|
||||||
|
|
||||||
|
_attr_should_poll = False
|
||||||
|
|
||||||
def __init__(self, client, config):
|
def __init__(self, client, config):
|
||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
self.client = client
|
self.client = client
|
||||||
@ -131,11 +133,6 @@ class WaterFurnaceSensor(SensorEntity):
|
|||||||
"""Return the units of measurement."""
|
"""Return the units of measurement."""
|
||||||
return self._unit_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):
|
async def async_added_to_hass(self):
|
||||||
"""Register callbacks."""
|
"""Register callbacks."""
|
||||||
self.async_on_remove(
|
self.async_on_remove(
|
||||||
|
@ -138,6 +138,8 @@ class WiffiIntegrationApi:
|
|||||||
class WiffiEntity(Entity):
|
class WiffiEntity(Entity):
|
||||||
"""Common functionality for all wiffi entities."""
|
"""Common functionality for all wiffi entities."""
|
||||||
|
|
||||||
|
_attr_should_poll = False
|
||||||
|
|
||||||
def __init__(self, device, metric, options):
|
def __init__(self, device, metric, options):
|
||||||
"""Initialize the base elements of a wiffi entity."""
|
"""Initialize the base elements of a wiffi entity."""
|
||||||
self._id = generate_unique_id(device, metric)
|
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
|
@property
|
||||||
def device_info(self):
|
def device_info(self):
|
||||||
"""Return wiffi device info which is shared between all entities of a device."""
|
"""Return wiffi device info which is shared between all entities of a device."""
|
||||||
|
@ -912,6 +912,8 @@ async def async_get_entity_id(
|
|||||||
class BaseWithingsSensor(Entity):
|
class BaseWithingsSensor(Entity):
|
||||||
"""Base class for withings sensors."""
|
"""Base class for withings sensors."""
|
||||||
|
|
||||||
|
_attr_should_poll = False
|
||||||
|
|
||||||
def __init__(self, data_manager: DataManager, attribute: WithingsAttribute) -> None:
|
def __init__(self, data_manager: DataManager, attribute: WithingsAttribute) -> None:
|
||||||
"""Initialize the Withings sensor."""
|
"""Initialize the Withings sensor."""
|
||||||
self._data_manager = data_manager
|
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._unique_id = get_attribute_unique_id(self._attribute, self._user_id)
|
||||||
self._state_data: Any | None = None
|
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
|
@property
|
||||||
def name(self) -> str:
|
def name(self) -> str:
|
||||||
"""Return the name of the sensor."""
|
"""Return the name of the sensor."""
|
||||||
|
@ -83,6 +83,8 @@ def get_user_gamercard(api, xuid):
|
|||||||
class XboxSensor(SensorEntity):
|
class XboxSensor(SensorEntity):
|
||||||
"""A class for the Xbox account."""
|
"""A class for the Xbox account."""
|
||||||
|
|
||||||
|
_attr_should_poll = False
|
||||||
|
|
||||||
def __init__(self, api, xuid, gamercard, interval):
|
def __init__(self, api, xuid, gamercard, interval):
|
||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
self._state = None
|
self._state = None
|
||||||
@ -100,11 +102,6 @@ class XboxSensor(SensorEntity):
|
|||||||
"""Return the name of the sensor."""
|
"""Return the name of the sensor."""
|
||||||
return self._gamertag
|
return self._gamertag
|
||||||
|
|
||||||
@property
|
|
||||||
def should_poll(self):
|
|
||||||
"""Return False as this entity has custom polling."""
|
|
||||||
return False
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self):
|
def native_value(self):
|
||||||
"""Return the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
|
@ -181,6 +181,8 @@ async def async_setup_platform(
|
|||||||
class XiaomiMiioRemote(RemoteEntity):
|
class XiaomiMiioRemote(RemoteEntity):
|
||||||
"""Representation of a Xiaomi Miio Remote device."""
|
"""Representation of a Xiaomi Miio Remote device."""
|
||||||
|
|
||||||
|
_attr_should_poll = False
|
||||||
|
|
||||||
def __init__(self, friendly_name, device, unique_id, slot, timeout, commands):
|
def __init__(self, friendly_name, device, unique_id, slot, timeout, commands):
|
||||||
"""Initialize the remote."""
|
"""Initialize the remote."""
|
||||||
self._name = friendly_name
|
self._name = friendly_name
|
||||||
@ -225,11 +227,6 @@ class XiaomiMiioRemote(RemoteEntity):
|
|||||||
except DeviceException:
|
except DeviceException:
|
||||||
return False
|
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):
|
async def async_turn_on(self, **kwargs):
|
||||||
"""Turn the device on."""
|
"""Turn the device on."""
|
||||||
_LOGGER.error(
|
_LOGGER.error(
|
||||||
|
@ -79,6 +79,8 @@ async def async_setup_entry(
|
|||||||
class MusicCastMediaPlayer(MusicCastDeviceEntity, MediaPlayerEntity):
|
class MusicCastMediaPlayer(MusicCastDeviceEntity, MediaPlayerEntity):
|
||||||
"""The musiccast media player."""
|
"""The musiccast media player."""
|
||||||
|
|
||||||
|
_attr_should_poll = False
|
||||||
|
|
||||||
def __init__(self, zone_id, name, entry_id, coordinator):
|
def __init__(self, zone_id, name, entry_id, coordinator):
|
||||||
"""Initialize the musiccast device."""
|
"""Initialize the musiccast device."""
|
||||||
self._player_state = STATE_PLAYING
|
self._player_state = STATE_PLAYING
|
||||||
@ -119,11 +121,6 @@ class MusicCastMediaPlayer(MusicCastDeviceEntity, MediaPlayerEntity):
|
|||||||
self.update_all_mc_entities
|
self.update_all_mc_entities
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
|
||||||
def should_poll(self):
|
|
||||||
"""Push an update after each command."""
|
|
||||||
return False
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def ip_address(self):
|
def ip_address(self):
|
||||||
"""Return the ip address of the musiccast device."""
|
"""Return the ip address of the musiccast device."""
|
||||||
|
@ -124,6 +124,7 @@ class ZhongHongClimate(ClimateEntity):
|
|||||||
HVACMode.FAN_ONLY,
|
HVACMode.FAN_ONLY,
|
||||||
HVACMode.OFF,
|
HVACMode.OFF,
|
||||||
]
|
]
|
||||||
|
_attr_should_poll = False
|
||||||
_attr_supported_features = (
|
_attr_supported_features = (
|
||||||
ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.FAN_MODE
|
ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.FAN_MODE
|
||||||
)
|
)
|
||||||
@ -160,11 +161,6 @@ class ZhongHongClimate(ClimateEntity):
|
|||||||
self._target_temperature = self._device.target_temperature
|
self._target_temperature = self._device.target_temperature
|
||||||
self.schedule_update_ha_state()
|
self.schedule_update_ha_state()
|
||||||
|
|
||||||
@property
|
|
||||||
def should_poll(self):
|
|
||||||
"""Return the polling state."""
|
|
||||||
return False
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Return the name of the thermostat, if any."""
|
"""Return the name of the thermostat, if any."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user