]> git.basschouten.com Git - openhab-addons.git/commitdiff
[tesla] Add channels for active routing (#15705)
authorHakan Tandogan <hakan@tandogan.com>
Thu, 12 Oct 2023 07:25:00 +0000 (09:25 +0200)
committerGitHub <noreply@github.com>
Thu, 12 Oct 2023 07:25:00 +0000 (09:25 +0200)
Signed-off-by: Hakan Tandogan <hakan@tandogan.com>
bundles/org.openhab.binding.tesla/README.md
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/protocol/DriveState.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 [new file with mode: 0644]

index e28d69c8ca0328a6f9ffb16eff361b6f0f8c0760..86bf7825256f6d428ed85ff8cbc2969eeda71e09 100644 (file)
@@ -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
+        }
     }
 }
 ```
index 40d5a990ba8ae01b3bc35720d0e185b7ad6110d2..69ed9afc50e3df4770d5e1c108861a5a7380172e 100644 (file)
@@ -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<String, String> 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<String, String> 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<String, String> 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<String, String> 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<String, String> 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<String, String> properties) {
index 56ac6f72a259e45c8b26c6159559d6bc27bf6370..5751a9ffdb87d0111ea73ef04df8aeba89bf02e4 100644 (file)
@@ -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;
index 0be5965cb164b1e1230e06ae84086aa4a13441aa..4a6c81c373db10e234d251190db152307465f1f8 100644 (file)
@@ -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
index 7355d5f368e507406dbd4ff8f787c66314e8eb3c..a24c283e189806a17f39b143ef0d7e69fc7975a0 100644 (file)
@@ -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">
 
+       <channel-type id="destinationname">
+               <item-type>String</item-type>
+               <label>Route Destination</label>
+               <description>Name of the destination</description>
+               <state readOnly="true"></state>
+       </channel-type>
+       <channel-type id="destinationlocation" advanced="false">
+               <item-type>Location</item-type>
+               <label>Route Location</label>
+               <description>Location of the destination</description>
+               <state readOnly="true"></state>
+       </channel-type>
+       <channel-type id="distancetoarrival">
+               <item-type>Number:Length</item-type>
+               <label>Distance To Arrival</label>
+               <description>Distance to drive to the destination (in miles)</description>
+               <state pattern="%.1f %unit%" readOnly="true"></state>
+       </channel-type>
+       <channel-type id="minutestoarrival">
+               <item-type>Number:Time</item-type>
+               <label>Minutes To Arrival</label>
+               <description>Minutes to drive to the destination</description>
+               <category>Time</category>
+               <state pattern="%d %unit%" readOnly="true"></state>
+       </channel-type>
+       <channel-type id="trafficminutesdelay">
+               <item-type>Number:Time</item-type>
+               <label>Traffic Delay</label>
+               <description>Delay to arrive at the destination due to traffic</description>
+               <category>Time</category>
+               <state pattern="%d %unit%" readOnly="true"></state>
+       </channel-type>
+
        <channel-type id="autoconditioning">
                <item-type>Switch</item-type>
                <label>Auto Conditioning</label>
index fdd9b5c4ad29d4549ef20a94637e709e02152b1b..2a892589c9344023872a39f364e2ebf548c982d2 100644 (file)
                <description>A Tesla Model 3 Vehicle</description>
 
                <channels>
+                       <channel id="destinationname" typeId="destinationname"/>
+                       <channel id="destinationlocation" typeId="destinationlocation"/>
+                       <channel id="distancetoarrival" typeId="distancetoarrival"/>
+                       <channel id="minutestoarrival" typeId="minutestoarrival"/>
+                       <channel id="trafficminutesdelay" typeId="trafficminutesdelay"/>
                        <channel id="autoconditioning" typeId="autoconditioning"/>
                        <channel id="autoparkstate" typeId="autoparkstate"/>
                        <channel id="autoparkstate2" typeId="autoparkstate"/>
                        <channel id="wakeup" typeId="wakeup"/>
                </channels>
 
+               <properties>
+                       <property name="thingTypeVersion">1</property>
+               </properties>
+
                <config-description>
                        <parameter name="vin" type="text" required="true">
                                <label>Vehicle Identification Number</label>
index 1a7b7c13ecd8bae4c206d9de68d4f6d63731f775..2251bdc60477cb0f2bc6154adda40e9e12a0ac8b 100644 (file)
                <description>A Tesla Model S Vehicle</description>
 
                <channels>
+                       <channel id="destinationname" typeId="destinationname"/>
+                       <channel id="destinationlocation" typeId="destinationlocation"/>
+                       <channel id="distancetoarrival" typeId="distancetoarrival"/>
+                       <channel id="minutestoarrival" typeId="minutestoarrival"/>
+                       <channel id="trafficminutesdelay" typeId="trafficminutesdelay"/>
                        <channel id="autoconditioning" typeId="autoconditioning"/>
                        <channel id="autoparkstate" typeId="autoparkstate"/>
                        <channel id="autoparkstate2" typeId="autoparkstate"/>
                        <channel id="wiperbladeheater" typeId="wiperbladeheater"/>
                </channels>
 
+               <properties>
+                       <property name="thingTypeVersion">1</property>
+               </properties>
+
                <config-description>
                        <parameter name="vin" type="text" required="true">
                                <label>Vehicle Identification Number</label>
index 369fffc35339b078c8af90a5d3510a968012a02e..6d3074a987260e5a8cec85502fa6bc974a2e074a 100644 (file)
                <description>A Tesla Model X Vehicle</description>
 
                <channels>
+                       <channel id="destinationname" typeId="destinationname"/>
+                       <channel id="destinationlocation" typeId="destinationlocation"/>
+                       <channel id="distancetoarrival" typeId="distancetoarrival"/>
+                       <channel id="minutestoarrival" typeId="minutestoarrival"/>
+                       <channel id="trafficminutesdelay" typeId="trafficminutesdelay"/>
                        <channel id="autoconditioning" typeId="autoconditioning"/>
                        <channel id="autoparkstate" typeId="autoparkstate"/>
                        <channel id="autoparkstate2" typeId="autoparkstate"/>
                        <channel id="wiperbladeheater" typeId="wiperbladeheater"/>
                </channels>
 
+               <properties>
+                       <property name="thingTypeVersion">1</property>
+               </properties>
+
                <config-description>
                        <parameter name="vin" type="text" required="true">
                                <label>Vehicle Identification Number</label>
index 46fb050f3644925b0c715fa55ad54e00228cb34c..647d592b928e500da4c388389d429438497f07b8 100644 (file)
                <description>A Tesla Model Y Vehicle</description>
 
                <channels>
+                       <channel id="destinationname" typeId="destinationname"/>
+                       <channel id="destinationlocation" typeId="destinationlocation"/>
+                       <channel id="distancetoarrival" typeId="distancetoarrival"/>
+                       <channel id="minutestoarrival" typeId="minutestoarrival"/>
+                       <channel id="trafficminutesdelay" typeId="trafficminutesdelay"/>
                        <channel id="allowwakeup" typeId="allowwakeup"/>
                        <channel id="autoconditioning" typeId="autoconditioning"/>
                        <channel id="autoparkstate" typeId="autoparkstate"/>
                        <channel id="wakeup" typeId="wakeup"/>
                </channels>
 
+               <properties>
+                       <property name="thingTypeVersion">1</property>
+               </properties>
+
                <config-description>
                        <parameter name="vin" type="text" required="true">
                                <label>Vehicle Identification Number</label>
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 (file)
index 0000000..e21eda2
--- /dev/null
@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
+<update:update-descriptions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:update="https://openhab.org/schemas/update-description/v1.0.0"
+       xsi:schemaLocation="https://openhab.org/schemas/update-description/v1.0.0 https://openhab.org/schemas/update-description-1.0.0.xsd">
+
+       <thing-type uid="tesla:model3">
+               <instruction-set targetVersion="1">
+                       <add-channel id="destinationname">
+                               <type>tesla:destinationname</type>
+                       </add-channel>
+                       <add-channel id="destinationlocation">
+                               <type>tesla:destinationlocation</type>
+                       </add-channel>
+                       <add-channel id="distancetoarrival">
+                               <type>tesla:distancetoarrival</type>
+                       </add-channel>
+                       <add-channel id="minutestoarrival">
+                               <type>tesla:minutestoarrival</type>
+                       </add-channel>
+                       <add-channel id="trafficminutesdelay">
+                               <type>tesla:trafficminutesdelay</type>
+                       </add-channel>
+               </instruction-set>
+       </thing-type>
+
+       <thing-type uid="tesla:models">
+               <instruction-set targetVersion="1">
+                       <add-channel id="destinationname">
+                               <type>tesla:destinationname</type>
+                       </add-channel>
+                       <add-channel id="destinationlocation">
+                               <type>tesla:destinationlocation</type>
+                       </add-channel>
+                       <add-channel id="distancetoarrival">
+                               <type>tesla:distancetoarrival</type>
+                       </add-channel>
+                       <add-channel id="minutestoarrival">
+                               <type>tesla:minutestoarrival</type>
+                       </add-channel>
+                       <add-channel id="trafficminutesdelay">
+                               <type>tesla:trafficminutesdelay</type>
+                       </add-channel>
+               </instruction-set>
+       </thing-type>
+
+       <thing-type uid="tesla:modelx">
+               <instruction-set targetVersion="1">
+                       <add-channel id="destinationname">
+                               <type>tesla:destinationname</type>
+                       </add-channel>
+                       <add-channel id="destinationlocation">
+                               <type>tesla:destinationlocation</type>
+                       </add-channel>
+                       <add-channel id="distancetoarrival">
+                               <type>tesla:distancetoarrival</type>
+                       </add-channel>
+                       <add-channel id="minutestoarrival">
+                               <type>tesla:minutestoarrival</type>
+                       </add-channel>
+                       <add-channel id="trafficminutesdelay">
+                               <type>tesla:trafficminutesdelay</type>
+                       </add-channel>
+               </instruction-set>
+       </thing-type>
+
+       <thing-type uid="tesla:modely">
+               <instruction-set targetVersion="1">
+                       <add-channel id="destinationname">
+                               <type>tesla:destinationname</type>
+                       </add-channel>
+                       <add-channel id="destinationlocation">
+                               <type>tesla:destinationlocation</type>
+                       </add-channel>
+                       <add-channel id="distancetoarrival">
+                               <type>tesla:distancetoarrival</type>
+                       </add-channel>
+                       <add-channel id="minutestoarrival">
+                               <type>tesla:minutestoarrival</type>
+                       </add-channel>
+                       <add-channel id="trafficminutesdelay">
+                               <type>tesla:trafficminutesdelay</type>
+                       </add-channel>
+               </instruction-set>
+       </thing-type>
+</update:update-descriptions>