Add support for flow sensor metrics in RainMachine (#23221)
* Initial commit * In the clear
This commit is contained in:
1 parent
f3925b7ede
commit
daa1d103d4
4 files changed
+86
-34
No files matched your search
@@ -20,7 +20,7 @@ from homeassistant.helpers.service import verify_domain_control
|
||||
from .config_flow import configured_instances
|
||||
from .const import (
|
||||
DATA_CLIENT, DEFAULT_PORT, DEFAULT_SCAN_INTERVAL, DEFAULT_SSL, DOMAIN,
|
||||
OPERATION_RESTRICTIONS_CURRENT, OPERATION_RESTRICTIONS_UNIVERSAL)
|
||||
PROVISION_SETTINGS, RESTRICTIONS_CURRENT, RESTRICTIONS_UNIVERSAL)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@@ -40,6 +40,11 @@ DEFAULT_ATTRIBUTION = 'Data provided by Green Electronics LLC'
|
||||
DEFAULT_ICON = 'mdi:water'
|
||||
DEFAULT_ZONE_RUN = 60 * 10
|
||||
|
||||
TYPE_FLOW_SENSOR = 'flow_sensor'
|
||||
TYPE_FLOW_SENSOR_CLICK_M3 = 'flow_sensor_clicks_cubic_meter'
|
||||
TYPE_FLOW_SENSOR_CONSUMED_LITERS = 'flow_sensor_consumed_liters'
|
||||
TYPE_FLOW_SENSOR_START_INDEX = 'flow_sensor_start_index'
|
||||
TYPE_FLOW_SENSOR_WATERING_CLICKS = 'flow_sensor_watering_clicks'
|
||||
TYPE_FREEZE = 'freeze'
|
||||
TYPE_FREEZE_PROTECTION = 'freeze_protection'
|
||||
TYPE_FREEZE_TEMP = 'freeze_protect_temp'
|
||||
@@ -51,6 +56,7 @@ TYPE_RAINSENSOR = 'rainsensor'
|
||||
TYPE_WEEKDAY = 'weekday'
|
||||
|
||||
BINARY_SENSORS = {
|
||||
TYPE_FLOW_SENSOR: ('Flow Sensor', 'mdi:water-pump'),
|
||||
TYPE_FREEZE: ('Freeze Restrictions', 'mdi:cancel'),
|
||||
TYPE_FREEZE_PROTECTION: ('Freeze Protection', 'mdi:weather-snowy'),
|
||||
TYPE_HOT_DAYS: ('Extra Water on Hot Days', 'mdi:thermometer-lines'),
|
||||
@@ -62,6 +68,14 @@ BINARY_SENSORS = {
|
||||
}
|
||||
|
||||
SENSORS = {
|
||||
TYPE_FLOW_SENSOR_CLICK_M3: (
|
||||
'Flow Sensor Clicks', 'mdi:water-pump', 'clicks/m^3'),
|
||||
TYPE_FLOW_SENSOR_CONSUMED_LITERS: (
|
||||
'Flow Sensor Consumed Liters', 'mdi:water-pump', 'liter'),
|
||||
TYPE_FLOW_SENSOR_START_INDEX: (
|
||||
'Flow Sensor Start Index', 'mdi:water-pump', None),
|
||||
TYPE_FLOW_SENSOR_WATERING_CLICKS: (
|
||||
'Flow Sensor Clicks', 'mdi:water-pump', 'clicks'),
|
||||
TYPE_FREEZE_TEMP: ('Freeze Protect Temperature', 'mdi:thermometer', '°C'),
|
||||
}
|
||||
|
||||
@@ -319,11 +333,26 @@ class RainMachine:
|
||||
"""Update sensor/binary sensor data."""
|
||||
from regenmaschine.errors import RainMachineError
|
||||
|
||||
tasks = {
|
||||
OPERATION_RESTRICTIONS_CURRENT: self.client.restrictions.current(),
|
||||
OPERATION_RESTRICTIONS_UNIVERSAL:
|
||||
self.client.restrictions.universal(),
|
||||
}
|
||||
tasks = {}
|
||||
|
||||
if (TYPE_FLOW_SENSOR in self.binary_sensor_conditions
|
||||
or any(c in self.sensor_conditions
|
||||
for c in (TYPE_FLOW_SENSOR_CLICK_M3,
|
||||
TYPE_FLOW_SENSOR_CONSUMED_LITERS,
|
||||
TYPE_FLOW_SENSOR_START_INDEX,
|
||||
TYPE_FLOW_SENSOR_WATERING_CLICKS))):
|
||||
tasks[PROVISION_SETTINGS] = self.client.provisioning.settings()
|
||||
|
||||
if any(c in self.binary_sensor_conditions
|
||||
for c in (TYPE_FREEZE, TYPE_HOURLY, TYPE_MONTH, TYPE_RAINDELAY,
|
||||
TYPE_RAINSENSOR, TYPE_WEEKDAY)):
|
||||
tasks[RESTRICTIONS_CURRENT] = self.client.restrictions.current()
|
||||
|
||||
if (any(c in self.binary_sensor_conditions
|
||||
for c in (TYPE_FREEZE_PROTECTION, TYPE_HOT_DAYS))
|
||||
or TYPE_FREEZE_TEMP in self.sensor_conditions):
|
||||
tasks[RESTRICTIONS_UNIVERSAL] = (
|
||||
self.client.restrictions.universal())
|
||||
|
||||
results = await asyncio.gather(*tasks.values(), return_exceptions=True)
|
||||
for operation, result in zip(tasks, results):
|
||||
|
||||
Reference in new issue
Block a user