Add new Water Meter Sensor for Toon (#37879)

Co-authored-by: Franck Nijhof <git@frenck.dev>
pull/40212/head
tizzen33 2020-08-05 01:02:19 +02:00 committed by GitHub
parent e53d770b3d
commit 2d7b9326ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 89 additions and 0 deletions

View File

@ -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 = {

View File

@ -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."""

View File

@ -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."""