]> git.basschouten.com Git - openhab-addons.git/blob
ade56576842ce8927883a119362997c0c3084085
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.mercedesme.internal.handler;
14
15 import static org.junit.jupiter.api.Assertions.*;
16 import static org.mockito.Mockito.*;
17
18 import java.util.Optional;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.junit.jupiter.api.Test;
22 import org.openhab.binding.mercedesme.FileReader;
23 import org.openhab.binding.mercedesme.internal.Constants;
24 import org.openhab.binding.mercedesme.internal.MercedesMeCommandOptionProvider;
25 import org.openhab.binding.mercedesme.internal.MercedesMeStateOptionProvider;
26 import org.openhab.binding.mercedesme.internal.config.VehicleConfiguration;
27 import org.openhab.binding.mercedesme.internal.utils.Utils;
28 import org.openhab.core.events.EventPublisher;
29 import org.openhab.core.library.types.DateTimeType;
30 import org.openhab.core.library.types.DecimalType;
31 import org.openhab.core.library.types.QuantityType;
32 import org.openhab.core.thing.ChannelUID;
33 import org.openhab.core.thing.Thing;
34 import org.openhab.core.thing.ThingUID;
35 import org.openhab.core.thing.i18n.ChannelTypeI18nLocalizationService;
36 import org.openhab.core.thing.link.ItemChannelLinkRegistry;
37 import org.openhab.core.types.RefreshType;
38
39 import com.daimler.mbcarkit.proto.VehicleEvents.VEPUpdate;
40
41 /**
42  * {@link VehicleHandlerTest} check state updates and command sending of vehicles
43  *
44  * @author Bernd Weymann - Initial contribution
45  */
46 @NonNullByDefault
47 class VehicleHandlerTest {
48
49     @Test
50     public void testBEVFullUpdateNoCapacities() {
51         Thing thingMock = mock(Thing.class);
52         when(thingMock.getThingTypeUID()).thenReturn(Constants.THING_TYPE_BEV);
53         when(thingMock.getUID()).thenReturn(new ThingUID("test", Constants.BEV));
54         VehicleHandler vh = new VehicleHandler(thingMock, new LocationProviderMock(),
55                 mock(MercedesMeCommandOptionProvider.class), mock(MercedesMeStateOptionProvider.class));
56         vh.accountHandler = Optional.of(mock(AccountHandler.class));
57         VehicleConfiguration vehicleConfig = new VehicleConfiguration();
58         vh.config = Optional.of(vehicleConfig);
59         ThingCallbackListener updateListener = new ThingCallbackListener();
60         vh.setCallback(updateListener);
61
62         String json = FileReader.readFileInString("src/test/resources/proto-json/MB-BEV-EQA.json");
63         VEPUpdate update = ProtoConverter.json2Proto(json, true);
64         vh.distributeContent(update);
65
66         assertEquals(11, updateListener.updatesPerGroupMap.size(), "Group Update Count");
67         assertEquals(10, updateListener.getUpdatesForGroup("doors"), "Doors Update Count");
68         assertEquals(5, updateListener.getUpdatesForGroup("vehicle"), "Vehcile Update Count");
69         assertEquals(8, updateListener.getUpdatesForGroup("windows"), "Windows Update Count");
70         assertEquals(12, updateListener.getUpdatesForGroup("trip"), "Trip Update Count");
71         assertEquals(10, updateListener.getUpdatesForGroup("tires"), "Tire Update Count");
72         assertEquals(6, updateListener.getUpdatesForGroup("service"), "Service Update Count");
73         assertEquals(7, updateListener.getUpdatesForGroup("range"), "Range Update Count");
74         assertEquals(2, updateListener.getUpdatesForGroup("position"), "Position Update Count");
75         assertEquals(5, updateListener.getUpdatesForGroup("lock"), "Lock Update Count");
76         assertEquals(7, updateListener.getUpdatesForGroup("hvac"), "HVAC Update Count");
77         assertEquals(10, updateListener.getUpdatesForGroup("charge"), "Charge Update Count");
78     }
79
80     @Test
81     public void testBEVImperialUnits() {
82         Thing thingMock = mock(Thing.class);
83         when(thingMock.getThingTypeUID()).thenReturn(Constants.THING_TYPE_BEV);
84         when(thingMock.getUID()).thenReturn(new ThingUID("test", Constants.BEV));
85         MercedesMeDynamicStateDescriptionProviderMock<?> patternMock = new MercedesMeDynamicStateDescriptionProviderMock<>(
86                 mock(EventPublisher.class), mock(ItemChannelLinkRegistry.class),
87                 mock(ChannelTypeI18nLocalizationService.class));
88         MercedesMeCommandOptionProviderMock commandOptionMock = new MercedesMeCommandOptionProviderMock();
89         VehicleHandler vh = new VehicleHandler(thingMock, new LocationProviderMock(), commandOptionMock, patternMock);
90
91         AccountHandlerMock ahm = new AccountHandlerMock();
92         vh.accountHandler = Optional.of(ahm);
93         VehicleConfiguration vehicleConfig = new VehicleConfiguration();
94         vh.config = Optional.of(vehicleConfig);
95         ThingCallbackListener updateListener = new ThingCallbackListener();
96         vh.setCallback(updateListener);
97
98         String json = FileReader.readFileInString("src/test/resources/proto-json/MB-BEV-ImperialUnits.json");
99         VEPUpdate update = ProtoConverter.json2Proto(json, true);
100         vh.distributeContent(update);
101
102         assertEquals(11, updateListener.updatesPerGroupMap.size(), "Group Update Count");
103         assertEquals(10, updateListener.getUpdatesForGroup("doors"), "Doors Update Count");
104         assertEquals(5, updateListener.getUpdatesForGroup("vehicle"), "Vehcile Update Count");
105         assertEquals(8, updateListener.getUpdatesForGroup("windows"), "Windows Update Count");
106         assertEquals(12, updateListener.getUpdatesForGroup("trip"), "Trip Update Count");
107         assertEquals(10, updateListener.getUpdatesForGroup("tires"), "Tire Update Count");
108         assertEquals(6, updateListener.getUpdatesForGroup("service"), "Service Update Count");
109         assertEquals(7, updateListener.getUpdatesForGroup("range"), "Range Update Count");
110         assertEquals(2, updateListener.getUpdatesForGroup("position"), "Position Update Count");
111         assertEquals(5, updateListener.getUpdatesForGroup("lock"), "Lock Update Count");
112         assertEquals(7, updateListener.getUpdatesForGroup("hvac"), "HVAC Update Count");
113         assertEquals(10, updateListener.getUpdatesForGroup("charge"), "Charge Update Count");
114         assertTrue(updateListener.getResponse("test::bev:range#mileage").toFullString().endsWith("mi"),
115                 "Mileague Unit");
116         assertTrue(updateListener.getResponse("test::bev:range#range-electric").toFullString().endsWith("mi"),
117                 "Range Electric Unit");
118         assertTrue(updateListener.getResponse("test::bev:trip#distance").toFullString().endsWith("mi"),
119                 "Range Electric Unit");
120         assertTrue(updateListener.getResponse("test::bev:tires#pressure-front-left").toFullString().endsWith("psi"),
121                 "Pressure Unit");
122         assertTrue(updateListener.getResponse("test::bev:hvac#temperature").toFullString().endsWith("°F"),
123                 "Temperature Unit");
124         assertEquals("%.0f °F", patternMock.patternMap.get("test::bev:hvac#temperature"), "Temperature Pattern");
125         commandOptionMock.getCommandList("test::bev:hvac#temperature").forEach(cmd -> {
126             assertTrue(cmd.getCommand().endsWith(" °F"), "Command Option Fahrenheit Unit");
127         });
128
129         // overwrite with EU Units
130         json = FileReader.readFileInString("src/test/resources/proto-json/MB-BEV-EQA.json");
131         update = ProtoConverter.json2Proto(json, true);
132         vh.distributeContent(update);
133         assertEquals("%.1f °C", patternMock.patternMap.get("test::bev:hvac#temperature"), "Temperature Pattern");
134         commandOptionMock.getCommandList("test::bev:hvac#temperature").forEach(cmd -> {
135             assertTrue(cmd.getCommand().endsWith(" °C"), "Command Option Celsius Unit");
136         });
137     }
138
139     @Test
140     public void testBEVCharging() {
141         Thing thingMock = mock(Thing.class);
142         when(thingMock.getThingTypeUID()).thenReturn(Constants.THING_TYPE_BEV);
143         when(thingMock.getUID()).thenReturn(new ThingUID("test", Constants.BEV));
144         VehicleHandler vh = new VehicleHandler(thingMock, new LocationProviderMock(),
145                 mock(MercedesMeCommandOptionProvider.class), mock(MercedesMeStateOptionProvider.class));
146         vh.accountHandler = Optional.of(mock(AccountHandler.class));
147         VehicleConfiguration vehicleConfig = new VehicleConfiguration();
148         vh.config = Optional.of(vehicleConfig);
149         ThingCallbackListener updateListener = new ThingCallbackListener();
150         vh.setCallback(updateListener);
151
152         String json = FileReader.readFileInString("src/test/resources/proto-json/MB-BEV-EQA-Charging.json");
153         VEPUpdate update = ProtoConverter.json2Proto(json, true);
154         vh.distributeContent(update);
155
156         assertEquals(11, updateListener.updatesPerGroupMap.size(), "Group Update Count");
157         assertEquals(10, updateListener.getUpdatesForGroup("doors"), "Doors Update Count");
158         assertEquals(5, updateListener.getUpdatesForGroup("vehicle"), "Vehcile Update Count");
159         assertEquals(8, updateListener.getUpdatesForGroup("windows"), "Windows Update Count");
160         assertEquals(12, updateListener.getUpdatesForGroup("trip"), "Trip Update Count");
161         assertEquals(10, updateListener.getUpdatesForGroup("tires"), "Tire Update Count");
162         assertEquals(6, updateListener.getUpdatesForGroup("service"), "Service Update Count");
163         assertEquals(7, updateListener.getUpdatesForGroup("range"), "Range Update Count");
164         assertEquals(2, updateListener.getUpdatesForGroup("position"), "Position Update Count");
165         assertEquals(5, updateListener.getUpdatesForGroup("lock"), "Lock Update Count");
166         assertEquals(7, updateListener.getUpdatesForGroup("hvac"), "HVAC Update Count");
167         assertEquals(10, updateListener.getUpdatesForGroup("charge"), "Charge Update Count");
168         assertEquals("2023-09-06 13:55", ((DateTimeType) updateListener.getResponse("test::bev:charge#end-time"))
169                 .format("%1$tY-%1$tm-%1$td %1$tH:%1$tM"), "End of Charge Time");
170     }
171
172     @Test
173     public void testBEVPartialChargingUpdate() {
174         Thing thingMock = mock(Thing.class);
175         when(thingMock.getThingTypeUID()).thenReturn(Constants.THING_TYPE_BEV);
176         when(thingMock.getUID()).thenReturn(new ThingUID("test", Constants.BEV));
177         VehicleHandler vh = new VehicleHandler(thingMock, new LocationProviderMock(),
178                 mock(MercedesMeCommandOptionProvider.class), mock(MercedesMeStateOptionProvider.class));
179         vh.accountHandler = Optional.of(mock(AccountHandler.class));
180         VehicleConfiguration vehicleConfig = new VehicleConfiguration();
181         vh.config = Optional.of(vehicleConfig);
182         ThingCallbackListener updateListener = new ThingCallbackListener();
183         vh.setCallback(updateListener);
184
185         String json = FileReader.readFileInString("src/test/resources/proto-json/PartialUpdate-Charging.json");
186         VEPUpdate update = ProtoConverter.json2Proto(json, false);
187         vh.distributeContent(update);
188         assertEquals(2, updateListener.updatesReceived.size(), "Update Count");
189         assertEquals("2023-09-19 20:45", ((DateTimeType) updateListener.getResponse("test::bev:charge#end-time"))
190                 .format("%1$tY-%1$tm-%1$td %1$tH:%1$tM"), "End of Charge Time");
191         assertEquals("2.1 kW", updateListener.getResponse("test::bev:charge#power").toFullString(), "Charge Power");
192     }
193
194     @Test
195     public void testBEVPartialGPSUpdate() {
196         Thing thingMock = mock(Thing.class);
197         when(thingMock.getThingTypeUID()).thenReturn(Constants.THING_TYPE_BEV);
198         when(thingMock.getUID()).thenReturn(new ThingUID("test", Constants.BEV));
199         VehicleHandler vh = new VehicleHandler(thingMock, new LocationProviderMock(),
200                 mock(MercedesMeCommandOptionProvider.class), mock(MercedesMeStateOptionProvider.class));
201         vh.accountHandler = Optional.of(mock(AccountHandler.class));
202         VehicleConfiguration vehicleConfig = new VehicleConfiguration();
203         vh.config = Optional.of(vehicleConfig);
204         ThingCallbackListener updateListener = new ThingCallbackListener();
205         vh.setCallback(updateListener);
206
207         String json = FileReader.readFileInString("src/test/resources/proto-json/PartialUpdate-GPS.json");
208         VEPUpdate update = ProtoConverter.json2Proto(json, false);
209         vh.distributeContent(update);
210         assertEquals(3, updateListener.updatesReceived.size(), "Update Count");
211         assertEquals("1.23,4.56", updateListener.getResponse("test::bev:position#gps").toFullString(), "GPS update");
212         assertEquals("41.9 °", updateListener.getResponse("test::bev:position#heading").toFullString(),
213                 "Heading Update");
214     }
215
216     @Test
217     public void testBEVPartialRangeUpdate() {
218         Thing thingMock = mock(Thing.class);
219         when(thingMock.getThingTypeUID()).thenReturn(Constants.THING_TYPE_BEV);
220         when(thingMock.getUID()).thenReturn(new ThingUID("test", Constants.BEV));
221         VehicleHandler vh = new VehicleHandler(thingMock, new LocationProviderMock(),
222                 mock(MercedesMeCommandOptionProvider.class), mock(MercedesMeStateOptionProvider.class));
223         vh.accountHandler = Optional.of(mock(AccountHandler.class));
224         VehicleConfiguration vehicleConfig = new VehicleConfiguration();
225         vh.config = Optional.of(vehicleConfig);
226         ThingCallbackListener updateListener = new ThingCallbackListener();
227         vh.setCallback(updateListener);
228
229         String json = FileReader.readFileInString("src/test/resources/proto-json/PartialUpdate-Range.json");
230         VEPUpdate update = ProtoConverter.json2Proto(json, false);
231         vh.distributeContent(update);
232         assertEquals(3, updateListener.updatesReceived.size(), "Update Count");
233         assertEquals("15017 km", updateListener.getResponse("test::bev:range#mileage").toFullString(),
234                 "Mileage Update");
235         assertEquals("246 km", updateListener.getResponse("test::bev:range#radius-electric").toFullString(),
236                 "Range Update");
237         assertEquals("307 km", updateListener.getResponse("test::bev:range#range-electric").toFullString(),
238                 "Range Radius Update");
239     }
240
241     @Test
242     public void testHybridFullUpdateNoCapacities() {
243         Thing thingMock = mock(Thing.class);
244         when(thingMock.getThingTypeUID()).thenReturn(Constants.THING_TYPE_HYBRID);
245         when(thingMock.getUID()).thenReturn(new ThingUID("test", Constants.HYBRID));
246         VehicleHandler vh = new VehicleHandler(thingMock, new LocationProviderMock(),
247                 mock(MercedesMeCommandOptionProvider.class), mock(MercedesMeStateOptionProvider.class));
248         vh.accountHandler = Optional.of(mock(AccountHandler.class));
249         VehicleConfiguration vehicleConfig = new VehicleConfiguration();
250         vh.config = Optional.of(vehicleConfig);
251         ThingCallbackListener updateListener = new ThingCallbackListener();
252         vh.setCallback(updateListener);
253
254         String json = FileReader.readFileInString("src/test/resources/proto-json/MB-Hybrid-Charging.json");
255         VEPUpdate update = ProtoConverter.json2Proto(json, true);
256         vh.distributeContent(update);
257
258         assertEquals(11, updateListener.updatesPerGroupMap.size(), "Group Update Count");
259         assertEquals(10, updateListener.getUpdatesForGroup("doors"), "Doors Update Count");
260         assertEquals(5, updateListener.getUpdatesForGroup("vehicle"), "Vehcile Update Count");
261         assertEquals(8, updateListener.getUpdatesForGroup("windows"), "Windows Update Count");
262         assertEquals(12, updateListener.getUpdatesForGroup("trip"), "Trip Update Count");
263         assertEquals(10, updateListener.getUpdatesForGroup("tires"), "Trip Update Count");
264         assertEquals(8, updateListener.getUpdatesForGroup("service"), "Trip Update Count");
265         assertEquals(14, updateListener.getUpdatesForGroup("range"), "Update Upadte Count");
266         assertEquals(2, updateListener.getUpdatesForGroup("position"), "Update Upadte Count");
267         assertEquals(6, updateListener.getUpdatesForGroup("lock"), "Lock Update Count");
268         assertEquals(7, updateListener.getUpdatesForGroup("hvac"), "HVAC Update Count");
269         assertEquals(7, updateListener.getUpdatesForGroup("charge"), "Charge Update Count");
270     }
271
272     @Test
273     public void testHybridFullUpadteWithCapacities() {
274         Thing thingMock = mock(Thing.class);
275         when(thingMock.getThingTypeUID()).thenReturn(Constants.THING_TYPE_HYBRID);
276         when(thingMock.getUID()).thenReturn(new ThingUID("test", "hybrid"));
277         VehicleHandler vh = new VehicleHandler(thingMock, new LocationProviderMock(),
278                 mock(MercedesMeCommandOptionProvider.class), mock(MercedesMeStateOptionProvider.class));
279         vh.accountHandler = Optional.of(mock(AccountHandler.class));
280         VehicleConfiguration vehicleConfig = new VehicleConfiguration();
281         vehicleConfig.batteryCapacity = (float) 9.2;
282         vehicleConfig.fuelCapacity = (float) 59.9;
283         vh.config = Optional.of(vehicleConfig);
284         ThingCallbackListener updateListener = new ThingCallbackListener();
285         vh.setCallback(updateListener);
286
287         String json = FileReader.readFileInString("src/test/resources/proto-json/MB-Hybrid-Charging.json");
288         VEPUpdate update = ProtoConverter.json2Proto(json, true);
289         vh.distributeContent(update);
290
291         // Test charged / uncharged battery and filled / unfilled tank volume
292         assertEquals("5.800000190734863 kWh", updateListener.getResponse("test::hybrid:range#charged").toFullString(),
293                 "Battery Charged Update");
294         assertEquals("3.4000000953674316 kWh",
295                 updateListener.getResponse("test::hybrid:range#uncharged").toFullString(), "Battery Uncharged Update");
296         assertEquals("9.579999923706055 l", updateListener.getResponse("test::hybrid:range#tank-remain").toFullString(),
297                 "Tank Remain Update");
298         assertEquals("50.31999969482422 l", updateListener.getResponse("test::hybrid:range#tank-open").toFullString(),
299                 "Tank Open Update");
300     }
301
302     @Test
303     public void testEventStorage() {
304         Thing thingMock = mock(Thing.class);
305         when(thingMock.getThingTypeUID()).thenReturn(Constants.THING_TYPE_BEV);
306         when(thingMock.getUID()).thenReturn(new ThingUID("test", Constants.BEV));
307         VehicleHandler vh = new VehicleHandler(thingMock, new LocationProviderMock(),
308                 mock(MercedesMeCommandOptionProvider.class), mock(MercedesMeStateOptionProvider.class));
309         vh.accountHandler = Optional.of(mock(AccountHandler.class));
310         VehicleConfiguration vehicleConfig = new VehicleConfiguration();
311         vh.config = Optional.of(vehicleConfig);
312         ThingCallbackListener updateListener = new ThingCallbackListener();
313         updateListener.linked = true;
314         vh.setCallback(updateListener);
315
316         String json = FileReader.readFileInString("src/test/resources/proto-json/MB-BEV-EQA.json");
317         VEPUpdate update = ProtoConverter.json2Proto(json, true);
318         vh.distributeContent(update);
319
320         assertEquals(11, updateListener.updatesPerGroupMap.size(), "Group Update Count");
321         assertEquals(10, updateListener.getUpdatesForGroup("doors"), "Doors Update Count");
322         // 1 update more due to proto channel connected
323         // assertEquals(6, updateListener.getUpdatesForGroup("vehicle"), "Vehcile Update Count");
324         assertEquals(8, updateListener.getUpdatesForGroup("windows"), "Windows Update Count");
325         assertEquals(12, updateListener.getUpdatesForGroup("trip"), "Trip Update Count");
326         assertEquals(10, updateListener.getUpdatesForGroup("tires"), "Tire Update Count");
327         assertEquals(6, updateListener.getUpdatesForGroup("service"), "Service Update Count");
328         assertEquals(7, updateListener.getUpdatesForGroup("range"), "Range Update Count");
329         assertEquals(2, updateListener.getUpdatesForGroup("position"), "Position Update Count");
330         assertEquals(5, updateListener.getUpdatesForGroup("lock"), "Lock Update Count");
331         assertEquals(7, updateListener.getUpdatesForGroup("hvac"), "HVAC Update Count");
332         assertEquals(10, updateListener.getUpdatesForGroup("charge"), "Charge Update Count");
333
334         /**
335          * VehicleHandler fully updated eventStorage shall contain all data
336          * Let's simulate an item ad causing a RefreshType command
337          * Shall deliver data immediately
338          */
339         assertEquals(83, vh.eventStorage.size());
340         assertEquals(83, updateListener.updatesReceived.size());
341         updateListener = new ThingCallbackListener();
342         vh.setCallback(updateListener);
343         ChannelUID mileageChannelUID = new ChannelUID(new ThingUID("test", Constants.BEV), Constants.GROUP_RANGE,
344                 "mileage");
345
346         vh.handleCommand(mileageChannelUID, RefreshType.REFRESH);
347         assertEquals(1, updateListener.updatesReceived.size());
348     }
349
350     @Test
351     public void testProtoChannelLinked() {
352         Thing thingMock = mock(Thing.class);
353         when(thingMock.getThingTypeUID()).thenReturn(Constants.THING_TYPE_BEV);
354         when(thingMock.getUID()).thenReturn(new ThingUID("test", Constants.BEV));
355         VehicleHandler vh = new VehicleHandler(thingMock, new LocationProviderMock(),
356                 mock(MercedesMeCommandOptionProvider.class), mock(MercedesMeStateOptionProvider.class));
357         vh.accountHandler = Optional.of(mock(AccountHandler.class));
358         VehicleConfiguration vehicleConfig = new VehicleConfiguration();
359         vh.config = Optional.of(vehicleConfig);
360         ThingCallbackListener updateListener = new ThingCallbackListener();
361         vh.setCallback(updateListener);
362
363         String json = FileReader.readFileInString("src/test/resources/proto-json/MB-BEV-EQA.json");
364         VEPUpdate update = ProtoConverter.json2Proto(json, true);
365         vh.distributeContent(update);
366         assertFalse(updateListener.updatesReceived.containsKey("test::bev:vehicle#proto-update"),
367                 "Proto Channel not updated");
368
369         updateListener.linked = true;
370         vh.distributeContent(update);
371         assertTrue(updateListener.updatesReceived.containsKey("test::bev:vehicle#proto-update"),
372                 "Proto Channel not updated");
373     }
374
375     @Test
376     public void testTemperaturePoints() {
377         Thing thingMock = mock(Thing.class);
378         when(thingMock.getThingTypeUID()).thenReturn(Constants.THING_TYPE_BEV);
379         when(thingMock.getUID()).thenReturn(new ThingUID("test", Constants.BEV));
380         VehicleHandler vh = new VehicleHandler(thingMock, new LocationProviderMock(),
381                 mock(MercedesMeCommandOptionProvider.class), mock(MercedesMeStateOptionProvider.class));
382         vh.accountHandler = Optional.of(mock(AccountHandler.class));
383         VehicleConfiguration vehicleConfig = new VehicleConfiguration();
384         vh.config = Optional.of(vehicleConfig);
385         ThingCallbackListener updateListener = new ThingCallbackListener();
386         vh.setCallback(updateListener);
387
388         String json = FileReader.readFileInString("src/test/resources/proto-json/MB-Unknown.json");
389         VEPUpdate update = ProtoConverter.json2Proto(json, true);
390         vh.distributeContent(update);
391         assertEquals("22 °C", updateListener.getResponse("test::bev:hvac#temperature").toFullString(),
392                 "Temperature Point One Updated");
393
394         ChannelUID cuid = new ChannelUID(thingMock.getUID(), Constants.GROUP_HVAC, "zone");
395         updateListener = new ThingCallbackListener();
396         vh.setCallback(updateListener);
397         vh.handleCommand(cuid, new DecimalType(2));
398         assertEquals("2", updateListener.getResponse("test::bev:hvac#zone").toFullString(),
399                 "Temperature Point One Updated");
400         assertEquals("19 °C", updateListener.getResponse("test::bev:hvac#temperature").toFullString(),
401                 "Temperature Point One Updated");
402         vh.handleCommand(cuid, new DecimalType(-1));
403     }
404
405     @Test
406     public void testTemperaturePointSelection() {
407         Thing thingMock = mock(Thing.class);
408         when(thingMock.getThingTypeUID()).thenReturn(Constants.THING_TYPE_BEV);
409         when(thingMock.getUID()).thenReturn(new ThingUID("test", Constants.BEV));
410         AccountHandlerMock ahm = new AccountHandlerMock();
411         VehicleHandler vh = new VehicleHandler(thingMock, new LocationProviderMock(),
412                 mock(MercedesMeCommandOptionProvider.class), mock(MercedesMeStateOptionProvider.class));
413         vh.accountHandler = Optional.of(ahm);
414         VehicleConfiguration vehicleConfig = new VehicleConfiguration();
415         vh.config = Optional.of(vehicleConfig);
416         ThingCallbackListener updateListener = new ThingCallbackListener();
417         vh.setCallback(updateListener);
418         String json = FileReader.readFileInString("src/test/resources/proto-json/MB-Unknown.json");
419         VEPUpdate update = ProtoConverter.json2Proto(json, true);
420         vh.distributeContent(update);
421
422         ChannelUID cuid = new ChannelUID(thingMock.getUID(), Constants.GROUP_HVAC, "temperature");
423         updateListener = new ThingCallbackListener();
424         vh.setCallback(updateListener);
425         vh.handleCommand(cuid, QuantityType.valueOf("18 °C"));
426         assertEquals("frontLeft", ahm.getCommand().get("zone").toString(), "Zone Selection");
427         assertEquals(18, ahm.getCommand().getDouble("temperature_in_celsius"), "Temperature Selection");
428         vh.handleCommand(cuid, QuantityType.valueOf("80 °F"));
429         assertEquals("frontLeft", ahm.getCommand().get("zone").toString(), "Zone Selection");
430         assertEquals(26, ahm.getCommand().getDouble("temperature_in_celsius"), "Temperature Selection");
431     }
432
433     @Test
434     public void testChargeProgramSelection() {
435         Thing thingMock = mock(Thing.class);
436         when(thingMock.getThingTypeUID()).thenReturn(Constants.THING_TYPE_BEV);
437         when(thingMock.getUID()).thenReturn(new ThingUID("test", Constants.BEV));
438         AccountHandlerMock ahm = new AccountHandlerMock();
439         VehicleHandler vh = new VehicleHandler(thingMock, new LocationProviderMock(),
440                 mock(MercedesMeCommandOptionProvider.class), mock(MercedesMeStateOptionProvider.class));
441         vh.accountHandler = Optional.of(ahm);
442         VehicleConfiguration vehicleConfig = new VehicleConfiguration();
443         vh.config = Optional.of(vehicleConfig);
444         ThingCallbackListener updateListener = new ThingCallbackListener();
445         vh.setCallback(updateListener);
446
447         String json = FileReader.readFileInString("src/test/resources/proto-json/MB-BEV-EQA.json");
448         VEPUpdate update = ProtoConverter.json2Proto(json, true);
449         vh.distributeContent(update);
450
451         ChannelUID cuid = new ChannelUID(thingMock.getUID(), Constants.GROUP_CHARGE, "max-soc");
452         vh.handleCommand(cuid, QuantityType.valueOf("90 %"));
453         int selectedChargeProgram = ((DecimalType) updateListener.getResponse("test::bev:charge#program")).intValue();
454         assertEquals(selectedChargeProgram,
455                 Utils.getChargeProgramNumber(ahm.getCommand().get("charge_program").toString()),
456                 "Charge Program Command");
457         assertEquals(90, ahm.getCommand().getInt("max_soc"), "Charge Program SOC Setting");
458
459         cuid = new ChannelUID(thingMock.getUID(), Constants.GROUP_CHARGE, "program");
460         vh.handleCommand(cuid, new DecimalType(3));
461         assertEquals(3, Utils.getChargeProgramNumber(ahm.getCommand().get("charge_program").toString()),
462                 "Charge Program Command");
463         assertEquals(100, ahm.getCommand().getInt("max_soc"), "Charge Program SOC Setting");
464     }
465 }