Skip to content

Commit fe85eaf

Browse files
authored
Pooldose: Add sensors for water meter (home-assistant#157382)
1 parent 3551c4b commit fe85eaf

File tree

6 files changed

+88
-7
lines changed

6 files changed

+88
-7
lines changed

homeassistant/components/pooldose/const.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,20 @@
22

33
from __future__ import annotations
44

5-
from homeassistant.const import UnitOfTemperature, UnitOfVolumeFlowRate
5+
from homeassistant.const import UnitOfTemperature, UnitOfVolume, UnitOfVolumeFlowRate
66

77
DOMAIN = "pooldose"
88
MANUFACTURER = "SEKO"
99

10-
# Mapping of device units to Home Assistant units
10+
# Mapping of device units (upper case) to Home Assistant units
1111
UNIT_MAPPING: dict[str, str] = {
1212
# Temperature units
1313
"°C": UnitOfTemperature.CELSIUS,
1414
"°F": UnitOfTemperature.FAHRENHEIT,
1515
# Volume flow rate units
16-
"m3/h": UnitOfVolumeFlowRate.CUBIC_METERS_PER_HOUR,
17-
"L/s": UnitOfVolumeFlowRate.LITERS_PER_SECOND,
16+
"M3/H": UnitOfVolumeFlowRate.CUBIC_METERS_PER_HOUR,
17+
"L/S": UnitOfVolumeFlowRate.LITERS_PER_SECOND,
18+
# Volume units
19+
"L": UnitOfVolume.LITERS,
20+
"M3": UnitOfVolume.CUBIC_METERS,
1821
}

homeassistant/components/pooldose/icons.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@
119119
},
120120
"ph_type_dosing": {
121121
"default": "mdi:beaker"
122+
},
123+
"water_meter_total_permanent": {
124+
"default": "mdi:counter"
122125
}
123126
},
124127
"switch": {

homeassistant/components/pooldose/sensor.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
SensorDeviceClass,
1111
SensorEntity,
1212
SensorEntityDescription,
13+
SensorStateClass,
1314
)
1415
from homeassistant.const import (
1516
CONCENTRATION_PARTS_PER_MILLION,
@@ -58,6 +59,13 @@ class PooldoseSensorEntityDescription(SensorEntityDescription):
5859
device_class=SensorDeviceClass.VOLUME_FLOW_RATE,
5960
use_dynamic_unit=True,
6061
),
62+
PooldoseSensorEntityDescription(
63+
key="water_meter_total_permanent",
64+
translation_key="water_meter_total_permanent",
65+
device_class=SensorDeviceClass.VOLUME,
66+
state_class=SensorStateClass.TOTAL_INCREASING,
67+
use_dynamic_unit=True,
68+
),
6169
PooldoseSensorEntityDescription(
6270
key="ph_type_dosing",
6371
translation_key="ph_type_dosing",
@@ -223,8 +231,8 @@ def native_unit_of_measurement(self) -> str | None:
223231
and (data := self.get_data()) is not None
224232
and (device_unit := data.get("unit"))
225233
):
226-
# Map device unit to Home Assistant unit, return None if unknown
227-
return UNIT_MAPPING.get(device_unit)
234+
# Map device unit (upper case) to Home Assistant unit, return None if unknown
235+
return UNIT_MAPPING.get(device_unit.upper())
228236

229237
# Fall back to static unit from entity description
230238
return super().native_unit_of_measurement

homeassistant/components/pooldose/strings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@
160160
"acid": "pH-",
161161
"alcalyne": "pH+"
162162
}
163+
},
164+
"water_meter_total_permanent": {
165+
"name": "Totalizer"
163166
}
164167
},
165168
"switch": {

tests/components/pooldose/fixtures/instantvalues.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
},
1919
"flow_rate": {
2020
"value": 150,
21-
"unit": "L/s"
21+
"unit": "l/s"
2222
},
2323
"ph_type_dosing": {
2424
"value": "alcalyne",
@@ -75,6 +75,14 @@
7575
"orp_calibration_slope": {
7676
"value": 0.96,
7777
"unit": "mV"
78+
},
79+
"water_meter_total_permanent": {
80+
"value": 12345.67,
81+
"unit": "m3"
82+
},
83+
"water_meter_total_resettable": {
84+
"value": 123.45,
85+
"unit": "m3"
7886
}
7987
},
8088
"binary_sensor": {

tests/components/pooldose/snapshots/test_sensor.ambr

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,3 +1054,59 @@
10541054
'state': '25',
10551055
})
10561056
# ---
1057+
# name: test_all_sensors[sensor.pool_device_totalizer-entry]
1058+
EntityRegistryEntrySnapshot({
1059+
'aliases': set({
1060+
}),
1061+
'area_id': None,
1062+
'capabilities': dict({
1063+
'state_class': <SensorStateClass.TOTAL_INCREASING: 'total_increasing'>,
1064+
}),
1065+
'config_entry_id': <ANY>,
1066+
'config_subentry_id': <ANY>,
1067+
'device_class': None,
1068+
'device_id': <ANY>,
1069+
'disabled_by': None,
1070+
'domain': 'sensor',
1071+
'entity_category': None,
1072+
'entity_id': 'sensor.pool_device_totalizer',
1073+
'has_entity_name': True,
1074+
'hidden_by': None,
1075+
'icon': None,
1076+
'id': <ANY>,
1077+
'labels': set({
1078+
}),
1079+
'name': None,
1080+
'options': dict({
1081+
'sensor': dict({
1082+
'suggested_display_precision': 2,
1083+
}),
1084+
}),
1085+
'original_device_class': <SensorDeviceClass.VOLUME: 'volume'>,
1086+
'original_icon': None,
1087+
'original_name': 'Totalizer',
1088+
'platform': 'pooldose',
1089+
'previous_unique_id': None,
1090+
'suggested_object_id': None,
1091+
'supported_features': 0,
1092+
'translation_key': 'water_meter_total_permanent',
1093+
'unique_id': 'TEST123456789_water_meter_total_permanent',
1094+
'unit_of_measurement': <UnitOfVolume.CUBIC_METERS: 'm³'>,
1095+
})
1096+
# ---
1097+
# name: test_all_sensors[sensor.pool_device_totalizer-state]
1098+
StateSnapshot({
1099+
'attributes': ReadOnlyDict({
1100+
'device_class': 'volume',
1101+
'friendly_name': 'Pool Device Totalizer',
1102+
'state_class': <SensorStateClass.TOTAL_INCREASING: 'total_increasing'>,
1103+
'unit_of_measurement': <UnitOfVolume.CUBIC_METERS: 'm³'>,
1104+
}),
1105+
'context': <ANY>,
1106+
'entity_id': 'sensor.pool_device_totalizer',
1107+
'last_changed': <ANY>,
1108+
'last_reported': <ANY>,
1109+
'last_updated': <ANY>,
1110+
'state': '12345.67',
1111+
})
1112+
# ---

0 commit comments

Comments
 (0)