From 154093a4c8eb6905ee17b77c4bf5cf5dddc235b4 Mon Sep 17 00:00:00 2001 From: denpamusic Date: Wed, 13 Dec 2023 20:43:43 +0300 Subject: [PATCH] Add valve state sensor. Product name: ecoMAX 860P6-O Product type: 0 Product ID: 51 Related key: 139 Related to: #54 --- custom_components/plum_ecomax/sensor.py | 18 ++++++++++- custom_components/plum_ecomax/strings.json | 9 ++++++ .../plum_ecomax/translations/cs.json | 9 ++++++ .../plum_ecomax/translations/en.json | 9 ++++++ .../plum_ecomax/translations/fr.json | 9 ++++++ .../plum_ecomax/translations/pl.json | 9 ++++++ .../plum_ecomax/translations/ru.json | 9 ++++++ .../plum_ecomax/translations/ua.json | 9 ++++++ tests/test_sensor.py | 31 +++++++++++++++++++ 9 files changed, 111 insertions(+), 1 deletion(-) diff --git a/custom_components/plum_ecomax/sensor.py b/custom_components/plum_ecomax/sensor.py index f0951ce..694bdbd 100644 --- a/custom_components/plum_ecomax/sensor.py +++ b/custom_components/plum_ecomax/sensor.py @@ -143,7 +143,7 @@ class EcomaxSensorEntityDescription(SensorEntityDescription): key="state", translation_key="ecomax_state", device_class=DEVICE_CLASS_STATE, - value_fn=lambda x: EM_TO_HA_STATE[x] if x in EM_TO_HA_STATE else STATE_UNKNOWN, + value_fn=lambda x: EM_TO_HA_STATE.get(x, STATE_UNKNOWN), ), EcomaxSensorEntityDescription( key="password", @@ -500,6 +500,15 @@ class RegdataSensorEntityDescription(EcomaxSensorEntityDescription): product_models: set[ProductModel] +STATE_CLOSING: Final = "closing" +STATE_OPENING: Final = "opening" + +EM_TO_HA_MIXER_VALVE_STATE: dict[int, str] = { + 0: STATE_OFF, + 1: STATE_CLOSING, + 2: STATE_OPENING, +} + REGDATA_SENSOR_TYPES: tuple[RegdataSensorEntityDescription, ...] = ( RegdataSensorEntityDescription( key=227, @@ -530,6 +539,13 @@ class RegdataSensorEntityDescription(EcomaxSensorEntityDescription): suggested_display_precision=0, value_fn=lambda x: x, ), + RegdataSensorEntityDescription( + key=139, + translation_key="mixer_valve_state", + product_models={ProductModel.ECOMAX_860P6_O}, + device_class=DEVICE_CLASS_STATE, + value_fn=lambda x: EM_TO_HA_MIXER_VALVE_STATE.get(x, STATE_UNKNOWN), + ), ) diff --git a/custom_components/plum_ecomax/strings.json b/custom_components/plum_ecomax/strings.json index 307322b..2bd792f 100644 --- a/custom_components/plum_ecomax/strings.json +++ b/custom_components/plum_ecomax/strings.json @@ -163,6 +163,15 @@ "mixer_temp": { "name": "Mixer temperature" }, "mixer_target_temp": { "name": "Mixer target temperature" }, "mixer_valve_opening_percentage": { "name": "Mixer valve opening percentage" }, + "mixer_valve_state": { + "name": "Mixer valve state", + "state": { + "off": "[%key:common::state::off%]", + "closing": "Closing", + "opening": "Opening", + "unknown": "Unknown" + } + }, "circuit_temp": { "name": "Circuit temperature" }, "circuit_target_temp": { "name": "Circuit target temperature" }, "total_fuel_burned": { diff --git a/custom_components/plum_ecomax/translations/cs.json b/custom_components/plum_ecomax/translations/cs.json index 7424850..1478f58 100644 --- a/custom_components/plum_ecomax/translations/cs.json +++ b/custom_components/plum_ecomax/translations/cs.json @@ -163,6 +163,15 @@ "mixer_temp": { "name": "Mixer temperature" }, "mixer_target_temp": { "name": "Mixer target temperature" }, "mixer_valve_opening_percentage": { "name": "Mixer valve opening percentage" }, + "mixer_valve_state": { + "name": "Mixer valve state", + "state": { + "off": "Off", + "closing": "Closing", + "opening": "Opening", + "unknown": "Unknown" + } + }, "circuit_temp": { "name": "Circuit temperature" }, "circuit_target_temp": { "name": "Circuit target temperature" }, "total_fuel_burned": { diff --git a/custom_components/plum_ecomax/translations/en.json b/custom_components/plum_ecomax/translations/en.json index 6168d6f..db8e81e 100644 --- a/custom_components/plum_ecomax/translations/en.json +++ b/custom_components/plum_ecomax/translations/en.json @@ -163,6 +163,15 @@ "mixer_temp": { "name": "Mixer temperature" }, "mixer_target_temp": { "name": "Mixer target temperature" }, "mixer_valve_opening_percentage": { "name": "Mixer valve opening percentage" }, + "mixer_valve_state": { + "name": "Mixer valve state", + "state": { + "off": "Off", + "closing": "Closing", + "opening": "Opening", + "unknown": "Unknown" + } + }, "circuit_temp": { "name": "Circuit temperature" }, "circuit_target_temp": { "name": "Circuit target temperature" }, "total_fuel_burned": { diff --git a/custom_components/plum_ecomax/translations/fr.json b/custom_components/plum_ecomax/translations/fr.json index 7ccaa14..fb9e3ad 100644 --- a/custom_components/plum_ecomax/translations/fr.json +++ b/custom_components/plum_ecomax/translations/fr.json @@ -163,6 +163,15 @@ "mixer_temp": { "name": "Mixer temperature" }, "mixer_target_temp": { "name": "Mixer target temperature" }, "mixer_valve_opening_percentage": { "name": "Mixer valve opening percentage" }, + "mixer_valve_state": { + "name": "Mixer valve state", + "state": { + "off": "Off", + "closing": "Closing", + "opening": "Opening", + "unknown": "Unknown" + } + }, "circuit_temp": { "name": "Circuit temperature" }, "circuit_target_temp": { "name": "Circuit target temperature" }, "total_fuel_burned": { diff --git a/custom_components/plum_ecomax/translations/pl.json b/custom_components/plum_ecomax/translations/pl.json index f6ea9a7..23b2823 100644 --- a/custom_components/plum_ecomax/translations/pl.json +++ b/custom_components/plum_ecomax/translations/pl.json @@ -163,6 +163,15 @@ "mixer_temp": { "name": "Temperatura mieszacza" }, "mixer_target_temp": { "name": "Temperatura zadana mieszacza" }, "mixer_valve_opening_percentage": { "name": "Otwarcie zaworu mieszacza" }, + "mixer_valve_state": { + "name": "Status zaworu", + "state": { + "off": "Nie działa", + "closing": "Zamykanie", + "opening": "Otwieranie", + "unknown": "Nieznany" + } + }, "circuit_temp": { "name": "Temperatura obiegu" }, "circuit_target_temp": { "name": "Temperatura zadana obiegu" }, "total_fuel_burned": { diff --git a/custom_components/plum_ecomax/translations/ru.json b/custom_components/plum_ecomax/translations/ru.json index cc4ad80..3f17857 100644 --- a/custom_components/plum_ecomax/translations/ru.json +++ b/custom_components/plum_ecomax/translations/ru.json @@ -163,6 +163,15 @@ "mixer_temp": { "name": "Температура миксера" }, "mixer_target_temp": { "name": "Заданная температура миксера" }, "mixer_valve_opening_percentage": { "name": "Mixer valve opening percentage" }, + "mixer_valve_state": { + "name": "Mixer valve state", + "state": { + "off": "Off", + "closing": "Closing", + "opening": "Opening", + "unknown": "Unknown" + } + }, "circuit_temp": { "name": "Температура контура" }, "circuit_target_temp": { "name": "Заданная температура контура" }, "total_fuel_burned": { diff --git a/custom_components/plum_ecomax/translations/ua.json b/custom_components/plum_ecomax/translations/ua.json index a77861a..b031646 100644 --- a/custom_components/plum_ecomax/translations/ua.json +++ b/custom_components/plum_ecomax/translations/ua.json @@ -163,6 +163,15 @@ "mixer_temp": { "name": "Mixer temperature" }, "mixer_target_temp": { "name": "Mixer target temperature" }, "mixer_valve_opening_percentage": { "name": "Mixer valve opening percentage" }, + "mixer_valve_state": { + "name": "Mixer valve state", + "state": { + "off": "Off", + "closing": "Closing", + "opening": "Opening", + "unknown": "Unknown" + } + }, "circuit_temp": { "name": "Circuit temperature" }, "circuit_target_temp": { "name": "Circuit target temperature" }, "total_fuel_burned": { diff --git a/tests/test_sensor.py b/tests/test_sensor.py index 4427319..90b355e 100644 --- a/tests/test_sensor.py +++ b/tests/test_sensor.py @@ -17,6 +17,7 @@ ATTR_UNIT_OF_MEASUREMENT, EVENT_HOMEASSISTANT_START, PERCENTAGE, + STATE_OFF, UnitOfMass, UnitOfPower, UnitOfTemperature, @@ -72,6 +73,7 @@ from custom_components.plum_ecomax.sensor import ( SERVICE_CALIBRATE_METER, SERVICE_RESET_METER, + STATE_CLOSING, ) @@ -1265,6 +1267,35 @@ async def test_mixer_valve_opening_percentage_sensor_ecomax_860p6_o( assert state.state == "55" +@pytest.mark.usefixtures("ecomax_860p6_o") +async def test_mixer_valve_state_sensor_ecomax_860p6_o( + hass: HomeAssistant, + connection: EcomaxConnection, + config_entry: MockConfigEntry, + setup_integration, +) -> None: + """Test mixer valve state sensor for ecoMAX 860P6-O.""" + await setup_integration(hass, config_entry) + mixer_valve_state_entity_id = "sensor.ecomax_mixer_valve_state" + mixer_valve_state_key = 139 + + # Check entry. + entity_registry = er.async_get(hass) + entry = entity_registry.async_get(mixer_valve_state_entity_id) + assert entry + assert entry.translation_key == "mixer_valve_state" + + # Get initial value. + state = hass.states.get(mixer_valve_state_entity_id) + assert state.state == STATE_OFF + assert state.attributes[ATTR_FRIENDLY_NAME] == "ecoMAX Mixer valve state" + + # Dispatch new value. + await connection.device.dispatch(ATTR_REGDATA, {mixer_valve_state_key: 1}) + state = hass.states.get(mixer_valve_state_entity_id) + assert state.state == STATE_CLOSING + + @pytest.mark.usefixtures("ecomax_860p3_s_lite") async def test_ash_pan_full_sensor_ecomax_860p3_s_lite( hass: HomeAssistant,