From 97dc72a6e22b464cc32b7a3a30bada04b46018f9 Mon Sep 17 00:00:00 2001
From: G Johansson <goran.johansson@shiftit.se>
Date: Wed, 1 Jan 2025 23:02:06 +0100
Subject: [PATCH] Move available property to base entity in Sensibo (#134410)

* Move available property to base entity in Sensibo

* Fix test
---
 homeassistant/components/sensibo/climate.py    |  5 -----
 homeassistant/components/sensibo/entity.py     | 12 +++++++++++-
 tests/components/sensibo/test_binary_sensor.py |  9 +++------
 3 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/homeassistant/components/sensibo/climate.py b/homeassistant/components/sensibo/climate.py
index 5bf455c3631..c66ca47e463 100644
--- a/homeassistant/components/sensibo/climate.py
+++ b/homeassistant/components/sensibo/climate.py
@@ -295,11 +295,6 @@ class SensiboClimate(SensiboDeviceBaseEntity, ClimateEntity):
         """Return the maximum temperature."""
         return self.device_data.temp_list[-1]
 
-    @property
-    def available(self) -> bool:
-        """Return True if entity is available."""
-        return self.device_data.available and super().available
-
     async def async_set_temperature(self, **kwargs: Any) -> None:
         """Set new target temperature."""
         if "targetTemperature" not in self.device_data.active_features:
diff --git a/homeassistant/components/sensibo/entity.py b/homeassistant/components/sensibo/entity.py
index b13a5f82111..f9ffc4b31c5 100644
--- a/homeassistant/components/sensibo/entity.py
+++ b/homeassistant/components/sensibo/entity.py
@@ -75,6 +75,11 @@ class SensiboBaseEntity(CoordinatorEntity[SensiboDataUpdateCoordinator]):
         """Return data for device."""
         return self.coordinator.data.parsed[self._device_id]
 
+    @property
+    def available(self) -> bool:
+        """Return True if entity is available."""
+        return self.device_data.available and super().available
+
 
 class SensiboDeviceBaseEntity(SensiboBaseEntity):
     """Representation of a Sensibo Device."""
@@ -125,8 +130,13 @@ class SensiboMotionBaseEntity(SensiboBaseEntity):
         )
 
     @property
-    def sensor_data(self) -> MotionSensor | None:
+    def sensor_data(self) -> MotionSensor:
         """Return data for Motion Sensor."""
         if TYPE_CHECKING:
             assert self.device_data.motion_sensors
         return self.device_data.motion_sensors[self._sensor_id]
+
+    @property
+    def available(self) -> bool:
+        """Return True if entity is available."""
+        return bool(self.sensor_data.alive) and super().available
diff --git a/tests/components/sensibo/test_binary_sensor.py b/tests/components/sensibo/test_binary_sensor.py
index dbc3e87a236..41772f07f96 100644
--- a/tests/components/sensibo/test_binary_sensor.py
+++ b/tests/components/sensibo/test_binary_sensor.py
@@ -10,7 +10,7 @@ import pytest
 from syrupy.assertion import SnapshotAssertion
 
 from homeassistant.config_entries import ConfigEntry
-from homeassistant.const import Platform
+from homeassistant.const import STATE_OFF, STATE_ON, Platform
 from homeassistant.core import HomeAssistant
 from homeassistant.helpers import entity_registry as er
 from homeassistant.util import dt as dt_util
@@ -35,9 +35,6 @@ async def test_binary_sensor(
 
     await snapshot_platform(hass, entity_registry, snapshot, load_int.entry_id)
 
-    monkeypatch.setattr(
-        get_data.parsed["ABC999111"].motion_sensors["AABBCC"], "alive", False
-    )
     monkeypatch.setattr(
         get_data.parsed["ABC999111"].motion_sensors["AABBCC"], "motion", False
     )
@@ -54,5 +51,5 @@ async def test_binary_sensor(
 
     state1 = hass.states.get("binary_sensor.hallway_motion_sensor_connectivity")
     state3 = hass.states.get("binary_sensor.hallway_motion_sensor_motion")
-    assert state1.state == "off"
-    assert state3.state == "off"
+    assert state1.state == STATE_ON
+    assert state3.state == STATE_OFF
-- 
GitLab