mirror of
https://github.com/elisspace/core.git
synced 2026-08-29 15:43:55 +00:00
Make Ohmpilot entity state translateable
This commit is contained in:
@@ -96,3 +96,30 @@ def get_meter_location_description(code: StateType) -> MeterLocationCodeOption |
|
||||
case _ as _code if 256 <= _code <= 511:
|
||||
return MeterLocationCodeOption.SUBLOAD
|
||||
return None
|
||||
|
||||
|
||||
class OhmPilotStateCodeOption(StrEnum):
|
||||
"""OhmPilot state codes for Fronius inverters."""
|
||||
|
||||
# these are keys for state translations - so snake_case is used
|
||||
UP_AND_RUNNING = "up_and_running"
|
||||
KEEP_MINIMUM_TEMPERATURE = "keep_minimum_temperature"
|
||||
LEGIONELLA_PROTECTION = "legionella_protection"
|
||||
CRITICAL_FAULT = "critical_fault"
|
||||
FAULT = "fault"
|
||||
BOOST_MODE = "boost_mode"
|
||||
|
||||
|
||||
_OHMPILOT_STATE_CODES: Final[dict[int, OhmPilotStateCodeOption]] = {
|
||||
0: OhmPilotStateCodeOption.UP_AND_RUNNING,
|
||||
1: OhmPilotStateCodeOption.KEEP_MINIMUM_TEMPERATURE,
|
||||
2: OhmPilotStateCodeOption.LEGIONELLA_PROTECTION,
|
||||
3: OhmPilotStateCodeOption.CRITICAL_FAULT,
|
||||
4: OhmPilotStateCodeOption.FAULT,
|
||||
5: OhmPilotStateCodeOption.BOOST_MODE,
|
||||
}
|
||||
|
||||
|
||||
def get_ohmpilot_state_message(code: StateType) -> OhmPilotStateCodeOption | None:
|
||||
"""Return a status message for a given status code."""
|
||||
return _OHMPILOT_STATE_CODES.get(code) # type: ignore[arg-type]
|
||||
|
||||
@@ -34,8 +34,10 @@ from .const import (
|
||||
DOMAIN,
|
||||
InverterStatusCodeOption,
|
||||
MeterLocationCodeOption,
|
||||
OhmPilotStateCodeOption,
|
||||
get_inverter_status_message,
|
||||
get_meter_location_description,
|
||||
get_ohmpilot_state_message,
|
||||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -496,7 +498,11 @@ OHMPILOT_ENTITY_DESCRIPTIONS: list[FroniusSensorEntityDescription] = [
|
||||
),
|
||||
FroniusSensorEntityDescription(
|
||||
key="state_message",
|
||||
response_key="state_code",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
device_class=SensorDeviceClass.ENUM,
|
||||
options=[opt.value for opt in OhmPilotStateCodeOption],
|
||||
value_fn=get_ohmpilot_state_message,
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
@@ -218,7 +218,15 @@
|
||||
"name": "State code"
|
||||
},
|
||||
"state_message": {
|
||||
"name": "State message"
|
||||
"name": "State message",
|
||||
"state": {
|
||||
"up_and_running": "Up and running",
|
||||
"keep_minimum_temperature": "Keep minimum temperature",
|
||||
"legionella_protection": "Legionella protection",
|
||||
"critical_fault": "Critical fault",
|
||||
"fault": "Fault",
|
||||
"boost_mode": "Boost mode"
|
||||
}
|
||||
},
|
||||
"meter_mode": {
|
||||
"name": "Meter mode"
|
||||
|
||||
@@ -360,7 +360,7 @@ async def test_gen24_storage(
|
||||
assert_state("sensor.ohmpilot_power", 0.0)
|
||||
assert_state("sensor.ohmpilot_temperature", 38.9)
|
||||
assert_state("sensor.ohmpilot_state_code", 0.0)
|
||||
assert_state("sensor.ohmpilot_state_message", "Up and running")
|
||||
assert_state("sensor.ohmpilot_state_message", "up_and_running")
|
||||
# power_flow
|
||||
assert_state("sensor.solarnet_power_grid", 2274.9)
|
||||
assert_state("sensor.solarnet_power_battery", 0.1591)
|
||||
|
||||
Reference in New Issue
Block a user