Skip to content

Commit

Permalink
[tesla] Add channels for software update (#15816)
Browse files Browse the repository at this point in the history
* [tesla] Add value holders for Software Update state

Signed-off-by: Hakan Tandogan <hakan@tandogan.com>
  • Loading branch information
hakan42 authored Nov 1, 2023
1 parent e2b03de commit 59c3135
Show file tree
Hide file tree
Showing 13 changed files with 141 additions and 5 deletions.
5 changes: 4 additions & 1 deletion bundles/org.openhab.binding.tesla/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ public enum EventKeys {
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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,8 @@ public State getState(String s, TeslaChannelSelectorProxy proxy, Map<String, Str
}
},
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -922,6 +924,8 @@ public void parseAndUpdate(String request, String payLoad, String result) {
(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();

Expand All @@ -932,6 +936,8 @@ public void parseAndUpdate(String request, String payLoad, String result) {
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 {
Expand Down Expand Up @@ -966,6 +972,12 @@ public void parseAndUpdate(String request, String payLoad, String result) {
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();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public class VehicleState {
public String vehicle_name;
public String wheel_type;

public SoftwareUpdate software_update;

VehicleState() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@
<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"/>
Expand All @@ -126,7 +129,7 @@
</channels>

<properties>
<property name="thingTypeVersion">1</property>
<property name="thingTypeVersion">2</property>
</properties>

<config-description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@
<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"/>
Expand All @@ -132,7 +135,7 @@
</channels>

<properties>
<property name="thingTypeVersion">1</property>
<property name="thingTypeVersion">2</property>
</properties>

<config-description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@
<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"/>
Expand All @@ -132,7 +135,7 @@
</channels>

<properties>
<property name="thingTypeVersion">1</property>
<property name="thingTypeVersion">2</property>
</properties>

<config-description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@
<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"/>
Expand All @@ -128,7 +131,7 @@
</channels>

<properties>
<property name="thingTypeVersion">1</property>
<property name="thingTypeVersion">2</property>
</properties>

<config-description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@
<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">
Expand All @@ -41,6 +53,18 @@
<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">
Expand All @@ -61,6 +85,18 @@
<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">
Expand All @@ -81,5 +117,17 @@
<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>

0 comments on commit 59c3135

Please sign in to comment.