Skip to content

Commit

Permalink
Added PlugState 3, that is coming with renault-api 0.2.7, it fixes ho…
Browse files Browse the repository at this point in the history
  • Loading branch information
tmenguy committed Sep 6, 2024
1 parent 9f469c0 commit fce42ad
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 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

0 comments on commit fce42ad

Please sign in to comment.