Add flow rate sensor to acaia (#131254)

pull/131271/head
Josef Zweck 2024-11-22 13:26:16 +01:00 committed by GitHub
parent 430a47138a
commit ce46bac245
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 64 additions and 1 deletions

View File

@ -14,7 +14,7 @@ from homeassistant.components.sensor import (
SensorExtraStoredData,
SensorStateClass,
)
from homeassistant.const import PERCENTAGE, UnitOfMass
from homeassistant.const import PERCENTAGE, UnitOfMass, UnitOfVolumeFlowRate
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -49,6 +49,14 @@ SENSORS: tuple[AcaiaSensorEntityDescription, ...] = (
),
value_fn=lambda scale: scale.weight,
),
AcaiaDynamicUnitSensorEntityDescription(
key="flow_rate",
device_class=SensorDeviceClass.VOLUME_FLOW_RATE,
native_unit_of_measurement=UnitOfVolumeFlowRate.MILLILITERS_PER_SECOND,
suggested_display_precision=1,
state_class=SensorStateClass.MEASUREMENT,
value_fn=lambda scale: scale.flow_rate,
),
)
RESTORE_SENSORS: tuple[AcaiaSensorEntityDescription, ...] = (
AcaiaSensorEntityDescription(

View File

@ -80,4 +80,5 @@ def mock_scale() -> Generator[MagicMock]:
)
scale.weight = 123.45
scale.timer = 23
scale.flow_rate = 1.23
yield scale

View File

@ -50,6 +50,60 @@
'state': '42',
})
# ---
# name: test_sensors[sensor.lunar_ddeeff_volume_flow_rate-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
}),
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': None,
'entity_id': 'sensor.lunar_ddeeff_volume_flow_rate',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
'sensor': dict({
'suggested_display_precision': 1,
}),
}),
'original_device_class': <SensorDeviceClass.VOLUME_FLOW_RATE: 'volume_flow_rate'>,
'original_icon': None,
'original_name': 'Volume flow rate',
'platform': 'acaia',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': None,
'unique_id': 'aa:bb:cc:dd:ee:ff_flow_rate',
'unit_of_measurement': <UnitOfVolumeFlowRate.MILLILITERS_PER_SECOND: 'mL/s'>,
})
# ---
# name: test_sensors[sensor.lunar_ddeeff_volume_flow_rate-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'volume_flow_rate',
'friendly_name': 'LUNAR-DDEEFF Volume flow rate',
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
'unit_of_measurement': <UnitOfVolumeFlowRate.MILLILITERS_PER_SECOND: 'mL/s'>,
}),
'context': <ANY>,
'entity_id': 'sensor.lunar_ddeeff_volume_flow_rate',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '1.23',
})
# ---
# name: test_sensors[sensor.lunar_ddeeff_weight-entry]
EntityRegistryEntrySnapshot({
'aliases': set({