From 8d83341308ba68b305095d1178082b8dc972a902 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Mon, 19 May 2025 11:50:41 +0200 Subject: [PATCH] Mark type hint as compulsory for entity.available property (#145189) --- homeassistant/components/mediaroom/media_player.py | 2 +- homeassistant/components/osramlightify/light.py | 2 +- homeassistant/components/rmvtransport/sensor.py | 2 +- homeassistant/components/sony_projector/switch.py | 2 +- homeassistant/components/starline/button.py | 2 +- homeassistant/components/supervisord/sensor.py | 2 +- homeassistant/components/syncthing/sensor.py | 2 +- homeassistant/components/tfiac/climate.py | 2 +- homeassistant/components/versasense/sensor.py | 2 +- homeassistant/components/versasense/switch.py | 2 +- homeassistant/components/wiffi/binary_sensor.py | 2 +- homeassistant/components/wiffi/sensor.py | 4 ++-- homeassistant/components/xiaomi_miio/light.py | 4 ++-- homeassistant/components/xiaomi_miio/sensor.py | 4 ++-- homeassistant/components/xiaomi_miio/switch.py | 2 +- pylint/plugins/hass_enforce_type_hints.py | 1 + 16 files changed, 19 insertions(+), 18 deletions(-) diff --git a/homeassistant/components/mediaroom/media_player.py b/homeassistant/components/mediaroom/media_player.py index 4561c38ce80..bccbe9f66ac 100644 --- a/homeassistant/components/mediaroom/media_player.py +++ b/homeassistant/components/mediaroom/media_player.py @@ -165,7 +165,7 @@ class MediaroomDevice(MediaPlayerEntity): self._unique_id = None @property - def available(self): + def available(self) -> bool: """Return True if entity is available.""" return self._available diff --git a/homeassistant/components/osramlightify/light.py b/homeassistant/components/osramlightify/light.py index 25380810862..42af6c74e45 100644 --- a/homeassistant/components/osramlightify/light.py +++ b/homeassistant/components/osramlightify/light.py @@ -279,7 +279,7 @@ class Luminary(LightEntity): return self._device_attributes @property - def available(self): + def available(self) -> bool: """Return True if entity is available.""" return self._available diff --git a/homeassistant/components/rmvtransport/sensor.py b/homeassistant/components/rmvtransport/sensor.py index c3217d9334e..92f4f5a0434 100644 --- a/homeassistant/components/rmvtransport/sensor.py +++ b/homeassistant/components/rmvtransport/sensor.py @@ -156,7 +156,7 @@ class RMVDepartureSensor(SensorEntity): return self._name @property - def available(self): + def available(self) -> bool: """Return True if entity is available.""" return self._state is not None diff --git a/homeassistant/components/sony_projector/switch.py b/homeassistant/components/sony_projector/switch.py index f024c4ef4f7..c4d993cc22a 100644 --- a/homeassistant/components/sony_projector/switch.py +++ b/homeassistant/components/sony_projector/switch.py @@ -64,7 +64,7 @@ class SonyProjector(SwitchEntity): self._attributes = {} @property - def available(self): + def available(self) -> bool: """Return if projector is available.""" return self._available diff --git a/homeassistant/components/starline/button.py b/homeassistant/components/starline/button.py index fa46d2a3773..1d238e232b9 100644 --- a/homeassistant/components/starline/button.py +++ b/homeassistant/components/starline/button.py @@ -64,7 +64,7 @@ class StarlineButton(StarlineEntity, ButtonEntity): self.entity_description = description @property - def available(self): + def available(self) -> bool: """Return True if entity is available.""" return super().available and self._device.online diff --git a/homeassistant/components/supervisord/sensor.py b/homeassistant/components/supervisord/sensor.py index c443e1e63df..c14eb6fb353 100644 --- a/homeassistant/components/supervisord/sensor.py +++ b/homeassistant/components/supervisord/sensor.py @@ -71,7 +71,7 @@ class SupervisorProcessSensor(SensorEntity): return self._info.get("statename") @property - def available(self): + def available(self) -> bool: """Could the device be accessed during the last update call.""" return self._available diff --git a/homeassistant/components/syncthing/sensor.py b/homeassistant/components/syncthing/sensor.py index 697ea8aea6e..d6ad17969db 100644 --- a/homeassistant/components/syncthing/sensor.py +++ b/homeassistant/components/syncthing/sensor.py @@ -111,7 +111,7 @@ class FolderSensor(SensorEntity): return self._state["state"] @property - def available(self): + def available(self) -> bool: """Could the device be accessed during the last update call.""" return self._state is not None diff --git a/homeassistant/components/tfiac/climate.py b/homeassistant/components/tfiac/climate.py index 9571597abe6..7fc6e2594c4 100644 --- a/homeassistant/components/tfiac/climate.py +++ b/homeassistant/components/tfiac/climate.py @@ -95,7 +95,7 @@ class TfiacClimate(ClimateEntity): self._available = True @property - def available(self): + def available(self) -> bool: """Return if the device is available.""" return self._available diff --git a/homeassistant/components/versasense/sensor.py b/homeassistant/components/versasense/sensor.py index 4c861bf5787..3956bd21fea 100644 --- a/homeassistant/components/versasense/sensor.py +++ b/homeassistant/components/versasense/sensor.py @@ -86,7 +86,7 @@ class VSensor(SensorEntity): return self._unit @property - def available(self): + def available(self) -> bool: """Return if the sensor is available.""" return self._available diff --git a/homeassistant/components/versasense/switch.py b/homeassistant/components/versasense/switch.py index 10bca79e536..828dbf6d9af 100644 --- a/homeassistant/components/versasense/switch.py +++ b/homeassistant/components/versasense/switch.py @@ -84,7 +84,7 @@ class VActuator(SwitchEntity): return self._is_on @property - def available(self): + def available(self) -> bool: """Return if the actuator is available.""" return self._available diff --git a/homeassistant/components/wiffi/binary_sensor.py b/homeassistant/components/wiffi/binary_sensor.py index 93fdb7cce1c..abb6dd11235 100644 --- a/homeassistant/components/wiffi/binary_sensor.py +++ b/homeassistant/components/wiffi/binary_sensor.py @@ -44,7 +44,7 @@ class BoolEntity(WiffiEntity, BinarySensorEntity): self.reset_expiration_date() @property - def available(self): + def available(self) -> bool: """Return true if value is valid.""" return self._attr_is_on is not None diff --git a/homeassistant/components/wiffi/sensor.py b/homeassistant/components/wiffi/sensor.py index 9afcc719c9b..f28c68dc31c 100644 --- a/homeassistant/components/wiffi/sensor.py +++ b/homeassistant/components/wiffi/sensor.py @@ -86,7 +86,7 @@ class NumberEntity(WiffiEntity, SensorEntity): self.reset_expiration_date() @property - def available(self): + def available(self) -> bool: """Return true if value is valid.""" return self._attr_native_value is not None @@ -116,7 +116,7 @@ class StringEntity(WiffiEntity, SensorEntity): self.reset_expiration_date() @property - def available(self): + def available(self) -> bool: """Return true if value is valid.""" return self._attr_native_value is not None diff --git a/homeassistant/components/xiaomi_miio/light.py b/homeassistant/components/xiaomi_miio/light.py index 81f68306cbc..781ac0b4acd 100644 --- a/homeassistant/components/xiaomi_miio/light.py +++ b/homeassistant/components/xiaomi_miio/light.py @@ -271,7 +271,7 @@ class XiaomiPhilipsAbstractLight(XiaomiMiioEntity, LightEntity): self._state_attrs = {} @property - def available(self): + def available(self) -> bool: """Return true when state is known.""" return self._available @@ -1027,7 +1027,7 @@ class XiaomiGatewayLight(LightEntity): return self._name @property - def available(self): + def available(self) -> bool: """Return true when state is known.""" return self._available diff --git a/homeassistant/components/xiaomi_miio/sensor.py b/homeassistant/components/xiaomi_miio/sensor.py index 6f623c46af8..e837192ddd7 100644 --- a/homeassistant/components/xiaomi_miio/sensor.py +++ b/homeassistant/components/xiaomi_miio/sensor.py @@ -928,7 +928,7 @@ class XiaomiAirQualityMonitor(XiaomiMiioEntity, SensorEntity): self.entity_description = description @property - def available(self): + def available(self) -> bool: """Return true when state is known.""" return self._available @@ -1001,7 +1001,7 @@ class XiaomiGatewayIlluminanceSensor(SensorEntity): self._state = None @property - def available(self): + def available(self) -> bool: """Return true when state is known.""" return self._available diff --git a/homeassistant/components/xiaomi_miio/switch.py b/homeassistant/components/xiaomi_miio/switch.py index e4b94aebc20..4469849eae7 100644 --- a/homeassistant/components/xiaomi_miio/switch.py +++ b/homeassistant/components/xiaomi_miio/switch.py @@ -789,7 +789,7 @@ class XiaomiPlugGenericSwitch(XiaomiMiioEntity, SwitchEntity): return self._icon @property - def available(self): + def available(self) -> bool: """Return true when state is known.""" return self._available diff --git a/pylint/plugins/hass_enforce_type_hints.py b/pylint/plugins/hass_enforce_type_hints.py index 9855f688622..ddce048e4a6 100644 --- a/pylint/plugins/hass_enforce_type_hints.py +++ b/pylint/plugins/hass_enforce_type_hints.py @@ -676,6 +676,7 @@ _ENTITY_MATCH: list[TypeHintMatch] = [ TypeHintMatch( function_name="available", return_type="bool", + mandatory=True, ), TypeHintMatch( function_name="assumed_state",