Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions homeassistant/components/pooldose/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@

from __future__ import annotations

from homeassistant.const import UnitOfTemperature, UnitOfVolumeFlowRate
from homeassistant.const import UnitOfTemperature, UnitOfVolume, UnitOfVolumeFlowRate

DOMAIN = "pooldose"
MANUFACTURER = "SEKO"

# Mapping of device units to Home Assistant units
# Mapping of device units (upper case) to Home Assistant units
UNIT_MAPPING: dict[str, str] = {
# Temperature units
"°C": UnitOfTemperature.CELSIUS,
"°F": UnitOfTemperature.FAHRENHEIT,
# Volume flow rate units
"m3/h": UnitOfVolumeFlowRate.CUBIC_METERS_PER_HOUR,
"L/s": UnitOfVolumeFlowRate.LITERS_PER_SECOND,
"M3/H": UnitOfVolumeFlowRate.CUBIC_METERS_PER_HOUR,
"L/S": UnitOfVolumeFlowRate.LITERS_PER_SECOND,
# Volume units
"L": UnitOfVolume.LITERS,
"M3": UnitOfVolume.CUBIC_METERS,
}
3 changes: 3 additions & 0 deletions homeassistant/components/pooldose/icons.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@
},
"ph_type_dosing": {
"default": "mdi:beaker"
},
"water_meter_total_permanent": {
"default": "mdi:counter"
}
},
"switch": {
Expand Down
12 changes: 10 additions & 2 deletions homeassistant/components/pooldose/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
SensorDeviceClass,
SensorEntity,
SensorEntityDescription,
SensorStateClass,
)
from homeassistant.const import (
CONCENTRATION_PARTS_PER_MILLION,
Expand Down Expand Up @@ -58,6 +59,13 @@ class PooldoseSensorEntityDescription(SensorEntityDescription):
device_class=SensorDeviceClass.VOLUME_FLOW_RATE,
use_dynamic_unit=True,
),
PooldoseSensorEntityDescription(
key="water_meter_total_permanent",
Comment thread
lmaertin marked this conversation as resolved.
translation_key="water_meter_total_permanent",
device_class=SensorDeviceClass.VOLUME,
state_class=SensorStateClass.TOTAL_INCREASING,
use_dynamic_unit=True,
),
PooldoseSensorEntityDescription(
key="ph_type_dosing",
translation_key="ph_type_dosing",
Expand Down Expand Up @@ -223,8 +231,8 @@ def native_unit_of_measurement(self) -> str | None:
and (data := self.get_data()) is not None
and (device_unit := data.get("unit"))
):
# Map device unit to Home Assistant unit, return None if unknown
return UNIT_MAPPING.get(device_unit)
# Map device unit (upper case) to Home Assistant unit, return None if unknown
return UNIT_MAPPING.get(device_unit.upper())

# Fall back to static unit from entity description
return super().native_unit_of_measurement
3 changes: 3 additions & 0 deletions homeassistant/components/pooldose/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@
"acid": "pH-",
"alcalyne": "pH+"
}
},
"water_meter_total_permanent": {
"name": "Totalizer"
}
},
"switch": {
Expand Down
10 changes: 9 additions & 1 deletion tests/components/pooldose/fixtures/instantvalues.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"flow_rate": {
"value": 150,
"unit": "L/s"
"unit": "l/s"
},
"ph_type_dosing": {
"value": "alcalyne",
Expand Down Expand Up @@ -75,6 +75,14 @@
"orp_calibration_slope": {
"value": 0.96,
"unit": "mV"
},
"water_meter_total_permanent": {
"value": 12345.67,
"unit": "m3"
},
"water_meter_total_resettable": {
"value": 123.45,
"unit": "m3"
}
},
"binary_sensor": {
Expand Down
56 changes: 56 additions & 0 deletions tests/components/pooldose/snapshots/test_sensor.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -1054,3 +1054,59 @@
'state': '25',
})
# ---
# name: test_all_sensors[sensor.pool_device_totalizer-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'state_class': <SensorStateClass.TOTAL_INCREASING: 'total_increasing'>,
}),
'config_entry_id': <ANY>,
'config_subentry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': None,
'entity_id': 'sensor.pool_device_totalizer',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
'sensor': dict({
'suggested_display_precision': 2,
}),
}),
'original_device_class': <SensorDeviceClass.VOLUME: 'volume'>,
'original_icon': None,
'original_name': 'Totalizer',
'platform': 'pooldose',
'previous_unique_id': None,
'suggested_object_id': None,
'supported_features': 0,
'translation_key': 'water_meter_total_permanent',
'unique_id': 'TEST123456789_water_meter_total_permanent',
'unit_of_measurement': <UnitOfVolume.CUBIC_METERS: 'm³'>,
})
# ---
# name: test_all_sensors[sensor.pool_device_totalizer-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'volume',
'friendly_name': 'Pool Device Totalizer',
'state_class': <SensorStateClass.TOTAL_INCREASING: 'total_increasing'>,
'unit_of_measurement': <UnitOfVolume.CUBIC_METERS: 'm³'>,
}),
'context': <ANY>,
'entity_id': 'sensor.pool_device_totalizer',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '12345.67',
})
# ---
Loading