mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 09:47:52 +00:00
Add profile duration sensor for Vallox integration (#120240)
This commit is contained in:
parent
862cd76f89
commit
30a3e9af2b
@ -18,6 +18,7 @@ from homeassistant.const import (
|
||||
REVOLUTIONS_PER_MINUTE,
|
||||
EntityCategory,
|
||||
UnitOfTemperature,
|
||||
UnitOfTime,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
@ -127,6 +128,18 @@ class ValloxCellStateSensor(ValloxSensorEntity):
|
||||
return VALLOX_CELL_STATE_TO_STR.get(super_native_value)
|
||||
|
||||
|
||||
class ValloxProfileDurationSensor(ValloxSensorEntity):
|
||||
"""Child class for profile duration reporting."""
|
||||
|
||||
@property
|
||||
def native_value(self) -> StateType:
|
||||
"""Return the value reported by the sensor."""
|
||||
|
||||
return self.coordinator.data.get_remaining_profile_duration(
|
||||
self.coordinator.data.profile
|
||||
)
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class ValloxSensorEntityDescription(SensorEntityDescription):
|
||||
"""Describes Vallox sensor entity."""
|
||||
@ -253,6 +266,14 @@ SENSOR_ENTITIES: tuple[ValloxSensorEntityDescription, ...] = (
|
||||
native_unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION,
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
ValloxSensorEntityDescription(
|
||||
key="profile_duration",
|
||||
translation_key="profile_duration",
|
||||
device_class=SensorDeviceClass.DURATION,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
native_unit_of_measurement=UnitOfTime.MINUTES,
|
||||
entity_type=ValloxProfileDurationSensor,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
|
@ -87,6 +87,9 @@
|
||||
},
|
||||
"efficiency": {
|
||||
"name": "Efficiency"
|
||||
},
|
||||
"profile_duration": {
|
||||
"name": "Profile duration"
|
||||
}
|
||||
},
|
||||
"switch": {
|
||||
|
@ -112,9 +112,9 @@ def default_metrics():
|
||||
"A_CYC_UUID5": 10,
|
||||
"A_CYC_UUID6": 11,
|
||||
"A_CYC_UUID7": 12,
|
||||
"A_CYC_BOOST_TIMER": 30,
|
||||
"A_CYC_FIREPLACE_TIMER": 30,
|
||||
"A_CYC_EXTRA_TIMER": 30,
|
||||
"A_CYC_BOOST_TIMER": 0,
|
||||
"A_CYC_FIREPLACE_TIMER": 0,
|
||||
"A_CYC_EXTRA_TIMER": 0,
|
||||
"A_CYC_MODE": 0,
|
||||
"A_CYC_STATE": 0,
|
||||
"A_CYC_FILTER_CHANGED_YEAR": 24,
|
||||
|
@ -135,3 +135,48 @@ async def test_cell_state_sensor(
|
||||
# Assert
|
||||
sensor = hass.states.get("sensor.vallox_cell_state")
|
||||
assert sensor.state == expected_state
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("metrics", "expected_state"),
|
||||
[
|
||||
(
|
||||
{"A_CYC_STATE": 0},
|
||||
"unknown",
|
||||
),
|
||||
(
|
||||
{"A_CYC_STATE": 1},
|
||||
"unknown",
|
||||
),
|
||||
(
|
||||
{"A_CYC_EXTRA_TIMER": 10},
|
||||
"10",
|
||||
),
|
||||
(
|
||||
{"A_CYC_FIREPLACE_TIMER": 9},
|
||||
"9",
|
||||
),
|
||||
(
|
||||
{"A_CYC_BOOST_TIMER": 8},
|
||||
"8",
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_profile_duration_sensor(
|
||||
metrics,
|
||||
expected_state,
|
||||
mock_entry: MockConfigEntry,
|
||||
hass: HomeAssistant,
|
||||
setup_fetch_metric_data_mock,
|
||||
) -> None:
|
||||
"""Test profile sensor in different states."""
|
||||
# Arrange
|
||||
setup_fetch_metric_data_mock(metrics=metrics)
|
||||
|
||||
# Act
|
||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
# Assert
|
||||
sensor = hass.states.get("sensor.vallox_profile_duration")
|
||||
assert sensor.state == expected_state
|
||||
|
Loading…
x
Reference in New Issue
Block a user