]> git.basschouten.com Git - openhab-addons.git/commitdiff
[mybmw] Add home-distance channel (#13093)
authorBernd Weymann <bernd.weymann@gmail.com>
Sat, 9 Jul 2022 13:56:05 +0000 (15:56 +0200)
committerGitHub <noreply@github.com>
Sat, 9 Jul 2022 13:56:05 +0000 (15:56 +0200)
* add home-distance channel
* use uniformed instead of random gps coordinates

Signed-off-by: Bernd Weymann <bernd.weymann@gmail.com>
17 files changed:
bundles/org.openhab.binding.mybmw/README.md
bundles/org.openhab.binding.mybmw/src/main/java/org/openhab/binding/mybmw/internal/MyBMWConstants.java
bundles/org.openhab.binding.mybmw/src/main/java/org/openhab/binding/mybmw/internal/MyBMWHandlerFactory.java
bundles/org.openhab.binding.mybmw/src/main/java/org/openhab/binding/mybmw/internal/dto/properties/Coordinates.java
bundles/org.openhab.binding.mybmw/src/main/java/org/openhab/binding/mybmw/internal/dto/properties/Location.java
bundles/org.openhab.binding.mybmw/src/main/java/org/openhab/binding/mybmw/internal/handler/VehicleChannelHandler.java
bundles/org.openhab.binding.mybmw/src/main/java/org/openhab/binding/mybmw/internal/handler/VehicleHandler.java
bundles/org.openhab.binding.mybmw/src/main/java/org/openhab/binding/mybmw/internal/utils/Converter.java
bundles/org.openhab.binding.mybmw/src/main/resources/OH-INF/i18n/mybmw.properties
bundles/org.openhab.binding.mybmw/src/main/resources/OH-INF/thing/location-channel-group.xml
bundles/org.openhab.binding.mybmw/src/main/resources/OH-INF/thing/location-channel-types.xml
bundles/org.openhab.binding.mybmw/src/test/java/org/openhab/binding/mybmw/internal/dto/StatusWrapper.java
bundles/org.openhab.binding.mybmw/src/test/java/org/openhab/binding/mybmw/internal/dto/VehicleStatusTest.java
bundles/org.openhab.binding.mybmw/src/test/java/org/openhab/binding/mybmw/internal/handler/ChargeStatisticsTest.java
bundles/org.openhab.binding.mybmw/src/test/java/org/openhab/binding/mybmw/internal/handler/ErrorResponseTest.java
bundles/org.openhab.binding.mybmw/src/test/java/org/openhab/binding/mybmw/internal/handler/VehicleTests.java
bundles/org.openhab.binding.mybmw/src/test/resources/responses/I01_REX/vehicles.json

index 9ee702052bdf233c7021f5d861e90ee2e2e7197a..d0dc7a475f3aec78a49c3541e3d9ad4c5255cb46 100644 (file)
@@ -339,12 +339,12 @@ GPS location and heading of the vehicle.
 * Available for all vehicles with built-in GPS sensor. Function can be enabled/disabled in the head unit
 * Read-only values
 
-| Channel Label   | Channel ID          | Type         | 
-|-----------------|---------------------|--------------|
-| GPS Coordinates | gps                 | Location     | 
-| Heading         | heading             | Number:Angle | 
-| Address         | address             | String       | 
-
+| Channel Label       | Channel ID          | Type          | 
+|---------------------|---------------------|---------------|
+| GPS Coordinates     | gps                 | Location      | 
+| Heading             | heading             | Number:Angle  | 
+| Address             | address             | String        | 
+| Distance from Home  | home-distance       | Number:Length | 
 
 #### Remote Services
 
index b26cc0a965e6a86194529d040f40baec3b0d920d..ca8c257e6d9760bae60c97b221c854e691b52474 100644 (file)
@@ -114,6 +114,7 @@ public class MyBMWConstants {
     public static final String GPS = "gps";
     public static final String HEADING = "heading";
     public static final String ADDRESS = "address";
+    public static final String HOME_DISTANCE = "home-distance";
 
     // Status
     public static final String DOORS = "doors";
index 902d51e069ff8f8e0c3db30b221ab2ceb317f44d..22860f029979fec45ab18738384279c6a0328674 100644 (file)
@@ -20,6 +20,7 @@ import org.openhab.binding.mybmw.internal.handler.MyBMWBridgeHandler;
 import org.openhab.binding.mybmw.internal.handler.MyBMWCommandOptionProvider;
 import org.openhab.binding.mybmw.internal.handler.VehicleHandler;
 import org.openhab.core.i18n.LocaleProvider;
+import org.openhab.core.i18n.LocationProvider;
 import org.openhab.core.io.net.http.HttpClientFactory;
 import org.openhab.core.thing.Bridge;
 import org.openhab.core.thing.Thing;
@@ -42,14 +43,16 @@ import org.osgi.service.component.annotations.Reference;
 public class MyBMWHandlerFactory extends BaseThingHandlerFactory {
     private final HttpClientFactory httpClientFactory;
     private final MyBMWCommandOptionProvider commandOptionProvider;
+    private final LocationProvider locationProvider;
     private String localeLanguage;
 
     @Activate
     public MyBMWHandlerFactory(final @Reference HttpClientFactory hcf, final @Reference MyBMWCommandOptionProvider cop,
-            final @Reference LocaleProvider lp) {
+            final @Reference LocaleProvider localeP, final @Reference LocationProvider locationP) {
         httpClientFactory = hcf;
         commandOptionProvider = cop;
-        localeLanguage = lp.getLocale().getLanguage().toLowerCase();
+        locationProvider = locationP;
+        localeLanguage = localeP.getLocale().getLanguage().toLowerCase();
     }
 
     @Override
@@ -63,7 +66,8 @@ public class MyBMWHandlerFactory extends BaseThingHandlerFactory {
         if (THING_TYPE_CONNECTED_DRIVE_ACCOUNT.equals(thingTypeUID)) {
             return new MyBMWBridgeHandler((Bridge) thing, httpClientFactory, localeLanguage);
         } else if (SUPPORTED_THING_SET.contains(thingTypeUID)) {
-            VehicleHandler vh = new VehicleHandler(thing, commandOptionProvider, thingTypeUID.getId());
+            VehicleHandler vh = new VehicleHandler(thing, commandOptionProvider, locationProvider,
+                    thingTypeUID.getId());
             return vh;
         }
         return null;
index 9e74e3e9dd75917fe063a4c6f379cb99999c0a1f..6391a5e1aba1cc9e9c19a7aae0fe42c71983bde9 100644 (file)
@@ -18,6 +18,6 @@ package org.openhab.binding.mybmw.internal.dto.properties;
  * @author Bernd Weymann - Initial contribution
  */
 public class Coordinates {
-    public double latitude;// ": 50.556049,
-    public double longitude;// ": 8.495669
+    public double latitude;
+    public double longitude;
 }
index e19decfdd5a2e4d93f883451c181cfb6f068b3f0..167f5f3ca7d772d5226304efea510bae52691254 100644 (file)
@@ -20,5 +20,5 @@ package org.openhab.binding.mybmw.internal.dto.properties;
 public class Location {
     public Coordinates coordinates;
     public Address address;
-    public int heading;// ": 222
+    public int heading;
 }
index 1dec0d62e6bba98429621d31d151037780fffb33..3f380ce085e09ba4d7aa42973cdb3929bdabe106 100644 (file)
@@ -48,6 +48,7 @@ import org.openhab.binding.mybmw.internal.utils.Constants;
 import org.openhab.binding.mybmw.internal.utils.Converter;
 import org.openhab.binding.mybmw.internal.utils.RemoteServiceUtils;
 import org.openhab.binding.mybmw.internal.utils.VehicleStatusUtils;
+import org.openhab.core.i18n.LocationProvider;
 import org.openhab.core.library.types.DateTimeType;
 import org.openhab.core.library.types.DecimalType;
 import org.openhab.core.library.types.OnOffType;
@@ -55,6 +56,7 @@ import org.openhab.core.library.types.PointType;
 import org.openhab.core.library.types.QuantityType;
 import org.openhab.core.library.types.StringType;
 import org.openhab.core.library.unit.ImperialUnits;
+import org.openhab.core.library.unit.SIUnits;
 import org.openhab.core.library.unit.Units;
 import org.openhab.core.thing.ChannelUID;
 import org.openhab.core.thing.Thing;
@@ -87,17 +89,22 @@ public abstract class VehicleChannelHandler extends BaseThingHandler {
     protected String selectedSession = Constants.UNDEF;
 
     protected MyBMWCommandOptionProvider commandOptionProvider;
+    private LocationProvider locationProvider;
 
     // Data Caches
     protected Optional<String> vehicleStatusCache = Optional.empty();
     protected Optional<byte[]> imageCache = Optional.empty();
 
-    public VehicleChannelHandler(Thing thing, MyBMWCommandOptionProvider cop, String type) {
+    public VehicleChannelHandler(Thing thing, MyBMWCommandOptionProvider cop, LocationProvider lp, String type) {
         super(thing);
         commandOptionProvider = cop;
+        locationProvider = lp;
+        if (lp.getLocation() == null) {
+            logger.debug("Home location not available");
+        }
 
         hasFuel = type.equals(VehicleType.CONVENTIONAL.toString()) || type.equals(VehicleType.PLUGIN_HYBRID.toString())
-                || type.equals(VehicleType.ELECTRIC_REX.toString());
+                || type.equals(VehicleType.ELECTRIC_REX.toString()) || type.equals(VehicleType.MILD_HYBRID.toString());
         isElectric = type.equals(VehicleType.PLUGIN_HYBRID.toString())
                 || type.equals(VehicleType.ELECTRIC_REX.toString()) || type.equals(VehicleType.ELECTRIC.toString());
         isHybrid = hasFuel && isElectric;
@@ -448,9 +455,24 @@ public abstract class VehicleChannelHandler extends BaseThingHandler {
     }
 
     protected void updatePosition(Location pos) {
-        updateChannel(CHANNEL_GROUP_LOCATION, GPS, PointType
-                .valueOf(Double.toString(pos.coordinates.latitude) + "," + Double.toString(pos.coordinates.longitude)));
-        updateChannel(CHANNEL_GROUP_LOCATION, HEADING, QuantityType.valueOf(pos.heading, Units.DEGREE_ANGLE));
-        updateChannel(CHANNEL_GROUP_LOCATION, ADDRESS, StringType.valueOf(pos.address.formatted));
+        if (pos.coordinates.latitude < 0) {
+            updateChannel(CHANNEL_GROUP_LOCATION, GPS, UnDefType.UNDEF);
+            updateChannel(CHANNEL_GROUP_LOCATION, HEADING, UnDefType.UNDEF);
+            updateChannel(CHANNEL_GROUP_LOCATION, ADDRESS, UnDefType.UNDEF);
+            updateChannel(CHANNEL_GROUP_LOCATION, HOME_DISTANCE, UnDefType.UNDEF);
+        } else {
+            PointType vehicleLocation = PointType.valueOf(
+                    Double.toString(pos.coordinates.latitude) + "," + Double.toString(pos.coordinates.longitude));
+            updateChannel(CHANNEL_GROUP_LOCATION, GPS, vehicleLocation);
+            updateChannel(CHANNEL_GROUP_LOCATION, HEADING, QuantityType.valueOf(pos.heading, Units.DEGREE_ANGLE));
+            updateChannel(CHANNEL_GROUP_LOCATION, ADDRESS, StringType.valueOf(pos.address.formatted));
+            PointType homeLocation = locationProvider.getLocation();
+            if (homeLocation != null) {
+                updateChannel(CHANNEL_GROUP_LOCATION, HOME_DISTANCE,
+                        QuantityType.valueOf(vehicleLocation.distanceFrom(homeLocation).intValue(), SIUnits.METRE));
+            } else {
+                updateChannel(CHANNEL_GROUP_LOCATION, HOME_DISTANCE, UnDefType.UNDEF);
+            }
+        }
     }
 }
index c7b2da83dfd9d80d27a63ce7e49c302b4e24af20..53863a9ab79da15dc5d07978fa5c3a360496dc6a 100644 (file)
@@ -30,6 +30,7 @@ import org.openhab.binding.mybmw.internal.utils.Constants;
 import org.openhab.binding.mybmw.internal.utils.Converter;
 import org.openhab.binding.mybmw.internal.utils.ImageProperties;
 import org.openhab.binding.mybmw.internal.utils.RemoteServiceUtils;
+import org.openhab.core.i18n.LocationProvider;
 import org.openhab.core.io.net.http.HttpUtil;
 import org.openhab.core.library.types.RawType;
 import org.openhab.core.library.types.StringType;
@@ -64,8 +65,8 @@ public class VehicleHandler extends VehicleChannelHandler {
     ChargeSessionsCallback chargeSessionCallback = new ChargeSessionsCallback();
     ByteResponseCallback imageCallback = new ImageCallback();
 
-    public VehicleHandler(Thing thing, MyBMWCommandOptionProvider cop, String driveTrain) {
-        super(thing, cop, driveTrain);
+    public VehicleHandler(Thing thing, MyBMWCommandOptionProvider cop, LocationProvider lp, String driveTrain) {
+        super(thing, cop, lp, driveTrain);
     }
 
     @Override
index 6f8fa6d31944ef783e3e3fa08c705b6870daf3b6..6ae227ba6dc3e3325d13ba4fec7d4633149ceabd 100644 (file)
@@ -238,10 +238,10 @@ public class Converter {
         }
         if (v.properties.vehicleLocation == null) {
             v.properties.vehicleLocation = new Location();
-            v.properties.vehicleLocation.heading = -1;
+            v.properties.vehicleLocation.heading = Constants.INT_UNDEF;
             v.properties.vehicleLocation.coordinates = new Coordinates();
-            v.properties.vehicleLocation.coordinates.latitude = -1.234;
-            v.properties.vehicleLocation.coordinates.longitude = -9.876;
+            v.properties.vehicleLocation.coordinates.latitude = Constants.INT_UNDEF;
+            v.properties.vehicleLocation.coordinates.longitude = Constants.INT_UNDEF;
             v.properties.vehicleLocation.address = new Address();
             v.properties.vehicleLocation.address.formatted = Constants.UNDEF;
         }
index a4baeb1d4e974eb3053666e595d145b0750c57f1..f5a1129b036ad8bd0a9222402f3f934fab9a3499 100644 (file)
@@ -87,6 +87,8 @@ channel-type.mybmw.front-right-current-channel.label = Tire Pressure Front Right
 channel-type.mybmw.front-right-target-channel.label = Tire Pressure Front Right Target
 channel-type.mybmw.gps-channel.label = GPS Coordinates
 channel-type.mybmw.heading-channel.label = Heading Angle
+channel-type.mybmw.home-distance-channel.label = Distance from Home
+channel-type.mybmw.home-distance-channel.description = Computed distance between vehicle and home location
 channel-type.mybmw.hood-channel.label = Hood
 channel-type.mybmw.image-view-channel.label = Image Viewport
 channel-type.mybmw.image-view-channel.command.option.VehicleStatus = Front Side View
index 46cbbcf7156944352f77af464aab738d205ba829..94d97c72676a46c10009ec00a2ef24f04a2525c7 100644 (file)
@@ -10,6 +10,7 @@
                        <channel id="gps" typeId="gps-channel"/>
                        <channel id="heading" typeId="heading-channel"/>
                        <channel id="address" typeId="address-channel"/>
+                       <channel id="home-distance" typeId="home-distance-channel"/>
                </channels>
        </channel-group-type>
 </thing:thing-descriptions>
index 04fe7b5221293009589438d1ab9032037bb47928..df395e8a4cf01dc69e1044e2384c9239db8a0ddd 100644 (file)
                <item-type>String</item-type>
                <label>Address</label>
        </channel-type>
+       <channel-type id="home-distance-channel">
+               <item-type>Number:Length</item-type>
+               <label>Distance from Home</label>
+               <description>Computed distance between vehicle and home location</description>
+               <state pattern="%d %unit%" readOnly="true"/>
+       </channel-type>
 </thing:thing-descriptions>
index dabcd71ee1c56c25c90c633bef171e7a4c270c98..60799b06fcda9372f942d2aa6bc8d0c537258027 100644 (file)
@@ -27,6 +27,7 @@ import org.eclipse.jdt.annotation.Nullable;
 import org.openhab.binding.mybmw.internal.MyBMWConstants.VehicleType;
 import org.openhab.binding.mybmw.internal.dto.properties.CBS;
 import org.openhab.binding.mybmw.internal.dto.vehicle.Vehicle;
+import org.openhab.binding.mybmw.internal.handler.VehicleTests;
 import org.openhab.binding.mybmw.internal.utils.Constants;
 import org.openhab.binding.mybmw.internal.utils.Converter;
 import org.openhab.binding.mybmw.internal.utils.VehicleStatusUtils;
@@ -36,6 +37,7 @@ import org.openhab.core.library.types.PointType;
 import org.openhab.core.library.types.QuantityType;
 import org.openhab.core.library.types.StringType;
 import org.openhab.core.library.unit.ImperialUnits;
+import org.openhab.core.library.unit.SIUnits;
 import org.openhab.core.library.unit.Units;
 import org.openhab.core.thing.ChannelUID;
 import org.openhab.core.types.State;
@@ -60,7 +62,7 @@ public class StatusWrapper {
 
     public StatusWrapper(String type, String statusJson) {
         hasFuel = type.equals(VehicleType.CONVENTIONAL.toString()) || type.equals(VehicleType.PLUGIN_HYBRID.toString())
-                || type.equals(VehicleType.ELECTRIC_REX.toString());
+                || type.equals(VehicleType.ELECTRIC_REX.toString()) || type.equals(VehicleType.MILD_HYBRID.toString());
         isElectric = type.equals(VehicleType.PLUGIN_HYBRID.toString())
                 || type.equals(VehicleType.ELECTRIC_REX.toString()) || type.equals(VehicleType.ELECTRIC.toString());
         isHybrid = hasFuel && isElectric;
@@ -246,20 +248,22 @@ public class StatusWrapper {
                 assertEquals(expected.toString(), dtt.toString(), "Last Update");
                 break;
             case GPS:
-                assertTrue(state instanceof PointType);
-                pt = (PointType) state;
-                assertNotNull(vehicle.properties.vehicleLocation);
-                assertEquals(
-                        PointType.valueOf(Double.toString(vehicle.properties.vehicleLocation.coordinates.latitude) + ","
-                                + Double.toString(vehicle.properties.vehicleLocation.coordinates.longitude)),
-                        pt, "Coordinates");
+                if (state instanceof PointType) {
+                    pt = (PointType) state;
+                    assertNotNull(vehicle.properties.vehicleLocation);
+                    assertEquals(
+                            PointType.valueOf(Double.toString(vehicle.properties.vehicleLocation.coordinates.latitude)
+                                    + "," + Double.toString(vehicle.properties.vehicleLocation.coordinates.longitude)),
+                            pt, "Coordinates");
+                } // else no check needed
                 break;
             case HEADING:
-                assertTrue(state instanceof QuantityType);
-                qt = ((QuantityType) state);
-                assertEquals(Units.DEGREE_ANGLE, qt.getUnit(), "Angle Unit");
-                assertNotNull(vehicle.properties.vehicleLocation);
-                assertEquals(vehicle.properties.vehicleLocation.heading, qt.intValue(), 0.01, "Heading");
+                if (state instanceof QuantityType) {
+                    qt = ((QuantityType) state);
+                    assertEquals(Units.DEGREE_ANGLE, qt.getUnit(), "Angle Unit");
+                    assertNotNull(vehicle.properties.vehicleLocation);
+                    assertEquals(vehicle.properties.vehicleLocation.heading, qt.intValue(), 0.01, "Heading");
+                } // else no check needed
                 break;
             case RANGE_RADIUS_ELECTRIC:
                 assertTrue(state instanceof QuantityType);
@@ -568,10 +572,22 @@ public class StatusWrapper {
                 }
                 break;
             case ADDRESS:
-                assertTrue(state instanceof StringType);
-                st = (StringType) state;
-                assertEquals(st.toFullString(), vehicle.properties.vehicleLocation.address.formatted,
-                        "Location Address");
+                if (state instanceof StringType) {
+                    st = (StringType) state;
+                    assertEquals(st.toFullString(), vehicle.properties.vehicleLocation.address.formatted,
+                            "Location Address");
+                } // else no check needed
+                break;
+            case HOME_DISTANCE:
+                if (state instanceof QuantityType) {
+                    qt = (QuantityType) state;
+                    PointType vehicleLocation = PointType
+                            .valueOf(Double.toString(vehicle.properties.vehicleLocation.coordinates.latitude) + ","
+                                    + Double.toString(vehicle.properties.vehicleLocation.coordinates.longitude));
+                    int distance = vehicleLocation.distanceFrom(VehicleTests.HOME_LOCATION).intValue();
+                    assertEquals(qt.intValue(), distance, "Distance from Home");
+                    assertEquals(qt.getUnit(), SIUnits.METRE, "Distance from Home Unit");
+                } // else no check needed
                 break;
             case RAW:
                 // don't assert raw channel
index 80f8f1ed88855006ea4bfa8e5a5b626ae7f3fe4d..351eb93c10a549549ab9f310f3ac928edc78d10a 100644 (file)
@@ -62,7 +62,7 @@ public class VehicleStatusTest {
         assertEquals("BMW", v.brand, "Car brand");
         assertEquals(true, v.properties.areDoorsClosed, "Doors Closed");
         assertEquals(76, v.properties.electricRange.distance.value, "Electric Range");
-        assertEquals(6.789, v.properties.vehicleLocation.coordinates.longitude, 0.1, "Location lon");
+        assertEquals(9.876, v.properties.vehicleLocation.coordinates.longitude, 0.1, "Location lon");
         assertEquals("immediateCharging", v.status.chargingProfile.chargingMode, "Charging Mode");
         assertEquals(2, v.status.chargingProfile.getTimerId(2).id, "Timer ID");
         assertEquals("[sunday]", v.status.chargingProfile.getTimerId(2).timerWeekDays.toString(), "Timer Weekdays");
index 0770483b5240def6fa826a78032c04f8e7ba7df2..1e31cd93ce5e03f3aed938028c7f2a266455e285 100644 (file)
@@ -28,6 +28,7 @@ import org.openhab.binding.mybmw.internal.VehicleConfiguration;
 import org.openhab.binding.mybmw.internal.dto.ChargeStatisticWrapper;
 import org.openhab.binding.mybmw.internal.util.FileReader;
 import org.openhab.binding.mybmw.internal.utils.Constants;
+import org.openhab.core.i18n.LocationProvider;
 import org.openhab.core.thing.ChannelUID;
 import org.openhab.core.thing.Thing;
 import org.openhab.core.thing.ThingUID;
@@ -73,7 +74,8 @@ public class ChargeStatisticsTest {
         Thing thing = mock(Thing.class);
         when(thing.getUID()).thenReturn(new ThingUID("testbinding", "test"));
         MyBMWCommandOptionProvider cop = mock(MyBMWCommandOptionProvider.class);
-        cch = new VehicleHandler(thing, cop, type);
+        LocationProvider locationProvider = mock(LocationProvider.class);
+        cch = new VehicleHandler(thing, cop, locationProvider, type);
         VehicleConfiguration vc = new VehicleConfiguration();
         vc.vin = Constants.ANONYMOUS;
         Optional<VehicleConfiguration> ovc = Optional.of(vc);
index 50db2bdc5b6ca8d63b35c7adcdfd8d546aa33fd0..cdd40384a7cd1cdb9e4db9b4671be297aca7f438 100644 (file)
@@ -20,6 +20,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.junit.jupiter.api.Test;
 import org.mockito.ArgumentCaptor;
+import org.openhab.core.i18n.LocationProvider;
 import org.openhab.core.thing.ChannelUID;
 import org.openhab.core.thing.Thing;
 import org.openhab.core.thing.ThingUID;
@@ -60,7 +61,8 @@ public class ErrorResponseTest {
         Thing thing = mock(Thing.class);
         when(thing.getUID()).thenReturn(new ThingUID("testbinding", "test"));
         MyBMWCommandOptionProvider cop = mock(MyBMWCommandOptionProvider.class);
-        cch = new VehicleHandler(thing, cop, type);
+        LocationProvider locationProvider = mock(LocationProvider.class);
+        cch = new VehicleHandler(thing, cop, locationProvider, type);
         tc = mock(ThingHandlerCallback.class);
         cch.setCallback(tc);
         channelCaptor = ArgumentCaptor.forClass(ChannelUID.class);
index 80363a6d18f81791d2a5004ed9cff0645aa5f405..da675ae85abc70499d33cc2b9553cc546d20a9a2 100644 (file)
@@ -28,6 +28,8 @@ import org.openhab.binding.mybmw.internal.VehicleConfiguration;
 import org.openhab.binding.mybmw.internal.dto.StatusWrapper;
 import org.openhab.binding.mybmw.internal.util.FileReader;
 import org.openhab.binding.mybmw.internal.utils.Constants;
+import org.openhab.core.i18n.LocationProvider;
+import org.openhab.core.library.types.PointType;
 import org.openhab.core.thing.ChannelUID;
 import org.openhab.core.thing.Thing;
 import org.openhab.core.thing.ThingUID;
@@ -57,10 +59,10 @@ public class VehicleTests {
     private static final int CHECK_AVAILABLE = 3;
     private static final int SERVICE_AVAILABLE = 3;
     private static final int SERVICE_EMPTY = 3;
-    private static final int LOCATION = 3;
+    private static final int LOCATION = 4;
     private static final int CHARGE_PROFILE = 44;
     private static final int TIRES = 8;
-
+    public static final PointType HOME_LOCATION = new PointType("54.321,9.876");
     @Nullable
     ArgumentCaptor<ChannelUID> channelCaptor;
     @Nullable
@@ -83,7 +85,9 @@ public class VehicleTests {
         Thing thing = mock(Thing.class);
         when(thing.getUID()).thenReturn(new ThingUID("testbinding", "test"));
         MyBMWCommandOptionProvider cop = mock(MyBMWCommandOptionProvider.class);
-        cch = new VehicleHandler(thing, cop, type);
+        LocationProvider locationProvider = mock(LocationProvider.class);
+        when(locationProvider.getLocation()).thenReturn(HOME_LOCATION);
+        cch = new VehicleHandler(thing, cop, locationProvider, type);
         VehicleConfiguration vc = new VehicleConfiguration();
         vc.vin = vin;
         Optional<VehicleConfiguration> ovc = Optional.of(vc);
@@ -332,9 +336,7 @@ public class VehicleTests {
         logger.info("{}", Thread.currentThread().getStackTrace()[1].getMethodName());
         setup(VehicleType.MILD_HYBRID.toString(), "anonymous");
         String content = FileReader.readFileInString("src/test/resources/responses/G21/340i.json");
-        assertTrue(testVehicle(content, 38, Optional.empty()));
-        // assertTrue(testVehicle(content,
-        // STATUS_CONV + DOORS + RANGE_CONV + SERVICE_AVAILABLE + CHECK_EMPTY + LOCATION + TIRES,
-        // Optional.empty()));
+        assertTrue(testVehicle(content,
+                STATUS_CONV + DOORS + RANGE_CONV + LOCATION + SERVICE_EMPTY + CHECK_EMPTY + TIRES, Optional.empty()));
     }
 }
index a822abefd9ae58f997fcadab0706b83abf0330c8..15afdbad8ca5457aaa6131887f6480ee3a756f02 100644 (file)
                        ],
                        "vehicleLocation": {
                                "coordinates": {
-                                       "latitude": 1.2345,
-                                       "longitude": 6.789
+                                       "latitude": 54.321,
+                                       "longitude": 9.876
                                },
                                "address": {
                                        "formatted": "anonymous"