From b7e78e3a0dd6433197d7e6ddc0458c71210088da Mon Sep 17 00:00:00 2001 From: Kai Kreuzer Date: Wed, 12 Jan 2022 08:41:10 +0100 Subject: [PATCH] Update sunroof feature to changed Tesla API (#12031) Signed-off-by: Kai Kreuzer --- bundles/org.openhab.binding.tesla/README.md | 4 +-- .../internal/handler/TeslaVehicleHandler.java | 36 +++++-------------- .../resources/OH-INF/i18n/tesla.properties | 6 ++-- .../main/resources/OH-INF/thing/channels.xml | 13 ++++--- 4 files changed, 23 insertions(+), 36 deletions(-) diff --git a/bundles/org.openhab.binding.tesla/README.md b/bundles/org.openhab.binding.tesla/README.md index 8145e96965..de852632f9 100644 --- a/bundles/org.openhab.binding.tesla/README.md +++ b/bundles/org.openhab.binding.tesla/README.md @@ -180,8 +180,8 @@ Additionally, these advanced channels are available (not all are available on al | soc | Number | State of Charge | State of Charge, in % | | state | String | State | “online”, “asleep”, “waking” | | steeringwheelheater | Switch | Steering Wheel Heater | Indicates if the steering wheel heater is switched on | -| sunroofstate | String | Sunroof State | “unknown”, “open”, “closed”, “vent”, “comfort” | -| sunroof | Dimmer | Sunroof | Open or close the sunroof to provided % (0 closed, 100 fully open) | +| sunroofstate | String | Sunroof State | Valid states are “unknown”, “open”, “closed”, “vent”, “comfort”. Accepts commands "close" and "vent". | +| sunroof | Dimmer | Sunroof | Indicates the opening state of the sunroof (0% closed, 100% fully open) | | temperature | Number:Temperature | Temperature | Set the temperature of the autoconditioning system. The temperature for the driver and passenger will be synced. | | timetofullcharge | Number | Time To Full Charge | Number of hours to fully charge the battery | | tripcharging | Switch | Trip Charging | Not documented / To be defined | diff --git a/bundles/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/handler/TeslaVehicleHandler.java b/bundles/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/handler/TeslaVehicleHandler.java index 14faab4e3c..9178580216 100644 --- a/bundles/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/handler/TeslaVehicleHandler.java +++ b/bundles/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/handler/TeslaVehicleHandler.java @@ -290,22 +290,6 @@ public class TeslaVehicleHandler extends BaseThingHandler { } break; } - case SUN_ROOF: { - if (command instanceof PercentType) { - moveSunroof(((PercentType) command).intValue()); - } else if (command instanceof OnOffType && command == OnOffType.ON) { - moveSunroof(100); - } else if (command instanceof OnOffType && command == OnOffType.OFF) { - moveSunroof(0); - } else if (command instanceof IncreaseDecreaseType - && command == IncreaseDecreaseType.INCREASE) { - moveSunroof(Math.min(vehicleState.sun_roof_percent_open + 1, 100)); - } else if (command instanceof IncreaseDecreaseType - && command == IncreaseDecreaseType.DECREASE) { - moveSunroof(Math.max(vehicleState.sun_roof_percent_open - 1, 0)); - } - break; - } case CHARGE_TO_MAX: { if (command instanceof OnOffType) { if (((OnOffType) command) == OnOffType.ON) { @@ -582,18 +566,14 @@ public class TeslaVehicleHandler extends BaseThingHandler { } public void setSunroof(String state) { - JsonObject payloadObject = new JsonObject(); - payloadObject.addProperty("state", state); - sendCommand(COMMAND_SUN_ROOF, gson.toJson(payloadObject), account.commandTarget); - requestData(VEHICLE_STATE); - } - - public void moveSunroof(int percent) { - JsonObject payloadObject = new JsonObject(); - payloadObject.addProperty("state", "move"); - payloadObject.addProperty("percent", percent); - sendCommand(COMMAND_SUN_ROOF, gson.toJson(payloadObject), account.commandTarget); - requestData(VEHICLE_STATE); + if (state.equals("vent") || state.equals("close")) { + JsonObject payloadObject = new JsonObject(); + payloadObject.addProperty("state", state); + sendCommand(COMMAND_SUN_ROOF, gson.toJson(payloadObject), account.commandTarget); + requestData(VEHICLE_STATE); + } else { + logger.warn("Ignoring invalid command '{}' for sunroof.", state); + } } /** diff --git a/bundles/org.openhab.binding.tesla/src/main/resources/OH-INF/i18n/tesla.properties b/bundles/org.openhab.binding.tesla/src/main/resources/OH-INF/i18n/tesla.properties index 34c4493408..456337296b 100644 --- a/bundles/org.openhab.binding.tesla/src/main/resources/OH-INF/i18n/tesla.properties +++ b/bundles/org.openhab.binding.tesla/src/main/resources/OH-INF/i18n/tesla.properties @@ -252,9 +252,11 @@ channel-type.tesla.state.description = “online”, “asleep”, “waking” channel-type.tesla.steeringwheelheater.label = Steering Wheel Heater channel-type.tesla.steeringwheelheater.description = Indicates if the steering wheel heater is switched on channel-type.tesla.sunroof.label = Sunroof -channel-type.tesla.sunroof.description = Open or close the sunroof to provided % (0 closed, 100 fully open) +channel-type.tesla.sunroof.description = Indicates the opening state of the sunroof (0% closed, 100% fully open) channel-type.tesla.sunroofstate.label = Sunroof State -channel-type.tesla.sunroofstate.description = “unknown”, “open”, “closed”, “vent”, “comfort” +channel-type.tesla.sunroofstate.description = Valid states are “unknown”, “open”, “closed”, “vent”, “comfort”. Accepts commands "close" and "vent". +channel-type.tesla.sunroofstate.command.option.close = close +channel-type.tesla.sunroofstate.command.option.vent = vent channel-type.tesla.timetofullcharge.label = Time To Full Charge channel-type.tesla.timetofullcharge.description = Number of hours to fully charge the battery channel-type.tesla.tripcharging.label = Trip Charging diff --git a/bundles/org.openhab.binding.tesla/src/main/resources/OH-INF/thing/channels.xml b/bundles/org.openhab.binding.tesla/src/main/resources/OH-INF/thing/channels.xml index 6aa616f5f7..de6cb004ab 100644 --- a/bundles/org.openhab.binding.tesla/src/main/resources/OH-INF/thing/channels.xml +++ b/bundles/org.openhab.binding.tesla/src/main/resources/OH-INF/thing/channels.xml @@ -583,14 +583,19 @@ String - “unknown”, “open”, “closed”, “vent”, “comfort” - + Valid states are “unknown”, “open”, “closed”, “vent”, “comfort”. Accepts commands "close" and "vent". + + + + + + Dimmer - Open or close the sunroof to provided % (0 closed, 100 fully open) - + Indicates the opening state of the sunroof (0% closed, 100% fully open) + Number:Temperature -- 2.47.3