From 2a8109304f42b3d93cb171cfc6ac7265a22623ca Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Fri, 26 Aug 2022 10:20:38 +0200 Subject: [PATCH] Use _attr_should_poll in components [h-i] (#77270) --- homeassistant/components/heos/media_player.py | 7 ++----- .../components/hikvision/binary_sensor.py | 7 ++----- homeassistant/components/hlk_sw16/__init__.py | 7 ++----- .../components/home_connect/entity.py | 7 ++----- homeassistant/components/homematic/entity.py | 13 +++--------- .../homematicip_cloud/alarm_control_panel.py | 6 +----- .../homematicip_cloud/generic_entity.py | 7 ++----- .../components/huawei_lte/__init__.py | 6 +----- homeassistant/components/hyperion/light.py | 6 +----- homeassistant/components/hyperion/switch.py | 6 +----- .../components/iaqualink/__init__.py | 11 ++-------- homeassistant/components/icloud/sensor.py | 6 +----- homeassistant/components/ihc/ihcdevice.py | 7 ++----- .../components/incomfort/__init__.py | 7 ++----- .../components/input_datetime/__init__.py | 7 ++----- .../components/input_number/__init__.py | 7 ++----- .../components/input_text/__init__.py | 7 ++----- .../components/insteon/insteon_entity.py | 7 ++----- .../components/intesishome/climate.py | 7 ++----- homeassistant/components/izone/climate.py | 20 ++++--------------- 20 files changed, 38 insertions(+), 120 deletions(-) diff --git a/homeassistant/components/heos/media_player.py b/homeassistant/components/heos/media_player.py index ad9225d9b21..765fe2f79c5 100644 --- a/homeassistant/components/heos/media_player.py +++ b/homeassistant/components/heos/media_player.py @@ -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.""" diff --git a/homeassistant/components/hikvision/binary_sensor.py b/homeassistant/components/hikvision/binary_sensor.py index 011f4ca05d1..e7f3c49fb08 100644 --- a/homeassistant/components/hikvision/binary_sensor.py +++ b/homeassistant/components/hikvision/binary_sensor.py @@ -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.""" diff --git a/homeassistant/components/hlk_sw16/__init__.py b/homeassistant/components/hlk_sw16/__init__.py index c695f5524c3..f80972da613 100644 --- a/homeassistant/components/hlk_sw16/__init__.py +++ b/homeassistant/components/hlk_sw16/__init__.py @@ -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.""" diff --git a/homeassistant/components/home_connect/entity.py b/homeassistant/components/home_connect/entity.py index b27988f997d..3c2ac52929a 100644 --- a/homeassistant/components/home_connect/entity.py +++ b/homeassistant/components/home_connect/entity.py @@ -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).""" diff --git a/homeassistant/components/homematic/entity.py b/homeassistant/components/homematic/entity.py index fee68caf7ed..700ef5cdc94 100644 --- a/homeassistant/components/homematic/entity.py +++ b/homeassistant/components/homematic/entity.py @@ -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.""" diff --git a/homeassistant/components/homematicip_cloud/alarm_control_panel.py b/homeassistant/components/homematicip_cloud/alarm_control_panel.py index 3b6ae684d07..85d241051c1 100644 --- a/homeassistant/components/homematicip_cloud/alarm_control_panel.py +++ b/homeassistant/components/homematicip_cloud/alarm_control_panel.py @@ -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.""" diff --git a/homeassistant/components/homematicip_cloud/generic_entity.py b/homeassistant/components/homematicip_cloud/generic_entity.py index 8bcea5d1435..a5296675292 100644 --- a/homeassistant/components/homematicip_cloud/generic_entity.py +++ b/homeassistant/components/homematicip_cloud/generic_entity.py @@ -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.""" diff --git a/homeassistant/components/huawei_lte/__init__.py b/homeassistant/components/huawei_lte/__init__.py index 565286c4505..5740cf99f53 100644 --- a/homeassistant/components/huawei_lte/__init__.py +++ b/homeassistant/components/huawei_lte/__init__.py @@ -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 diff --git a/homeassistant/components/hyperion/light.py b/homeassistant/components/hyperion/light.py index fc4ec4d023e..49177ac94c6 100644 --- a/homeassistant/components/hyperion/light.py +++ b/homeassistant/components/hyperion/light.py @@ -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.""" diff --git a/homeassistant/components/hyperion/switch.py b/homeassistant/components/hyperion/switch.py index bf4958d845c..523aa3e31b6 100644 --- a/homeassistant/components/hyperion/switch.py +++ b/homeassistant/components/hyperion/switch.py @@ -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.""" diff --git a/homeassistant/components/iaqualink/__init__.py b/homeassistant/components/iaqualink/__init__.py index 844313a4aed..61f27e8970c 100644 --- a/homeassistant/components/iaqualink/__init__.py +++ b/homeassistant/components/iaqualink/__init__.py @@ -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.""" diff --git a/homeassistant/components/icloud/sensor.py b/homeassistant/components/icloud/sensor.py index 3feb30f078f..e747d898dea 100644 --- a/homeassistant/components/icloud/sensor.py +++ b/homeassistant/components/icloud/sensor.py @@ -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( diff --git a/homeassistant/components/ihc/ihcdevice.py b/homeassistant/components/ihc/ihcdevice.py index 31887c51397..0c077f8698e 100644 --- a/homeassistant/components/ihc/ihcdevice.py +++ b/homeassistant/components/ihc/ihcdevice.py @@ -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.""" diff --git a/homeassistant/components/incomfort/__init__.py b/homeassistant/components/incomfort/__init__.py index 9b2f0d88b3f..fe3d37e1440 100644 --- a/homeassistant/components/incomfort/__init__.py +++ b/homeassistant/components/incomfort/__init__.py @@ -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 diff --git a/homeassistant/components/input_datetime/__init__.py b/homeassistant/components/input_datetime/__init__.py index 2a64c8d3b89..bda5572081c 100644 --- a/homeassistant/components/input_datetime/__init__.py +++ b/homeassistant/components/input_datetime/__init__.py @@ -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.""" diff --git a/homeassistant/components/input_number/__init__.py b/homeassistant/components/input_number/__init__.py index 8e922687e59..ff01bd124b6 100644 --- a/homeassistant/components/input_number/__init__.py +++ b/homeassistant/components/input_number/__init__.py @@ -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.""" diff --git a/homeassistant/components/input_text/__init__.py b/homeassistant/components/input_text/__init__.py index f1e0b45afec..38d74f57931 100644 --- a/homeassistant/components/input_text/__init__.py +++ b/homeassistant/components/input_text/__init__.py @@ -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.""" diff --git a/homeassistant/components/insteon/insteon_entity.py b/homeassistant/components/insteon/insteon_entity.py index 67d30ba8cad..d1ba7c5f829 100644 --- a/homeassistant/components/insteon/insteon_entity.py +++ b/homeassistant/components/insteon/insteon_entity.py @@ -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.""" diff --git a/homeassistant/components/intesishome/climate.py b/homeassistant/components/intesishome/climate.py index 050bed8c721..61b171ea8cc 100644 --- a/homeassistant/components/intesishome/climate.py +++ b/homeassistant/components/intesishome/climate.py @@ -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.""" diff --git a/homeassistant/components/izone/climate.py b/homeassistant/components/izone/climate.py index 58834f995dd..df7b8af4fa3 100644 --- a/homeassistant/components/izone/climate.py +++ b/homeassistant/components/izone/climate.py @@ -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):