Replace slave by meter in v2c ()

This commit is contained in:
Robert Resch 2024-06-05 18:21:03 +02:00 committed by GitHub
parent e2dd88be6e
commit 0562c3085f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 20 additions and 15 deletions
homeassistant/components/v2c
tests/components/v2c

View file

@ -16,7 +16,7 @@
"fv_power": {
"default": "mdi:solar-power-variant"
},
"slave_error": {
"meter_error": {
"default": "mdi:alert"
},
"battery_power": {

View file

@ -35,7 +35,12 @@ class V2CSensorEntityDescription(SensorEntityDescription):
value_fn: Callable[[TrydanData], StateType]
_METER_ERROR_OPTIONS = [error.name.lower() for error in SlaveCommunicationState]
def get_meter_value(value: SlaveCommunicationState) -> str:
"""Return the value of the enum and replace slave by meter."""
return value.name.lower().replace("slave", "meter")
_METER_ERROR_OPTIONS = [get_meter_value(error) for error in SlaveCommunicationState]
TRYDAN_SENSORS = (
V2CSensorEntityDescription(
@ -82,7 +87,7 @@ TRYDAN_SENSORS = (
V2CSensorEntityDescription(
key="meter_error",
translation_key="meter_error",
value_fn=lambda evse_data: evse_data.slave_error.name.lower(),
value_fn=lambda evse_data: get_meter_value(evse_data.slave_error),
entity_registry_enabled_default=False,
device_class=SensorDeviceClass.ENUM,
options=_METER_ERROR_OPTIONS,

View file

@ -60,12 +60,12 @@
"no_error": "No error",
"communication": "Communication",
"reading": "Reading",
"slave": "Meter",
"meter": "Meter",
"waiting_wifi": "Waiting for Wi-Fi",
"waiting_communication": "Waiting communication",
"wrong_ip": "Wrong IP",
"slave_not_found": "Meter not found",
"wrong_slave": "Wrong Meter",
"meter_not_found": "Meter not found",
"wrong_meter": "Wrong meter",
"no_response": "No response",
"clamp_not_connected": "Clamp not connected",
"illegal_function": "Illegal function",

View file

@ -265,12 +265,12 @@
'no_error',
'communication',
'reading',
'slave',
'meter',
'waiting_wifi',
'waiting_communication',
'wrong_ip',
'slave_not_found',
'wrong_slave',
'meter_not_found',
'wrong_meter',
'no_response',
'clamp_not_connected',
'illegal_function',
@ -335,12 +335,12 @@
'no_error',
'communication',
'reading',
'slave',
'meter',
'waiting_wifi',
'waiting_communication',
'wrong_ip',
'slave_not_found',
'wrong_slave',
'meter_not_found',
'wrong_meter',
'no_response',
'clamp_not_connected',
'illegal_function',

View file

@ -33,12 +33,12 @@ async def test_sensor(
"no_error",
"communication",
"reading",
"slave",
"meter",
"waiting_wifi",
"waiting_communication",
"wrong_ip",
"slave_not_found",
"wrong_slave",
"meter_not_found",
"wrong_meter",
"no_response",
"clamp_not_connected",
"illegal_function",