Skip to content

Commit

Permalink
Fix renault plug state (#125421)
Browse files Browse the repository at this point in the history
* Added PlugState 3, that is coming with renault-api 0.2.7, it fixes #124682 HA ticket

* Added PlugState 3, that is coming with renault-api 0.2.7, it fixes #124682 HA ticket
  • Loading branch information
tmenguy authored Sep 7, 2024
1 parent 17994ff commit 3e70342
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 9 deletions.
16 changes: 11 additions & 5 deletions homeassistant/components/renault/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class RenaultBinarySensorEntityDescription(
"""Class describing Renault binary sensor entities."""

on_key: str
on_value: StateType
on_value: StateType | list[StateType]


async def async_setup_entry(
Expand Down Expand Up @@ -58,6 +58,9 @@ def is_on(self) -> bool | None:
"""Return true if the binary sensor is on."""
if (data := self._get_data_attr(self.entity_description.on_key)) is None:
return None

if isinstance(self.entity_description.on_value, list):
return data in self.entity_description.on_value
return data == self.entity_description.on_value


Expand All @@ -68,7 +71,10 @@ def is_on(self) -> bool | None:
coordinator="battery",
device_class=BinarySensorDeviceClass.PLUG,
on_key="plugStatus",
on_value=PlugState.PLUGGED.value,
on_value=[
PlugState.PLUGGED.value,
PlugState.PLUGGED_WAITING_FOR_CHARGE.value,
],
),
RenaultBinarySensorEntityDescription(
key="charging",
Expand Down Expand Up @@ -104,13 +110,13 @@ def is_on(self) -> bool | None:
]
+ [
RenaultBinarySensorEntityDescription(
key=f"{door.replace(' ','_').lower()}_door_status",
key=f"{door.replace(' ', '_').lower()}_door_status",
coordinator="lock_status",
# On means open, Off means closed
device_class=BinarySensorDeviceClass.DOOR,
on_key=f"doorStatus{door.replace(' ','')}",
on_key=f"doorStatus{door.replace(' ', '')}",
on_value="open",
translation_key=f"{door.lower().replace(' ','_')}_door_status",
translation_key=f"{door.lower().replace(' ', '_')}_door_status",
)
for door in ("Rear Left", "Rear Right", "Driver", "Passenger")
],
Expand Down
8 changes: 7 additions & 1 deletion homeassistant/components/renault/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,13 @@ def _get_utc_value(entity: RenaultSensor[T]) -> datetime:
translation_key="plug_state",
device_class=SensorDeviceClass.ENUM,
entity_class=RenaultSensor[KamereonVehicleBatteryStatusData],
options=["unplugged", "plugged", "plug_error", "plug_unknown"],
options=[
"unplugged",
"plugged",
"plugged_waiting_for_charge",
"plug_error",
"plug_unknown",
],
value_lambda=_get_plug_state_formatted,
),
RenaultSensorEntityDescription(
Expand Down
1 change: 1 addition & 0 deletions homeassistant/components/renault/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
"state": {
"unplugged": "Unplugged",
"plugged": "Plugged in",
"plugged_waiting_for_charge": "Plugged in, waiting for charge",
"plug_error": "Plug error",
"plug_unknown": "Plug unknown"
}
Expand Down
24 changes: 21 additions & 3 deletions tests/components/renault/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,13 @@
ATTR_DEVICE_CLASS: SensorDeviceClass.ENUM,
ATTR_ENTITY_ID: "sensor.reg_number_plug_state",
ATTR_ICON: "mdi:power-plug",
ATTR_OPTIONS: ["unplugged", "plugged", "plug_error", "plug_unknown"],
ATTR_OPTIONS: [
"unplugged",
"plugged",
"plugged_waiting_for_charge",
"plug_error",
"plug_unknown",
],
ATTR_STATE: "plugged",
ATTR_UNIQUE_ID: "vf1aaaaa555777999_plug_state",
},
Expand Down Expand Up @@ -487,7 +493,13 @@
ATTR_DEVICE_CLASS: SensorDeviceClass.ENUM,
ATTR_ENTITY_ID: "sensor.reg_number_plug_state",
ATTR_ICON: "mdi:power-plug-off",
ATTR_OPTIONS: ["unplugged", "plugged", "plug_error", "plug_unknown"],
ATTR_OPTIONS: [
"unplugged",
"plugged",
"plugged_waiting_for_charge",
"plug_error",
"plug_unknown",
],
ATTR_STATE: "unplugged",
ATTR_UNIQUE_ID: "vf1aaaaa555777999_plug_state",
},
Expand Down Expand Up @@ -725,7 +737,13 @@
ATTR_DEVICE_CLASS: SensorDeviceClass.ENUM,
ATTR_ENTITY_ID: "sensor.reg_number_plug_state",
ATTR_ICON: "mdi:power-plug",
ATTR_OPTIONS: ["unplugged", "plugged", "plug_error", "plug_unknown"],
ATTR_OPTIONS: [
"unplugged",
"plugged",
"plugged_waiting_for_charge",
"plug_error",
"plug_unknown",
],
ATTR_STATE: "plugged",
ATTR_UNIQUE_ID: "vf1aaaaa555777123_plug_state",
},
Expand Down
12 changes: 12 additions & 0 deletions tests/components/renault/snapshots/test_sensor.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@
'options': list([
'unplugged',
'plugged',
'plugged_waiting_for_charge',
'plug_error',
'plug_unknown',
]),
Expand Down Expand Up @@ -921,6 +922,7 @@
'options': list([
'unplugged',
'plugged',
'plugged_waiting_for_charge',
'plug_error',
'plug_unknown',
]),
Expand Down Expand Up @@ -1249,6 +1251,7 @@
'options': list([
'unplugged',
'plugged',
'plugged_waiting_for_charge',
'plug_error',
'plug_unknown',
]),
Expand Down Expand Up @@ -1674,6 +1677,7 @@
'options': list([
'unplugged',
'plugged',
'plugged_waiting_for_charge',
'plug_error',
'plug_unknown',
]),
Expand Down Expand Up @@ -2000,6 +2004,7 @@
'options': list([
'unplugged',
'plugged',
'plugged_waiting_for_charge',
'plug_error',
'plug_unknown',
]),
Expand Down Expand Up @@ -2456,6 +2461,7 @@
'options': list([
'unplugged',
'plugged',
'plugged_waiting_for_charge',
'plug_error',
'plug_unknown',
]),
Expand Down Expand Up @@ -3104,6 +3110,7 @@
'options': list([
'unplugged',
'plugged',
'plugged_waiting_for_charge',
'plug_error',
'plug_unknown',
]),
Expand Down Expand Up @@ -3531,6 +3538,7 @@
'options': list([
'unplugged',
'plugged',
'plugged_waiting_for_charge',
'plug_error',
'plug_unknown',
]),
Expand Down Expand Up @@ -3859,6 +3867,7 @@
'options': list([
'unplugged',
'plugged',
'plugged_waiting_for_charge',
'plug_error',
'plug_unknown',
]),
Expand Down Expand Up @@ -4284,6 +4293,7 @@
'options': list([
'unplugged',
'plugged',
'plugged_waiting_for_charge',
'plug_error',
'plug_unknown',
]),
Expand Down Expand Up @@ -4610,6 +4620,7 @@
'options': list([
'unplugged',
'plugged',
'plugged_waiting_for_charge',
'plug_error',
'plug_unknown',
]),
Expand Down Expand Up @@ -5066,6 +5077,7 @@
'options': list([
'unplugged',
'plugged',
'plugged_waiting_for_charge',
'plug_error',
'plug_unknown',
]),
Expand Down

0 comments on commit 3e70342

Please sign in to comment.