Skip to content

Commit

Permalink
Add valve state sensor.
Browse files Browse the repository at this point in the history
Product name: ecoMAX 860P6-O
Product type: 0
Product ID: 51
Related key: 139

Related to: #54
  • Loading branch information
denpamusic committed Dec 13, 2023
1 parent eccb980 commit 154093a
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 1 deletion.
18 changes: 17 additions & 1 deletion custom_components/plum_ecomax/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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),
),
)


Expand Down
9 changes: 9 additions & 0 deletions custom_components/plum_ecomax/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
9 changes: 9 additions & 0 deletions custom_components/plum_ecomax/translations/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
9 changes: 9 additions & 0 deletions custom_components/plum_ecomax/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
9 changes: 9 additions & 0 deletions custom_components/plum_ecomax/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
9 changes: 9 additions & 0 deletions custom_components/plum_ecomax/translations/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
9 changes: 9 additions & 0 deletions custom_components/plum_ecomax/translations/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
9 changes: 9 additions & 0 deletions custom_components/plum_ecomax/translations/ua.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
31 changes: 31 additions & 0 deletions tests/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
ATTR_UNIT_OF_MEASUREMENT,
EVENT_HOMEASSISTANT_START,
PERCENTAGE,
STATE_OFF,
UnitOfMass,
UnitOfPower,
UnitOfTemperature,
Expand Down Expand Up @@ -72,6 +73,7 @@
from custom_components.plum_ecomax.sensor import (
SERVICE_CALIBRATE_METER,
SERVICE_RESET_METER,
STATE_CLOSING,
)


Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 154093a

Please sign in to comment.