From dad9423c086dc9695e558a19dc382e6a69a8ab59 Mon Sep 17 00:00:00 2001
From: Ben Van Mechelen <ben@benvm.be>
Date: Tue, 14 May 2024 21:50:38 +0200
Subject: [PATCH] Add water meter to Youless intergration (#117452)

Co-authored-by: Franck Nijhof <git@frenck.dev>
---
 homeassistant/components/youless/sensor.py | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/homeassistant/components/youless/sensor.py b/homeassistant/components/youless/sensor.py
index 81cd8b384d2..ed0fc703cc4 100644
--- a/homeassistant/components/youless/sensor.py
+++ b/homeassistant/components/youless/sensor.py
@@ -42,6 +42,7 @@ async def async_setup_entry(
 
     async_add_entities(
         [
+            WaterSensor(coordinator, device),
             GasSensor(coordinator, device),
             EnergyMeterSensor(
                 coordinator, device, "low", SensorStateClass.TOTAL_INCREASING
@@ -110,6 +111,27 @@ class YoulessBaseSensor(
         return super().available and self.get_sensor is not None
 
 
+class WaterSensor(YoulessBaseSensor):
+    """The Youless Water sensor."""
+
+    _attr_native_unit_of_measurement = UnitOfVolume.CUBIC_METERS
+    _attr_device_class = SensorDeviceClass.WATER
+    _attr_state_class = SensorStateClass.TOTAL_INCREASING
+
+    def __init__(
+        self, coordinator: DataUpdateCoordinator[YoulessAPI], device: str
+    ) -> None:
+        """Instantiate a Water sensor."""
+        super().__init__(coordinator, device, "water", "Water meter", "water")
+        self._attr_name = "Water usage"
+        self._attr_icon = "mdi:water"
+
+    @property
+    def get_sensor(self) -> YoulessSensor | None:
+        """Get the sensor for providing the value."""
+        return self.coordinator.data.water_meter
+
+
 class GasSensor(YoulessBaseSensor):
     """The Youless gas sensor."""
 
-- 
GitLab