]> git.basschouten.com Git - openhab-addons.git/commitdiff
Update sunroof feature to changed Tesla API (#12031)
authorKai Kreuzer <kai@openhab.org>
Wed, 12 Jan 2022 07:41:10 +0000 (08:41 +0100)
committerGitHub <noreply@github.com>
Wed, 12 Jan 2022 07:41:10 +0000 (08:41 +0100)
Signed-off-by: Kai Kreuzer <kai@openhab.org>
bundles/org.openhab.binding.tesla/README.md
bundles/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/handler/TeslaVehicleHandler.java
bundles/org.openhab.binding.tesla/src/main/resources/OH-INF/i18n/tesla.properties
bundles/org.openhab.binding.tesla/src/main/resources/OH-INF/thing/channels.xml

index 8145e96965a28fcc50cd53d0b1aed19ac590ab88..de852632f9a9b7c5e4448bd638213e2bc514a346 100644 (file)
@@ -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                                                                                   |
index 14faab4e3c4bef371fa1c8f9f862579ce8f70913..91785802168350a26e9505380e91c2907bb68f25 100644 (file)
@@ -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);
+        }
     }
 
     /**
index 34c4493408aafc121583da6779ffb811c1a543a7..456337296b30b58c9c7210d93d4633e29d5932d5 100644 (file)
@@ -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
index 6aa616f5f74c7d48ce520a86325c620ace70d96c..de6cb004abc3b6c77d1e7be06727ff3c5c08a71e 100644 (file)
        <channel-type id="sunroofstate" advanced="true">
                <item-type>String</item-type>
                <label>Sunroof State</label>
-               <description>“unknown”, “open”, “closed”, “vent”, “comfort”</description>
-               <state readOnly="true"></state>
+               <description>Valid states are “unknown”, “open”, “closed”, “vent”, “comfort”. Accepts commands "close" and "vent".</description>
+               <command>
+                       <options>
+                               <option value="close">close</option>
+                               <option value="vent">vent</option>
+                       </options>
+               </command>
        </channel-type>
        <channel-type id="sunroof">
                <item-type>Dimmer</item-type>
                <label>Sunroof</label>
-               <description>Open or close the sunroof to provided % (0 closed, 100 fully open)</description>
-               <state pattern="%d %%"></state>
+               <description>Indicates the opening state of the sunroof (0% closed, 100% fully open)</description>
+               <state pattern="%d %%" readOnly="true"></state>
        </channel-type>
        <channel-type id="combinedtemp" advanced="true">
                <item-type>Number:Temperature</item-type>