From 2d7b9326ee34b9992b5c4ffc77dbdbdcc8f2e089 Mon Sep 17 00:00:00 2001 From: tizzen33 <53906250+tizzen33@users.noreply.github.com> Date: Wed, 5 Aug 2020 01:02:19 +0200 Subject: [PATCH] Add new Water Meter Sensor for Toon (#37879) Co-authored-by: Franck Nijhof --- homeassistant/components/toon/const.py | 56 +++++++++++++++++++++++++ homeassistant/components/toon/models.py | 14 +++++++ homeassistant/components/toon/sensor.py | 19 +++++++++ 3 files changed, 89 insertions(+) diff --git a/homeassistant/components/toon/const.py b/homeassistant/components/toon/const.py index 5015d50fa63..c814134f767 100644 --- a/homeassistant/components/toon/const.py +++ b/homeassistant/components/toon/const.py @@ -31,6 +31,8 @@ DEFAULT_MIN_TEMP = 6.0 CURRENCY_EUR = "EUR" VOLUME_CM3 = "CM3" VOLUME_M3 = "M3" +VOLUME_LHOUR = "L/H" +VOLUME_LMIN = "L/MIN" ATTR_DEFAULT_ENABLED = "default_enabled" ATTR_INVERTED = "inverted" @@ -338,6 +340,60 @@ SENSOR_ENTITIES = { ATTR_ICON: "mdi:solar-power", ATTR_DEFAULT_ENABLED: True, }, + "water_average": { + ATTR_NAME: "Average Water Usage", + ATTR_SECTION: "water_usage", + ATTR_MEASUREMENT: "average", + ATTR_UNIT_OF_MEASUREMENT: VOLUME_LMIN, + ATTR_DEVICE_CLASS: None, + ATTR_ICON: "mdi:water", + ATTR_DEFAULT_ENABLED: False, + }, + "water_average_daily": { + ATTR_NAME: "Average Daily Water Usage", + ATTR_SECTION: "water_usage", + ATTR_MEASUREMENT: "day_average", + ATTR_UNIT_OF_MEASUREMENT: VOLUME_M3, + ATTR_DEVICE_CLASS: None, + ATTR_ICON: "mdi:water", + ATTR_DEFAULT_ENABLED: False, + }, + "water_daily_usage": { + ATTR_NAME: "Water Usage Today", + ATTR_SECTION: "water_usage", + ATTR_MEASUREMENT: "day_usage", + ATTR_UNIT_OF_MEASUREMENT: VOLUME_M3, + ATTR_DEVICE_CLASS: None, + ATTR_ICON: "mdi:water", + ATTR_DEFAULT_ENABLED: False, + }, + "water_meter_reading": { + ATTR_NAME: "Water Meter", + ATTR_SECTION: "water_usage", + ATTR_MEASUREMENT: "meter", + ATTR_UNIT_OF_MEASUREMENT: VOLUME_M3, + ATTR_DEVICE_CLASS: None, + ATTR_ICON: "mdi:water", + ATTR_DEFAULT_ENABLED: False, + }, + "water_value": { + ATTR_NAME: "Current Water Usage", + ATTR_SECTION: "water_usage", + ATTR_MEASUREMENT: "current", + ATTR_UNIT_OF_MEASUREMENT: VOLUME_LMIN, + ATTR_DEVICE_CLASS: None, + ATTR_ICON: "mdi:water-pump", + ATTR_DEFAULT_ENABLED: False, + }, + "water_daily_cost": { + ATTR_NAME: "Water Cost Today", + ATTR_SECTION: "water_usage", + ATTR_MEASUREMENT: "day_cost", + ATTR_UNIT_OF_MEASUREMENT: CURRENCY_EUR, + ATTR_DEVICE_CLASS: None, + ATTR_ICON: "mdi:water-pump", + ATTR_DEFAULT_ENABLED: False, + }, } SWITCH_ENTITIES = { diff --git a/homeassistant/components/toon/models.py b/homeassistant/components/toon/models.py index 7634246d1c9..441b718c40a 100644 --- a/homeassistant/components/toon/models.py +++ b/homeassistant/components/toon/models.py @@ -110,6 +110,20 @@ class ToonGasMeterDeviceEntity(ToonEntity): } +class ToonWaterMeterDeviceEntity(ToonEntity): + """Defines a Water Meter device entity.""" + + @property + def device_info(self) -> Dict[str, Any]: + """Return device information about this entity.""" + agreement_id = self.coordinator.data.agreement.agreement_id + return { + "name": "Water Meter", + "identifiers": {(DOMAIN, agreement_id, "water")}, + "via_device": (DOMAIN, agreement_id, "electricity"), + } + + class ToonSolarDeviceEntity(ToonEntity): """Defines a Solar Device device entity.""" diff --git a/homeassistant/components/toon/sensor.py b/homeassistant/components/toon/sensor.py index 2a0604c6c74..e686ff28211 100644 --- a/homeassistant/components/toon/sensor.py +++ b/homeassistant/components/toon/sensor.py @@ -24,6 +24,7 @@ from .models import ( ToonEntity, ToonGasMeterDeviceEntity, ToonSolarDeviceEntity, + ToonWaterMeterDeviceEntity, ) _LOGGER = logging.getLogger(__name__) @@ -68,6 +69,20 @@ async def async_setup_entry( ] ) + sensors.extend( + [ + ToonWaterMeterDeviceSensor(coordinator, key=key) + for key in ( + "water_average_daily", + "water_average", + "water_daily_cost", + "water_daily_usage", + "water_meter_reading", + "water_value", + ) + ] + ) + if coordinator.data.agreement.is_toon_solar: sensors.extend( [ @@ -146,6 +161,10 @@ class ToonGasMeterDeviceSensor(ToonSensor, ToonGasMeterDeviceEntity): """Defines a Gas Meter sensor.""" +class ToonWaterMeterDeviceSensor(ToonSensor, ToonWaterMeterDeviceEntity): + """Defines a Water Meter sensor.""" + + class ToonSolarDeviceSensor(ToonSensor, ToonSolarDeviceEntity): """Defines a Solar sensor."""