]> git.basschouten.com Git - openhab-addons.git/commitdiff
[tesla] Add channels for software update (#15816)
authorHakan Tandogan <hakan@tandogan.com>
Wed, 1 Nov 2023 20:24:36 +0000 (21:24 +0100)
committerGitHub <noreply@github.com>
Wed, 1 Nov 2023 20:24:36 +0000 (21:24 +0100)
* [tesla] Add value holders for Software Update state

Signed-off-by: Hakan Tandogan <hakan@tandogan.com>
13 files changed:
bundles/org.openhab.binding.tesla/README.md
bundles/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/TeslaBindingConstants.java
bundles/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/TeslaChannelSelectorProxy.java
bundles/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/handler/TeslaVehicleHandler.java
bundles/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/protocol/SoftwareUpdate.java [new file with mode: 0644]
bundles/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/protocol/VehicleState.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
bundles/org.openhab.binding.tesla/src/main/resources/OH-INF/thing/model3.xml
bundles/org.openhab.binding.tesla/src/main/resources/OH-INF/thing/models.xml
bundles/org.openhab.binding.tesla/src/main/resources/OH-INF/thing/modelx.xml
bundles/org.openhab.binding.tesla/src/main/resources/OH-INF/thing/modely.xml
bundles/org.openhab.binding.tesla/src/main/resources/OH-INF/update/instructions.xml

index 86bf7825256f6d428ed85ff8cbc2969eeda71e09..4387fdc0b51aad9fb7fb89956c90ce403d7c25c3 100644 (file)
@@ -182,9 +182,12 @@ Additionally, these advanced channels are available (not all are available on al
 | shiftstate                | String                   | Shift State                   | Indicates the state of the transmission, “P”, “D”, “R”, or “N”                                                   |
 | sidemirrorheaters         | Switch                   | Side Mirror Heaters           | Indicates if the side mirror heaters are switched on                                                             |
 | smartpreconditioning      | Switch                   | Smart Preconditioning         | Indicates if smart preconditioning is switched on                                                                |
+| softwareupdateavailable   | Switch                   | Update Available              | Car software update available, automatically generated on non-empty "update version"                             |
+| softwareupdatestatus      | String                   | Update Status                 | Car software update status, e.g. "downloading_wifi_wait", "installing"                                           |
+| softwareupdateversion     | String                   | Update Version                | Car software version to update to, e.g. "2023.32.9" or empty                                                     |
 | soc                       | Number                   | State of Charge               | State of Charge, in %                                                                                            |
 | state                     | String                   | State                         | “online”, “asleep”, “waking”                                                                                     |
-| steeringwheelheater       | Switch                   | Steering Wheel Heater         | Turns On/Off the steering wheel heater                      |
+| steeringwheelheater       | Switch                   | Steering Wheel Heater         | Turns On/Off the steering wheel heater                                                                           |
 | 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. |
index 09c1cf3d3d351fb653c608634364c47ec40d173f..c752c8ea0846dc0c96f6292da2c9d339fe1dace9 100644 (file)
@@ -101,6 +101,8 @@ public class TeslaBindingConstants {
     public static final String CHANNEL_COMBINED_TEMP = "combinedtemp";
     public static final String CHANNEL_EVENTSTAMP = "eventstamp";
 
+    public static final String CHANNEL_SOFTWARE_UPDATE_AVAILABLE = "softwareupdateavailable";
+
     // thing configurations
     public static final String CONFIG_ALLOWWAKEUP = "allowWakeup";
     public static final String CONFIG_ALLOWWAKEUPFORCOMMANDS = "allowWakeupForCommands";
index 69ed9afc50e3df4770d5e1c108861a5a7380172e..8b0bec3bad44973a8428d81b5c7a67707bf5b113 100644 (file)
@@ -933,6 +933,8 @@ public class TeslaChannelSelectorProxy {
             }
         },
         SOC("soc", "soc", PercentType.class, false),
+        SOFTWARE_UPDATE_STATUS("status", "softwareupdatestatus", StringType.class, false),
+        SOFTWARE_UPDATE_VERSION("version", "softwareupdateversion", StringType.class, false),
         SPEED("speed", "speed", DecimalType.class, false) {
             @Override
             public State getState(String s, TeslaChannelSelectorProxy proxy, Map<String, String> properties) {
index 440b5e6da2a506481d030658fbe50f18c326532a..88ce230ee6e1b14e7e00e84fff4dff534f3c0a88 100644 (file)
@@ -48,6 +48,7 @@ import org.openhab.binding.tesla.internal.protocol.ClimateState;
 import org.openhab.binding.tesla.internal.protocol.DriveState;
 import org.openhab.binding.tesla.internal.protocol.Event;
 import org.openhab.binding.tesla.internal.protocol.GUIState;
+import org.openhab.binding.tesla.internal.protocol.SoftwareUpdate;
 import org.openhab.binding.tesla.internal.protocol.Vehicle;
 import org.openhab.binding.tesla.internal.protocol.VehicleData;
 import org.openhab.binding.tesla.internal.protocol.VehicleState;
@@ -111,6 +112,7 @@ public class TeslaVehicleHandler extends BaseThingHandler {
     protected VehicleState vehicleState;
     protected ChargeState chargeState;
     protected ClimateState climateState;
+    protected SoftwareUpdate softwareUpdate;
 
     protected boolean allowWakeUp;
     protected boolean allowWakeUpForCommands;
@@ -922,6 +924,8 @@ public class TeslaVehicleHandler extends BaseThingHandler {
                             (climateState.driver_temp_setting + climateState.passenger_temp_setting) / 2.0f));
                     updateState(CHANNEL_COMBINED_TEMP, new QuantityType<>(avgtemp, SIUnits.CELSIUS));
 
+                    softwareUpdate = vehicleState.software_update;
+
                     try {
                         lock.lock();
 
@@ -932,6 +936,8 @@ public class TeslaVehicleHandler extends BaseThingHandler {
                         entrySet.addAll(gson.toJsonTree(vehicleState, VehicleState.class).getAsJsonObject().entrySet());
                         entrySet.addAll(gson.toJsonTree(chargeState, ChargeState.class).getAsJsonObject().entrySet());
                         entrySet.addAll(gson.toJsonTree(climateState, ClimateState.class).getAsJsonObject().entrySet());
+                        entrySet.addAll(
+                                gson.toJsonTree(softwareUpdate, SoftwareUpdate.class).getAsJsonObject().entrySet());
 
                         for (Map.Entry<String, JsonElement> entry : entrySet) {
                             try {
@@ -966,6 +972,12 @@ public class TeslaVehicleHandler extends BaseThingHandler {
                                         e.getMessage(), e);
                             }
                         }
+
+                        if (softwareUpdate.version == null || softwareUpdate.version.isBlank()) {
+                            updateState(CHANNEL_SOFTWARE_UPDATE_AVAILABLE, OnOffType.OFF);
+                        } else {
+                            updateState(CHANNEL_SOFTWARE_UPDATE_AVAILABLE, OnOffType.ON);
+                        }
                     } finally {
                         lock.unlock();
                     }
diff --git a/bundles/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/protocol/SoftwareUpdate.java b/bundles/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/protocol/SoftwareUpdate.java
new file mode 100644 (file)
index 0000000..d6139c5
--- /dev/null
@@ -0,0 +1,31 @@
+/**
+ * Copyright (c) 2010-2023 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.tesla.internal.protocol;
+
+/**
+ * The {@link SoftwareUpdate} is a datastructure to capture
+ * variables sent by the Tesla Vehicle
+ *
+ * @author Hakan Tandogan - Initial contribution
+ */
+public class SoftwareUpdate {
+
+    public int download_perc;
+    public int expected_duration_sec;
+    public int install_perc;
+    public String status;
+    public String version;
+
+    SoftwareUpdate() {
+    }
+}
index b4fe8b8c1042c3740e68d7eae9b8122589e36445..98f66a7367ca8ad7a4ea6712b73d2652ce6fe42b 100644 (file)
@@ -57,6 +57,8 @@ public class VehicleState {
     public String vehicle_name;
     public String wheel_type;
 
+    public SoftwareUpdate software_update;
+
     VehicleState() {
     }
 }
index ce45237ac0e3cc9739aa3292309fde5d73c94de1..cdf0ab7d8c8a338702fabcbb5ad2d74b1367a164 100644 (file)
@@ -322,6 +322,12 @@ channel-type.tesla.smartpreconditioning.label = Smart Preconditioning
 channel-type.tesla.smartpreconditioning.description = Indicates if smart preconditioning is switched on
 channel-type.tesla.soc.label = State of Charge
 channel-type.tesla.soc.description = State of Charge, in %
+channel-type.tesla.softwareupdateavailable.label = Update Available
+channel-type.tesla.softwareupdateavailable.description = Car software update available
+channel-type.tesla.softwareupdatestatus.label = Update Status
+channel-type.tesla.softwareupdatestatus.description = Car software update status
+channel-type.tesla.softwareupdateversion.label = Update Version
+channel-type.tesla.softwareupdateversion.description = Car software version to update to
 channel-type.tesla.speed.label = Speed
 channel-type.tesla.speed.description = Vehicle speed
 channel-type.tesla.state.label = State
index a24c283e189806a17f39b143ef0d7e69fc7975a0..5facdaffb60fe3a9a92f2128f3cbafa32246f47f 100644 (file)
@@ -4,6 +4,24 @@
        xmlns:thing="https://openhab.org/schemas/thing-description/v1.0.0"
        xsi:schemaLocation="https://openhab.org/schemas/thing-description/v1.0.0 https://openhab.org/schemas/thing-description-1.0.0.xsd">
 
+       <channel-type id="softwareupdateavailable">
+               <item-type>Switch</item-type>
+               <label>Update Available</label>
+               <description>Car software update available</description>
+               <state readOnly="true"></state>
+       </channel-type>
+       <channel-type id="softwareupdatestatus">
+               <item-type>String</item-type>
+               <label>Update Status</label>
+               <description>Car software update status</description>
+               <state readOnly="true"></state>
+       </channel-type>
+       <channel-type id="softwareupdateversion">
+               <item-type>String</item-type>
+               <label>Update Version</label>
+               <description>Car software version to update to</description>
+               <state readOnly="true"></state>
+       </channel-type>
        <channel-type id="destinationname">
                <item-type>String</item-type>
                <label>Route Destination</label>
index 2a892589c9344023872a39f364e2ebf548c982d2..ff1c073d4d98135f66e893e9d81bbc8cf3a0eaac 100644 (file)
                        <channel id="sidemirrorheaters" typeId="sidemirrorheaters"/>
                        <channel id="smartpreconditioning" typeId="smartpreconditioning"/>
                        <channel id="soc" typeId="soc"/>
+                       <channel id="softwareupdateavailable" typeId="softwareupdateavailable"/>
+                       <channel id="softwareupdatestatus" typeId="softwareupdatestatus"/>
+                       <channel id="softwareupdateversion" typeId="softwareupdateversion"/>
                        <channel id="speed" typeId="speed"/>
                        <channel id="state" typeId="state"/>
                        <channel id="steeringwheelheater" typeId="steeringwheelheater"/>
                </channels>
 
                <properties>
-                       <property name="thingTypeVersion">1</property>
+                       <property name="thingTypeVersion">2</property>
                </properties>
 
                <config-description>
index 2251bdc60477cb0f2bc6154adda40e9e12a0ac8b..b6d6394fdf86fa08a6c1739b17b8ea98f2094035 100644 (file)
                        <channel id="sidemirrorheaters" typeId="sidemirrorheaters"/>
                        <channel id="smartpreconditioning" typeId="smartpreconditioning"/>
                        <channel id="soc" typeId="soc"/>
+                       <channel id="softwareupdateavailable" typeId="softwareupdateavailable"/>
+                       <channel id="softwareupdatestatus" typeId="softwareupdatestatus"/>
+                       <channel id="softwareupdateversion" typeId="softwareupdateversion"/>
                        <channel id="speed" typeId="speed"/>
                        <channel id="state" typeId="state"/>
                        <channel id="steeringwheelheater" typeId="steeringwheelheater"/>
                </channels>
 
                <properties>
-                       <property name="thingTypeVersion">1</property>
+                       <property name="thingTypeVersion">2</property>
                </properties>
 
                <config-description>
index 6d3074a987260e5a8cec85502fa6bc974a2e074a..4440b6e4fa9adf419f8e9def41d79846aff2c3c3 100644 (file)
                        <channel id="sidemirrorheaters" typeId="sidemirrorheaters"/>
                        <channel id="smartpreconditioning" typeId="smartpreconditioning"/>
                        <channel id="soc" typeId="soc"/>
+                       <channel id="softwareupdateavailable" typeId="softwareupdateavailable"/>
+                       <channel id="softwareupdatestatus" typeId="softwareupdatestatus"/>
+                       <channel id="softwareupdateversion" typeId="softwareupdateversion"/>
                        <channel id="speed" typeId="speed"/>
                        <channel id="state" typeId="state"/>
                        <channel id="steeringwheelheater" typeId="steeringwheelheater"/>
                </channels>
 
                <properties>
-                       <property name="thingTypeVersion">1</property>
+                       <property name="thingTypeVersion">2</property>
                </properties>
 
                <config-description>
index 647d592b928e500da4c388389d429438497f07b8..781bc6a6fcc720e30fc5d8e7966ea3edd99bfb14 100644 (file)
                        <channel id="smartpreconditioning" typeId="smartpreconditioning"/>
                        <channel id="steeringwheelheater" typeId="steeringwheelheater"/>
                        <channel id="soc" typeId="soc"/>
+                       <channel id="softwareupdateavailable" typeId="softwareupdateavailable"/>
+                       <channel id="softwareupdatestatus" typeId="softwareupdatestatus"/>
+                       <channel id="softwareupdateversion" typeId="softwareupdateversion"/>
                        <channel id="speed" typeId="speed"/>
                        <channel id="state" typeId="state"/>
                        <channel id="combinedtemp" typeId="combinedtemp"/>
                </channels>
 
                <properties>
-                       <property name="thingTypeVersion">1</property>
+                       <property name="thingTypeVersion">2</property>
                </properties>
 
                <config-description>
index e21eda2f56dd65c0b6e8eca90a26d371a159f725..ef59ce2a2a5fbe6374a550734c83e6d1632e6503 100644 (file)
                                <type>tesla:trafficminutesdelay</type>
                        </add-channel>
                </instruction-set>
+
+               <instruction-set targetVersion="2">
+                       <add-channel id="softwareupdateavailable" typeId="softwareupdateavailable">
+                               <type>tesla:softwareupdateavailable</type>
+                       </add-channel>
+                       <add-channel id="softwareupdatestatus" typeId="softwareupdatestatus">
+                               <type>tesla:softwareupdatestatus</type>
+                       </add-channel>
+                       <add-channel id="softwareupdateversion" typeId="softwareupdateversion">
+                               <type>tesla:softwareupdateversion</type>
+                       </add-channel>
+               </instruction-set>
        </thing-type>
 
        <thing-type uid="tesla:models">
                                <type>tesla:trafficminutesdelay</type>
                        </add-channel>
                </instruction-set>
+
+               <instruction-set targetVersion="2">
+                       <add-channel id="softwareupdateavailable" typeId="softwareupdateavailable">
+                               <type>tesla:softwareupdateavailable</type>
+                       </add-channel>
+                       <add-channel id="softwareupdatestatus" typeId="softwareupdatestatus">
+                               <type>tesla:softwareupdatestatus</type>
+                       </add-channel>
+                       <add-channel id="softwareupdateversion" typeId="softwareupdateversion">
+                               <type>tesla:softwareupdateversion</type>
+                       </add-channel>
+               </instruction-set>
        </thing-type>
 
        <thing-type uid="tesla:modelx">
                                <type>tesla:trafficminutesdelay</type>
                        </add-channel>
                </instruction-set>
+
+               <instruction-set targetVersion="2">
+                       <add-channel id="softwareupdateavailable" typeId="softwareupdateavailable">
+                               <type>tesla:softwareupdateavailable</type>
+                       </add-channel>
+                       <add-channel id="softwareupdatestatus" typeId="softwareupdatestatus">
+                               <type>tesla:softwareupdatestatus</type>
+                       </add-channel>
+                       <add-channel id="softwareupdateversion" typeId="softwareupdateversion">
+                               <type>tesla:softwareupdateversion</type>
+                       </add-channel>
+               </instruction-set>
        </thing-type>
 
        <thing-type uid="tesla:modely">
                                <type>tesla:trafficminutesdelay</type>
                        </add-channel>
                </instruction-set>
+
+               <instruction-set targetVersion="2">
+                       <add-channel id="softwareupdateavailable" typeId="softwareupdateavailable">
+                               <type>tesla:softwareupdateavailable</type>
+                       </add-channel>
+                       <add-channel id="softwareupdatestatus" typeId="softwareupdatestatus">
+                               <type>tesla:softwareupdatestatus</type>
+                       </add-channel>
+                       <add-channel id="softwareupdateversion" typeId="softwareupdateversion">
+                               <type>tesla:softwareupdateversion</type>
+                       </add-channel>
+               </instruction-set>
        </thing-type>
 </update:update-descriptions>