From 74d55c60e18abfcf565fb3afa27051a0c6634e8c Mon Sep 17 00:00:00 2001 From: Hakan Tandogan Date: Thu, 12 Oct 2023 09:25:00 +0200 Subject: [PATCH] [tesla] Add channels for active routing (#15705) Signed-off-by: Hakan Tandogan --- bundles/org.openhab.binding.tesla/README.md | 18 +++- .../internal/TeslaChannelSelectorProxy.java | 42 +++++++++ .../tesla/internal/protocol/DriveState.java | 6 ++ .../resources/OH-INF/i18n/tesla.properties | 11 +++ .../main/resources/OH-INF/thing/channels.xml | 33 +++++++ .../main/resources/OH-INF/thing/model3.xml | 9 ++ .../main/resources/OH-INF/thing/models.xml | 9 ++ .../main/resources/OH-INF/thing/modelx.xml | 9 ++ .../main/resources/OH-INF/thing/modely.xml | 9 ++ .../resources/OH-INF/update/instructions.xml | 85 +++++++++++++++++++ 10 files changed, 230 insertions(+), 1 deletion(-) create mode 100644 bundles/org.openhab.binding.tesla/src/main/resources/OH-INF/update/instructions.xml diff --git a/bundles/org.openhab.binding.tesla/README.md b/bundles/org.openhab.binding.tesla/README.md index e28d69c8ca0..86bf7825256 100644 --- a/bundles/org.openhab.binding.tesla/README.md +++ b/bundles/org.openhab.binding.tesla/README.md @@ -90,6 +90,11 @@ Additionally, these advanced channels are available (not all are available on al | Channel ID | Item Type | Label | Description | |---------------------------|--------------------------|-------------------------------|------------------------------------------------------------------------------------------------------------------| +| destinationname | String | Route destination | Name of the destination | +| destinationlocation | Location | Route location | Location of the destination | +| distancetoarrival | Number:Length | Distance to arrival | Distance to drive to the destination (in miles) | +| minutestoarrival | Number:Time | Minutes to arrival | Minutes to drive to the destination | +| trafficminutesdelay | Number:Time | Traffic delay | Minutes of delay due to traffic | | autoparkstate | String | Autopark State | Undocumented / To be defined | | autoparkstyle | String | Autopark Style | Undocumented / To be defined | | batterycurrent | Number:ElectricCurrent | Battery Current | Current (Ampere) floating into (+) or out (-) of the battery | @@ -200,7 +205,6 @@ demo.Things: Bridge tesla:account:myaccount "My Tesla Account" [ refreshToken="xxxx" ] { model3 mycar "My favorite car" [ vin="5YJSA7H25FFP53736"] } -``` demo.items: @@ -263,6 +267,11 @@ Number:Temperature TeslaTemperature {channel="account:model3:myaccou Number:Temperature TeslaTemperatureCombined {channel="account:model3:myaccount:mycar:combinedtemp"} Number:Temperature TeslaInsideTemperature {channel="account:model3:myaccount:mycar:insidetemp"} Number:Temperature TeslaOutsideTemperature {channel="account:model3:myaccount:mycar:outsidetemp"} + +String TeslaDestinationName {channel="account:model3:myaccount:mycar:destinationname"} +Location TeslaDestinationLocation {channel="account:model3:myaccount:mycar:destinationlocation"} +Number:Time TeslaMinutesToArrival {channel="account:model3:myaccount:mycar:minutestoarrival", unit="min"} +Number:Length TeslaDistanceToArrival {channel="account:model3:myaccount:mycar:distancetoarrival"} ``` demo.sitemap: @@ -339,6 +348,13 @@ sitemap main label="Main" { Mapview item=TeslaLocation height=10 } + Frame + { + Default item=TeslaDestinationName + Default item=TeslaMinutesToArrival + Default item=TeslaDistanceToArrival + Mapview item=TeslaDestinationLocation height=10 + } } } ``` diff --git a/bundles/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/TeslaChannelSelectorProxy.java b/bundles/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/TeslaChannelSelectorProxy.java index 40d5a990ba8..69ed9afc50e 100644 --- a/bundles/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/TeslaChannelSelectorProxy.java +++ b/bundles/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/TeslaChannelSelectorProxy.java @@ -45,6 +45,48 @@ public class TeslaChannelSelectorProxy { public enum TeslaChannelSelector { API("api_version", "api", DecimalType.class, true), + AR_DESTINATION("active_route_destination", "destinationname", StringType.class, false), + AR_LATITUDE("active_route_latitude", "destinationlocation", DecimalType.class, false) { + @Override + public State getState(String s, TeslaChannelSelectorProxy proxy, Map properties) { + proxy.latitude = s; + return new PointType(new StringType(proxy.latitude), new StringType(proxy.longitude), + new StringType(proxy.elevation)); + } + }, + AR_LONGITUDE("active_route_longitude", "destinationlocation", DecimalType.class, false) { + @Override + public State getState(String s, TeslaChannelSelectorProxy proxy, Map properties) { + proxy.longitude = s; + return new PointType(new StringType(proxy.latitude), new StringType(proxy.longitude), + new StringType(proxy.elevation)); + } + }, + AR_DISTANCE_TO_ARRIVAL("active_route_miles_to_arrival", "distancetoarrival", DecimalType.class, false) { + @Override + public State getState(String s, TeslaChannelSelectorProxy proxy, Map properties) { + State someState = super.getState(s); + BigDecimal value = ((DecimalType) someState).toBigDecimal(); + return new QuantityType<>(value, ImperialUnits.MILE); + } + }, + AR_MINUTES_TO_ARRIVAL("active_route_minutes_to_arrival", "minutestoarrival", DecimalType.class, false) { + @Override + public State getState(String s, TeslaChannelSelectorProxy proxy, Map properties) { + State someState = super.getState(s); + BigDecimal value = ((DecimalType) someState).toBigDecimal(); + return new QuantityType<>(value, Units.MINUTE); + } + }, + AR_TRAFFIC_MINUTES_DELAY("active_route_traffic_minutes_delay", "trafficminutesdelay", DecimalType.class, + false) { + @Override + public State getState(String s, TeslaChannelSelectorProxy proxy, Map properties) { + State someState = super.getState(s); + BigDecimal value = ((DecimalType) someState).toBigDecimal(); + return new QuantityType<>(value, Units.MINUTE); + } + }, AUTO_COND("is_auto_conditioning_on", "autoconditioning", OnOffType.class, false) { @Override public State getState(String s, TeslaChannelSelectorProxy proxy, Map properties) { diff --git a/bundles/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/protocol/DriveState.java b/bundles/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/protocol/DriveState.java index 56ac6f72a25..5751a9ffdb8 100644 --- a/bundles/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/protocol/DriveState.java +++ b/bundles/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/protocol/DriveState.java @@ -20,6 +20,12 @@ package org.openhab.binding.tesla.internal.protocol; */ public class DriveState { + public String active_route_destination; + public double active_route_latitude; + public double active_route_longitude; + public double active_route_miles_to_arrival; + public double active_route_minutes_to_arrival; + public double active_route_traffic_minutes_delay; public double latitude; public double longitude; public double native_latitude; 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 0be5965cb16..4a6c81c373d 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 @@ -105,6 +105,17 @@ thing-type.config.tesla.vehicle.vin.description = VIN of the vehicle # channel types +channel-type.tesla.destinationname.label = Route Destination +channel-type.tesla.destinationname.description = Name of the destination +channel-type.tesla.destinationlocation.label = Route Location +channel-type.tesla.destinationlocation.description = Location of the destination +channel-type.tesla.distancetoarrival.label = Distance To Arrival +channel-type.tesla.distancetoarrival.description = Distance to drive to the destination (in miles) +channel-type.tesla.minutestoarrival.label = Minutes To Arrival +channel-type.tesla.minutestoarrival.description = Minutes to drive to the destination +channel-type.tesla.trafficminutesdelay.label = Traffic Delay +channel-type.tesla.trafficminutesdelay.description = Delay to arrive at the destination due to traffic + channel-type.tesla.autoconditioning.label = Auto Conditioning channel-type.tesla.autoconditioning.description = Turns on auto-conditioning (a/c or heating) channel-type.tesla.autoparkstate.label = Autopark State 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 7355d5f368e..a24c283e189 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 @@ -4,6 +4,39 @@ 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"> + + String + + Name of the destination + + + + Location + + Location of the destination + + + + Number:Length + + Distance to drive to the destination (in miles) + + + + Number:Time + + Minutes to drive to the destination + Time + + + + Number:Time + + Delay to arrive at the destination due to traffic + Time + + + Switch diff --git a/bundles/org.openhab.binding.tesla/src/main/resources/OH-INF/thing/model3.xml b/bundles/org.openhab.binding.tesla/src/main/resources/OH-INF/thing/model3.xml index fdd9b5c4ad2..2a892589c93 100644 --- a/bundles/org.openhab.binding.tesla/src/main/resources/OH-INF/thing/model3.xml +++ b/bundles/org.openhab.binding.tesla/src/main/resources/OH-INF/thing/model3.xml @@ -14,6 +14,11 @@ A Tesla Model 3 Vehicle + + + + + @@ -120,6 +125,10 @@ + + 1 + + diff --git a/bundles/org.openhab.binding.tesla/src/main/resources/OH-INF/thing/models.xml b/bundles/org.openhab.binding.tesla/src/main/resources/OH-INF/thing/models.xml index 1a7b7c13ecd..2251bdc6047 100644 --- a/bundles/org.openhab.binding.tesla/src/main/resources/OH-INF/thing/models.xml +++ b/bundles/org.openhab.binding.tesla/src/main/resources/OH-INF/thing/models.xml @@ -14,6 +14,11 @@ A Tesla Model S Vehicle + + + + + @@ -126,6 +131,10 @@ + + 1 + + diff --git a/bundles/org.openhab.binding.tesla/src/main/resources/OH-INF/thing/modelx.xml b/bundles/org.openhab.binding.tesla/src/main/resources/OH-INF/thing/modelx.xml index 369fffc3533..6d3074a9872 100644 --- a/bundles/org.openhab.binding.tesla/src/main/resources/OH-INF/thing/modelx.xml +++ b/bundles/org.openhab.binding.tesla/src/main/resources/OH-INF/thing/modelx.xml @@ -14,6 +14,11 @@ A Tesla Model X Vehicle + + + + + @@ -126,6 +131,10 @@ + + 1 + + diff --git a/bundles/org.openhab.binding.tesla/src/main/resources/OH-INF/thing/modely.xml b/bundles/org.openhab.binding.tesla/src/main/resources/OH-INF/thing/modely.xml index 46fb050f364..647d592b928 100644 --- a/bundles/org.openhab.binding.tesla/src/main/resources/OH-INF/thing/modely.xml +++ b/bundles/org.openhab.binding.tesla/src/main/resources/OH-INF/thing/modely.xml @@ -14,6 +14,11 @@ A Tesla Model Y Vehicle + + + + + @@ -122,6 +127,10 @@ + + 1 + + diff --git a/bundles/org.openhab.binding.tesla/src/main/resources/OH-INF/update/instructions.xml b/bundles/org.openhab.binding.tesla/src/main/resources/OH-INF/update/instructions.xml new file mode 100644 index 00000000000..e21eda2f56d --- /dev/null +++ b/bundles/org.openhab.binding.tesla/src/main/resources/OH-INF/update/instructions.xml @@ -0,0 +1,85 @@ + + + + + + + tesla:destinationname + + + tesla:destinationlocation + + + tesla:distancetoarrival + + + tesla:minutestoarrival + + + tesla:trafficminutesdelay + + + + + + + + tesla:destinationname + + + tesla:destinationlocation + + + tesla:distancetoarrival + + + tesla:minutestoarrival + + + tesla:trafficminutesdelay + + + + + + + + tesla:destinationname + + + tesla:destinationlocation + + + tesla:distancetoarrival + + + tesla:minutestoarrival + + + tesla:trafficminutesdelay + + + + + + + + tesla:destinationname + + + tesla:destinationlocation + + + tesla:distancetoarrival + + + tesla:minutestoarrival + + + tesla:trafficminutesdelay + + + +