From b0aba56753d84be93672744bb2af9a11c54cdf96 Mon Sep 17 00:00:00 2001 From: S Q Date: Sat, 22 Jun 2024 07:17:43 +0200 Subject: [PATCH 1/3] Adding option to tilt sunroof --- README.md | 3 +++ custom_components/mbapi2020/client.py | 27 +++++++++++++++++++ custom_components/mbapi2020/const.py | 1 + custom_components/mbapi2020/icons.json | 3 ++- custom_components/mbapi2020/services.py | 6 +++++ custom_components/mbapi2020/services.yaml | 10 +++++++ .../mbapi2020/translations/en.json | 12 ++++++++- info.md | 3 +++ 8 files changed, 63 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3ec6f2c7..5d094230 100644 --- a/README.md +++ b/README.md @@ -289,6 +289,9 @@ Some services require that the security PIN is created in your mobile Android/IO * sunroof_open: Open the sunroof of a car defined by a vin. PIN required. +* sunroof_tilt: + Tilt the sunroof of a car defined by a vin. PIN required. + * sunroof_close: Close the sunroof of a car defined by a vin. diff --git a/custom_components/mbapi2020/client.py b/custom_components/mbapi2020/client.py index 5b955ad9..0b974079 100644 --- a/custom_components/mbapi2020/client.py +++ b/custom_components/mbapi2020/client.py @@ -952,6 +952,33 @@ async def sunroof_open(self, vin: str): await self.websocket.call(message.SerializeToString()) LOGGER.info("End sunroof_open for vin %s", loghelper.Mask_VIN(vin)) + async def sunroof_tilt(self, vin: str): + """Send a sunroof tilt command to the car.""" + LOGGER.info("Start sunroof_tilt for vin %s", loghelper.Mask_VIN(vin)) + + if not self._is_car_feature_available(vin, "SUNROOF_LIFT"): + LOGGER.warning( + "Can't tilt the sunroof for car %s. VIN unknown or feature not availabe for this car.", + loghelper.Mask_VIN(vin), + ) + return + + message = client_pb2.ClientMessage() + + if not self.pin: + LOGGER.warning( + "Can't tilt the sunroof - car %s. PIN not set. Please set the PIN -> Integration, Options ", + loghelper.Mask_VIN(vin), + ) + return + + message.commandRequest.vin = vin + message.commandRequest.request_id = str(uuid.uuid4()) + message.commandRequest.sunroof_lift.pin = self.pin + + await self.websocket.call(message.SerializeToString()) + LOGGER.info("End sunroof_open for vin %s", loghelper.Mask_VIN(vin)) + async def sunroof_close(self, vin: str): """Send a sunroof close command to the car.""" LOGGER.info("Start sunroof_close for vin %s", loghelper.Mask_VIN(vin)) diff --git a/custom_components/mbapi2020/const.py b/custom_components/mbapi2020/const.py index 4c88d1b0..d2b3f30d 100644 --- a/custom_components/mbapi2020/const.py +++ b/custom_components/mbapi2020/const.py @@ -142,6 +142,7 @@ SERVICE_SEND_ROUTE = "send_route" SERVICE_SIGPOS_START = "sigpos_start" SERVICE_SUNROOF_OPEN = "sunroof_open" +SERVICE_SUNROOF_TILT = "sunroof_tilt" SERVICE_SUNROOF_CLOSE = "sunroof_close" SERVICE_PREHEAT_START = "preheat_start" SERVICE_PREHEAT_START_DEPARTURE_TIME = "preheat_start_departure_time" diff --git a/custom_components/mbapi2020/icons.json b/custom_components/mbapi2020/icons.json index 90fc9374..1c6a9d8c 100644 --- a/custom_components/mbapi2020/icons.json +++ b/custom_components/mbapi2020/icons.json @@ -15,10 +15,11 @@ "preheat_stop_departure_time": "mdi:car-seat-heater", "sigpos_start": "mdi:bugle", "sunroof_open": "mdi:car-door", + "sunroof_tilt": "mdi:car-door", "sunroof_close": "mdi:car-door", "windows_open": "mdi:car-door", "windows_close": "mdi:car-door", "windows_move": "mdi:car-door", "send_route": "mdi:routes" } -} \ No newline at end of file +} diff --git a/custom_components/mbapi2020/services.py b/custom_components/mbapi2020/services.py index 71919944..602854cf 100644 --- a/custom_components/mbapi2020/services.py +++ b/custom_components/mbapi2020/services.py @@ -34,6 +34,7 @@ SERVICE_SIGPOS_START, SERVICE_SUNROOF_CLOSE, SERVICE_SUNROOF_OPEN, + SERVICE_SUNROOF_TILT, SERVICE_VIN_CHARGE_PROGRAM_SCHEMA, SERVICE_VIN_PIN_SCHEMA, SERVICE_VIN_SCHEMA, @@ -105,6 +106,9 @@ async def sigpos_start(call) -> None: async def sunroof_open(call) -> None: await domain[_get_config_entryid(call.data.get(CONF_VIN))].client.sunroof_open(call.data.get(CONF_VIN)) + async def sunroof_tilt(call) -> None: + await domain[_get_config_entryid(call.data.get(CONF_VIN))].client.sunroof_tilt(call.data.get(CONF_VIN)) + async def sunroof_close(call) -> None: await domain[_get_config_entryid(call.data.get(CONF_VIN))].client.sunroof_close(call.data.get(CONF_VIN)) @@ -200,6 +204,7 @@ async def download_images(call) -> None: (SERVICE_SEND_ROUTE, send_route_to_car, SERVICE_SEND_ROUTE_SCHEMA), (SERVICE_SIGPOS_START, sigpos_start, SERVICE_VIN_SCHEMA), (SERVICE_SUNROOF_OPEN, sunroof_open, SERVICE_VIN_SCHEMA), + (SERVICE_SUNROOF_TILT, sunroof_tilt, SERVICE_VIN_SCHEMA), (SERVICE_SUNROOF_CLOSE, sunroof_close, SERVICE_VIN_SCHEMA), (SERVICE_WINDOWS_OPEN, windows_open, SERVICE_VIN_PIN_SCHEMA), (SERVICE_WINDOWS_CLOSE, windows_close, SERVICE_VIN_SCHEMA), @@ -230,6 +235,7 @@ def remove_services(hass: HomeAssistant) -> None: hass.services.async_remove(DOMAIN, SERVICE_SEND_ROUTE) hass.services.async_remove(DOMAIN, SERVICE_SIGPOS_START) hass.services.async_remove(DOMAIN, SERVICE_SUNROOF_OPEN) + hass.services.async_remove(DOMAIN, SERVICE_SUNROOF_TILT) hass.services.async_remove(DOMAIN, SERVICE_SUNROOF_CLOSE) hass.services.async_remove(DOMAIN, SERVICE_WINDOWS_OPEN) hass.services.async_remove(DOMAIN, SERVICE_WINDOWS_CLOSE) diff --git a/custom_components/mbapi2020/services.yaml b/custom_components/mbapi2020/services.yaml index c42b2f97..665d5e66 100644 --- a/custom_components/mbapi2020/services.yaml +++ b/custom_components/mbapi2020/services.yaml @@ -248,6 +248,16 @@ sunroof_open: selector: text: +sunroof_tilt: + description: "Tilt the sunroof of a car defined by a vin. PIN setup required. See options dialog of the integration." + fields: + vin: + description: "vin of the car" + example: "Wxxxxxxxxxxxxxx" + required: True + selector: + text: + sunroof_close: description: "Close the sunroof of a car defined by a vin." fields: diff --git a/custom_components/mbapi2020/translations/en.json b/custom_components/mbapi2020/translations/en.json index 62f0ad84..10dfd661 100755 --- a/custom_components/mbapi2020/translations/en.json +++ b/custom_components/mbapi2020/translations/en.json @@ -275,6 +275,16 @@ } } }, + "sunroof_tilt": { + "name": "Sunroof open", + "description": "Tilt the sunroof of a car defined by a vin. PIN setup required. See options dialog of the integration.", + "fields": { + "vin": { + "name": "Vin", + "description": "Vin/Fin of the car" + } + } + }, "sunroof_close": { "name": "Sunroof close", "description": "Close the sunroof of a car defined by a vin.", @@ -540,4 +550,4 @@ } } } -} \ No newline at end of file +} diff --git a/info.md b/info.md index c4bbb010..f3d1dcb9 100644 --- a/info.md +++ b/info.md @@ -270,6 +270,9 @@ Some services require that the security PIN is created in your mobile Android/IO * sunroof_open: Open the sunroof of a car defined by a vin. PIN required. +* sunroof_tilt: + Tilt the sunroof of a car defined by a vin. PIN required. + * sunroof_close: Close the sunroof of a car defined by a vin. From 84bfdd2160fce25331d09b6145f7d85d7d7ef0ab Mon Sep 17 00:00:00 2001 From: Rene Nulsch <33263735+ReneNulschDE@users.noreply.github.com> Date: Sun, 23 Jun 2024 12:15:07 +0200 Subject: [PATCH 2/3] Update en.json change sunroof_tilt service name --- custom_components/mbapi2020/translations/en.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/mbapi2020/translations/en.json b/custom_components/mbapi2020/translations/en.json index 10dfd661..dae2fa1f 100755 --- a/custom_components/mbapi2020/translations/en.json +++ b/custom_components/mbapi2020/translations/en.json @@ -276,7 +276,7 @@ } }, "sunroof_tilt": { - "name": "Sunroof open", + "name": "Sunroof tilt", "description": "Tilt the sunroof of a car defined by a vin. PIN setup required. See options dialog of the integration.", "fields": { "vin": { From 6383e1c2a3f6b7fc1448079b18d888b1eb462908 Mon Sep 17 00:00:00 2001 From: Rene Nulsch <33263735+ReneNulschDE@users.noreply.github.com> Date: Sun, 23 Jun 2024 12:19:07 +0200 Subject: [PATCH 3/3] Fix log statement sunroof_tilt end --- custom_components/mbapi2020/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/mbapi2020/client.py b/custom_components/mbapi2020/client.py index 0b974079..26ca59ef 100644 --- a/custom_components/mbapi2020/client.py +++ b/custom_components/mbapi2020/client.py @@ -977,7 +977,7 @@ async def sunroof_tilt(self, vin: str): message.commandRequest.sunroof_lift.pin = self.pin await self.websocket.call(message.SerializeToString()) - LOGGER.info("End sunroof_open for vin %s", loghelper.Mask_VIN(vin)) + LOGGER.info("End sunroof_tilt for vin %s", loghelper.Mask_VIN(vin)) async def sunroof_close(self, vin: str): """Send a sunroof close command to the car."""