mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Use _attr_should_poll in components [h-i] (#77270)
This commit is contained in:
parent
a46c25d2c8
commit
2a8109304f
@ -117,6 +117,8 @@ def log_command_error(
|
||||
class HeosMediaPlayer(MediaPlayerEntity):
|
||||
"""The HEOS player."""
|
||||
|
||||
_attr_should_poll = False
|
||||
|
||||
def __init__(self, player):
|
||||
"""Initialize."""
|
||||
self._media_position_updated_at = None
|
||||
@ -402,11 +404,6 @@ class HeosMediaPlayer(MediaPlayerEntity):
|
||||
"""Return the name of the device."""
|
||||
return self._player.name
|
||||
|
||||
@property
|
||||
def should_poll(self) -> bool:
|
||||
"""No polling needed for this device."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def shuffle(self) -> bool:
|
||||
"""Boolean if shuffle is enabled."""
|
||||
|
@ -199,6 +199,8 @@ class HikvisionData:
|
||||
class HikvisionBinarySensor(BinarySensorEntity):
|
||||
"""Representation of a Hikvision binary sensor."""
|
||||
|
||||
_attr_should_poll = False
|
||||
|
||||
def __init__(self, hass, sensor, channel, cam, delay):
|
||||
"""Initialize the binary_sensor."""
|
||||
self._hass = hass
|
||||
@ -255,11 +257,6 @@ class HikvisionBinarySensor(BinarySensorEntity):
|
||||
# Sensor must be unknown to us, add as generic
|
||||
return None
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""No polling needed."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def extra_state_attributes(self):
|
||||
"""Return the state attributes."""
|
||||
|
@ -138,6 +138,8 @@ class SW16Device(Entity):
|
||||
Contains the common logic for HLK-SW16 entities.
|
||||
"""
|
||||
|
||||
_attr_should_poll = False
|
||||
|
||||
def __init__(self, device_port, entry_id, client):
|
||||
"""Initialize the device."""
|
||||
# HLK-SW16 specific attributes for every component type
|
||||
@ -159,11 +161,6 @@ class SW16Device(Entity):
|
||||
self._is_on = event
|
||||
self.async_write_ha_state()
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""No polling needed."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return a name for the device."""
|
||||
|
@ -15,6 +15,8 @@ _LOGGER = logging.getLogger(__name__)
|
||||
class HomeConnectEntity(Entity):
|
||||
"""Generic Home Connect entity (base class)."""
|
||||
|
||||
_attr_should_poll = False
|
||||
|
||||
def __init__(self, device: HomeConnectDevice, desc: str) -> None:
|
||||
"""Initialize the entity."""
|
||||
self.device = device
|
||||
@ -35,11 +37,6 @@ class HomeConnectEntity(Entity):
|
||||
if ha_id == self.device.appliance.haId:
|
||||
self.async_entity_update()
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""No polling needed."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the node (used for Entity_ID)."""
|
||||
|
@ -35,6 +35,7 @@ class HMDevice(Entity):
|
||||
|
||||
_homematic: HMConnection
|
||||
_hmdevice: HMGeneric
|
||||
_attr_should_poll = False
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@ -69,11 +70,6 @@ class HMDevice(Entity):
|
||||
"""Return unique ID. HomeMatic entity IDs are unique by default."""
|
||||
return self._unique_id.replace(" ", "_")
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""Return false. HomeMatic states are pushed by the XML-RPC Server."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the device."""
|
||||
@ -213,6 +209,8 @@ class HMDevice(Entity):
|
||||
class HMHub(Entity):
|
||||
"""The HomeMatic hub. (CCU2/HomeGear)."""
|
||||
|
||||
_attr_should_poll = False
|
||||
|
||||
def __init__(self, hass, homematic, name):
|
||||
"""Initialize HomeMatic hub."""
|
||||
self.hass = hass
|
||||
@ -234,11 +232,6 @@ class HMHub(Entity):
|
||||
"""Return the name of the device."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""Return false. HomeMatic Hub object updates variables."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
"""Return the state of the entity."""
|
||||
|
@ -41,6 +41,7 @@ async def async_setup_entry(
|
||||
class HomematicipAlarmControlPanelEntity(AlarmControlPanelEntity):
|
||||
"""Representation of the HomematicIP alarm control panel."""
|
||||
|
||||
_attr_should_poll = False
|
||||
_attr_supported_features = (
|
||||
AlarmControlPanelEntityFeature.ARM_HOME
|
||||
| AlarmControlPanelEntityFeature.ARM_AWAY
|
||||
@ -120,11 +121,6 @@ class HomematicipAlarmControlPanelEntity(AlarmControlPanelEntity):
|
||||
name = f"{self._home.name} {name}"
|
||||
return name
|
||||
|
||||
@property
|
||||
def should_poll(self) -> bool:
|
||||
"""No polling needed."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def available(self) -> bool:
|
||||
"""Return if alarm control panel is available."""
|
||||
|
@ -72,6 +72,8 @@ GROUP_ATTRIBUTES = {
|
||||
class HomematicipGenericEntity(Entity):
|
||||
"""Representation of the HomematicIP generic entity."""
|
||||
|
||||
_attr_should_poll = False
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
hap: HomematicipHAP,
|
||||
@ -201,11 +203,6 @@ class HomematicipGenericEntity(Entity):
|
||||
|
||||
return name
|
||||
|
||||
@property
|
||||
def should_poll(self) -> bool:
|
||||
"""No polling needed."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def available(self) -> bool:
|
||||
"""Return if entity is available."""
|
||||
|
@ -588,6 +588,7 @@ class HuaweiLteBaseEntity(Entity):
|
||||
_available: bool = field(default=True, init=False)
|
||||
_unsub_handlers: list[Callable] = field(default_factory=list, init=False)
|
||||
_attr_has_entity_name: bool = field(default=True, init=False)
|
||||
_attr_should_poll = False
|
||||
|
||||
@property
|
||||
def _device_unique_id(self) -> str:
|
||||
@ -604,11 +605,6 @@ class HuaweiLteBaseEntity(Entity):
|
||||
"""Return whether the entity is available."""
|
||||
return self._available
|
||||
|
||||
@property
|
||||
def should_poll(self) -> bool:
|
||||
"""Huawei LTE entities report their state without polling."""
|
||||
return False
|
||||
|
||||
async def async_update(self) -> None:
|
||||
"""Update state."""
|
||||
raise NotImplementedError
|
||||
|
@ -125,6 +125,7 @@ class HyperionBaseLight(LightEntity):
|
||||
"""A Hyperion light base class."""
|
||||
|
||||
_attr_color_mode = ColorMode.HS
|
||||
_attr_should_poll = False
|
||||
_attr_supported_color_modes = {ColorMode.HS}
|
||||
_attr_supported_features = LightEntityFeature.EFFECT
|
||||
|
||||
@ -178,11 +179,6 @@ class HyperionBaseLight(LightEntity):
|
||||
"""Whether or not the entity is enabled by default."""
|
||||
return True
|
||||
|
||||
@property
|
||||
def should_poll(self) -> bool:
|
||||
"""Return whether or not this entity should be polled."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
"""Return the name of the light."""
|
||||
|
@ -127,6 +127,7 @@ class HyperionComponentSwitch(SwitchEntity):
|
||||
"""ComponentBinarySwitch switch class."""
|
||||
|
||||
_attr_entity_category = EntityCategory.CONFIG
|
||||
_attr_should_poll = False
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@ -149,11 +150,6 @@ class HyperionComponentSwitch(SwitchEntity):
|
||||
f"{KEY_COMPONENTS}-{KEY_UPDATE}": self._update_components
|
||||
}
|
||||
|
||||
@property
|
||||
def should_poll(self) -> bool:
|
||||
"""Return whether or not this entity should be polled."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def entity_registry_enabled_default(self) -> bool:
|
||||
"""Whether or not the entity is enabled by default."""
|
||||
|
@ -194,6 +194,8 @@ class AqualinkEntity(Entity):
|
||||
class.
|
||||
"""
|
||||
|
||||
_attr_should_poll = False
|
||||
|
||||
def __init__(self, dev: AqualinkDevice) -> None:
|
||||
"""Initialize the entity."""
|
||||
self.dev = dev
|
||||
@ -204,15 +206,6 @@ class AqualinkEntity(Entity):
|
||||
async_dispatcher_connect(self.hass, DOMAIN, self.async_write_ha_state)
|
||||
)
|
||||
|
||||
@property
|
||||
def should_poll(self) -> bool:
|
||||
"""Return False as entities shouldn't be polled.
|
||||
|
||||
Entities are checked periodically as the integration runs periodic
|
||||
updates on a timer.
|
||||
"""
|
||||
return False
|
||||
|
||||
@property
|
||||
def unique_id(self) -> str:
|
||||
"""Return a unique identifier for this entity."""
|
||||
|
@ -56,6 +56,7 @@ class IcloudDeviceBatterySensor(SensorEntity):
|
||||
|
||||
_attr_device_class = SensorDeviceClass.BATTERY
|
||||
_attr_native_unit_of_measurement = PERCENTAGE
|
||||
_attr_should_poll = False
|
||||
|
||||
def __init__(self, account: IcloudAccount, device: IcloudDevice) -> None:
|
||||
"""Initialize the battery sensor."""
|
||||
@ -102,11 +103,6 @@ class IcloudDeviceBatterySensor(SensorEntity):
|
||||
name=self._device.name,
|
||||
)
|
||||
|
||||
@property
|
||||
def should_poll(self) -> bool:
|
||||
"""No polling needed."""
|
||||
return False
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
"""Register state update callback."""
|
||||
self._unsub_dispatcher = async_dispatcher_connect(
|
||||
|
@ -18,6 +18,8 @@ class IHCDevice(Entity):
|
||||
Derived classes must implement the on_ihc_change method
|
||||
"""
|
||||
|
||||
_attr_should_poll = False
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
ihc_controller: IHCController,
|
||||
@ -56,11 +58,6 @@ class IHCDevice(Entity):
|
||||
_LOGGER.debug("Adding IHC entity notify event: %s", self.ihc_id)
|
||||
self.ihc_controller.add_notify_event(self.ihc_id, self.on_ihc_change, True)
|
||||
|
||||
@property
|
||||
def should_poll(self) -> bool:
|
||||
"""No polling needed for IHC devices."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the device name."""
|
||||
|
@ -91,6 +91,8 @@ class IncomfortEntity(Entity):
|
||||
class IncomfortChild(IncomfortEntity):
|
||||
"""Base class for all InComfort entities (excluding the boiler)."""
|
||||
|
||||
_attr_should_poll = False
|
||||
|
||||
async def async_added_to_hass(self) -> None:
|
||||
"""Set up a listener when this entity is added to HA."""
|
||||
self.async_on_remove(async_dispatcher_connect(self.hass, DOMAIN, self._refresh))
|
||||
@ -98,8 +100,3 @@ class IncomfortChild(IncomfortEntity):
|
||||
@callback
|
||||
def _refresh(self) -> None:
|
||||
self.async_schedule_update_ha_state(force_refresh=True)
|
||||
|
||||
@property
|
||||
def should_poll(self) -> bool:
|
||||
"""Return False as this device should never be polled."""
|
||||
return False
|
||||
|
@ -234,6 +234,8 @@ class DateTimeStorageCollection(collection.StorageCollection):
|
||||
class InputDatetime(RestoreEntity):
|
||||
"""Representation of a datetime input."""
|
||||
|
||||
_attr_should_poll = False
|
||||
|
||||
def __init__(self, config: dict) -> None:
|
||||
"""Initialize a select input."""
|
||||
self._config = config
|
||||
@ -303,11 +305,6 @@ class InputDatetime(RestoreEntity):
|
||||
tzinfo=dt_util.DEFAULT_TIME_ZONE
|
||||
)
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""If entity should be polled."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the select input."""
|
||||
|
@ -205,6 +205,8 @@ class NumberStorageCollection(collection.StorageCollection):
|
||||
class InputNumber(RestoreEntity):
|
||||
"""Representation of a slider."""
|
||||
|
||||
_attr_should_poll = False
|
||||
|
||||
def __init__(self, config: dict) -> None:
|
||||
"""Initialize an input number."""
|
||||
self._config = config
|
||||
@ -219,11 +221,6 @@ class InputNumber(RestoreEntity):
|
||||
input_num.editable = False
|
||||
return input_num
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""If entity should be polled."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def _minimum(self) -> float:
|
||||
"""Return minimum allowed value."""
|
||||
|
@ -198,6 +198,8 @@ class InputTextStorageCollection(collection.StorageCollection):
|
||||
class InputText(RestoreEntity):
|
||||
"""Represent a text box."""
|
||||
|
||||
_attr_should_poll = False
|
||||
|
||||
def __init__(self, config: dict) -> None:
|
||||
"""Initialize a text input."""
|
||||
self._config = config
|
||||
@ -212,11 +214,6 @@ class InputText(RestoreEntity):
|
||||
input_text.editable = False
|
||||
return input_text
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""If entity should be polled."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the text input entity."""
|
||||
|
@ -28,6 +28,8 @@ _LOGGER = logging.getLogger(__name__)
|
||||
class InsteonEntity(Entity):
|
||||
"""INSTEON abstract base entity."""
|
||||
|
||||
_attr_should_poll = False
|
||||
|
||||
def __init__(self, device, group):
|
||||
"""Initialize the INSTEON binary sensor."""
|
||||
self._insteon_device_group = device.groups[group]
|
||||
@ -37,11 +39,6 @@ class InsteonEntity(Entity):
|
||||
"""Return the hash of the Insteon Entity."""
|
||||
return hash(self._insteon_device)
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""No polling needed."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def address(self):
|
||||
"""Return the address of the node."""
|
||||
|
@ -143,6 +143,8 @@ async def async_setup_platform(
|
||||
class IntesisAC(ClimateEntity):
|
||||
"""Represents an Intesishome air conditioning device."""
|
||||
|
||||
_attr_should_poll = False
|
||||
|
||||
def __init__(self, ih_device_id, ih_device, controller):
|
||||
"""Initialize the thermostat."""
|
||||
self._controller = controller
|
||||
@ -410,11 +412,6 @@ class IntesisAC(ClimateEntity):
|
||||
"""Return the maximum temperature for the current mode of operation."""
|
||||
return self._max_temp
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""Poll for updates if pyIntesisHome doesn't have a socket open."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def fan_mode(self):
|
||||
"""Return whether the fan is on."""
|
||||
|
@ -126,6 +126,8 @@ def _return_on_connection_error(ret=None):
|
||||
class ControllerDevice(ClimateEntity):
|
||||
"""Representation of iZone Controller."""
|
||||
|
||||
_attr_should_poll = False
|
||||
|
||||
def __init__(self, controller: Controller) -> None:
|
||||
"""Initialise ControllerDevice."""
|
||||
self._controller = controller
|
||||
@ -250,14 +252,6 @@ class ControllerDevice(ClimateEntity):
|
||||
"""Return the name of the entity."""
|
||||
return f"iZone Controller {self._controller.device_uid}"
|
||||
|
||||
@property
|
||||
def should_poll(self) -> bool:
|
||||
"""Return True if entity has to be polled for state.
|
||||
|
||||
False if entity pushes its state to HA.
|
||||
"""
|
||||
return False
|
||||
|
||||
@property
|
||||
def temperature_unit(self) -> str:
|
||||
"""Return the unit of measurement which this thermostat uses."""
|
||||
@ -448,6 +442,8 @@ class ControllerDevice(ClimateEntity):
|
||||
class ZoneDevice(ClimateEntity):
|
||||
"""Representation of iZone Zone."""
|
||||
|
||||
_attr_should_poll = False
|
||||
|
||||
def __init__(self, controller: ControllerDevice, zone: Zone) -> None:
|
||||
"""Initialise ZoneDevice."""
|
||||
self._controller = controller
|
||||
@ -525,14 +521,6 @@ class ZoneDevice(ClimateEntity):
|
||||
"""Return the name of the entity."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def should_poll(self) -> bool:
|
||||
"""Return True if entity has to be polled for state.
|
||||
|
||||
False if entity pushes its state to HA.
|
||||
"""
|
||||
return False
|
||||
|
||||
@property # type: ignore[misc]
|
||||
@_return_on_connection_error(0)
|
||||
def supported_features(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user