From 9225fbf5947482f715474ec62db793ef81c47aad Mon Sep 17 00:00:00 2001 From: Philipp Waller <1090452+philippwaller@users.noreply.github.com> Date: Wed, 2 Oct 2024 17:01:05 +0200 Subject: [PATCH] feat: add "Wiper Health" sensor --- README.md | 7 +++++++ custom_components/mbapi2020/car.py | 8 ++++++++ custom_components/mbapi2020/client.py | 10 ++++++++++ custom_components/mbapi2020/const.py | 17 +++++++++++++++++ 4 files changed, 42 insertions(+) diff --git a/README.md b/README.md index 36168c4c..80de567c 100644 --- a/README.md +++ b/README.md @@ -104,6 +104,13 @@ Depends on your own car or purchased Mercedes Benz licenses. precondState, precondActive, precondError, precondNow, precondNowError, precondDuration, precondatdeparture, precondAtDepartureDisable, precondSeatFrontLeft, precondSeatFrontRight, precondSeatRearLeft, precondSeatRearRight ``` +- wiperHealth + + ``` + attributes: + wiperLifetimeExceeded [EXPERIMENTAL, user feedback wanted] + ``` + ### Device Tracker ``` diff --git a/custom_components/mbapi2020/car.py b/custom_components/mbapi2020/car.py index eeb15772..5e10df10 100644 --- a/custom_components/mbapi2020/car.py +++ b/custom_components/mbapi2020/car.py @@ -157,6 +157,8 @@ "auxheattime3", ] +WIPER_OPTIONS = ["wiperLifetimeExceeded", "wiperHealthPercent"] + PRE_COND_OPTIONS = [ "precondStatus", "precondOperatingMode", @@ -224,6 +226,7 @@ def __init__(self, vin: str): self.binarysensors = None self.tires = None + self.wipers = None self.odometer = None self.doors = None self.location = None @@ -295,6 +298,11 @@ class Tires: name: str = "Tires" +@dataclass(init=False) +class Wipers: + """Stores the Wiper values at runtime.""" + + name: str = "Wipers" @dataclass(init=False) class Odometer: diff --git a/custom_components/mbapi2020/client.py b/custom_components/mbapi2020/client.py index 618eff79..3118a4c9 100644 --- a/custom_components/mbapi2020/client.py +++ b/custom_components/mbapi2020/client.py @@ -30,6 +30,7 @@ PRE_COND_OPTIONS, TIRE_OPTIONS, WINDOW_OPTIONS, + WIPER_OPTIONS, Auxheat, BinarySensors, Car, @@ -44,6 +45,7 @@ Precond, Tires, Windows, + Wipers, ) from .const import ( CONF_DEBUG_FILE_SAVE, @@ -303,6 +305,14 @@ def _build_car(self, received_car_data, update_mode): update_mode, ) + car.wipers = self._get_car_values( + received_car_data, + car.finorvin, + Wipers() if not car.wipers else car.wipers, + WIPER_OPTIONS, + update_mode, + ) + car.doors = self._get_car_values( received_car_data, car.finorvin, diff --git a/custom_components/mbapi2020/const.py b/custom_components/mbapi2020/const.py index cbd7e156..ee54ceb2 100644 --- a/custom_components/mbapi2020/const.py +++ b/custom_components/mbapi2020/const.py @@ -1267,6 +1267,23 @@ None, None, ], + "wiperHealthPercent": [ + "Wiper Health", + None, # Deprecated: DO NOT USE + "wipers", + "wiperHealthPercent", + "value", + None, + { + "wiperLifetimeExceeded", + }, + "mdi:wiper", + None, + False, + None, + None, + None, + ], } LOCKS = {