Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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,
}
6 changes: 6 additions & 0 deletions homeassistant/components/pooldose/icons.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@
},
"ph_type_dosing": {
"default": "mdi:beaker"
},
"water_meter_total_permanent": {
"default": "mdi:counter"
},
"water_meter_total_resettable": {
"default": "mdi:counter"
}
},
"switch": {
Expand Down
17 changes: 15 additions & 2 deletions homeassistant/components/pooldose/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ 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,
use_dynamic_unit=True,
),
PooldoseSensorEntityDescription(
key="water_meter_total_resettable",
translation_key="water_meter_total_resettable",
entity_registry_enabled_default=False,
device_class=SensorDeviceClass.VOLUME,
use_dynamic_unit=True,
),
PooldoseSensorEntityDescription(
key="ph_type_dosing",
translation_key="ph_type_dosing",
Expand Down Expand Up @@ -223,8 +236,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
6 changes: 6 additions & 0 deletions homeassistant/components/pooldose/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@
"acid": "pH-",
"alcalyne": "pH+"
}
},
"water_meter_total_permanent": {
"name": "Water meter total"
},
"water_meter_total_resettable": {
"name": "Water meter resettable"
}
},
"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
106 changes: 106 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,109 @@
'state': '25',
})
# ---
# name: test_all_sensors[sensor.pool_device_water_meter_resettable-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'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_water_meter_resettable',
'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': 'Water meter resettable',
'platform': 'pooldose',
'previous_unique_id': None,
'suggested_object_id': None,
'supported_features': 0,
'translation_key': 'water_meter_total_resettable',
'unique_id': 'TEST123456789_water_meter_total_resettable',
'unit_of_measurement': <UnitOfVolume.CUBIC_METERS: 'm³'>,
})
# ---
# name: test_all_sensors[sensor.pool_device_water_meter_resettable-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'volume',
'friendly_name': 'Pool Device Water meter resettable',
'unit_of_measurement': <UnitOfVolume.CUBIC_METERS: 'm³'>,
}),
'context': <ANY>,
'entity_id': 'sensor.pool_device_water_meter_resettable',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '123.45',
})
# ---
# name: test_all_sensors[sensor.pool_device_water_meter_total-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'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_water_meter_total',
'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': 'Water meter total',
'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_water_meter_total-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'volume',
'friendly_name': 'Pool Device Water meter total',
'unit_of_measurement': <UnitOfVolume.CUBIC_METERS: 'm³'>,
}),
'context': <ANY>,
'entity_id': 'sensor.pool_device_water_meter_total',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '12345.67',
})
# ---
Loading