2 * Copyright (c) 2010-2024 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.mercedesme.internal.handler;
15 import static org.junit.jupiter.api.Assertions.*;
16 import static org.mockito.Mockito.*;
18 import java.util.Optional;
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;
39 import com.daimler.mbcarkit.proto.VehicleEvents.VEPUpdate;
42 * {@link VehicleHandlerTest} check state updates and command sending of vehicles
44 * @author Bernd Weymann - Initial contribution
47 class VehicleHandlerTest {
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);
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);
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");
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);
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);
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);
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"),
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"),
122 assertTrue(updateListener.getResponse("test::bev:hvac#temperature").toFullString().endsWith("°F"),
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");
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");
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);
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);
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");
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);
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");
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);
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(),
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);
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(),
235 assertEquals("246 km", updateListener.getResponse("test::bev:range#radius-electric").toFullString(),
237 assertEquals("307 km", updateListener.getResponse("test::bev:range#range-electric").toFullString(),
238 "Range Radius Update");
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);
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);
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");
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);
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);
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(),
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);
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);
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");
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
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,
346 vh.handleCommand(mileageChannelUID, RefreshType.REFRESH);
347 assertEquals(1, updateListener.updatesReceived.size());
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);
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");
369 updateListener.linked = true;
370 vh.distributeContent(update);
371 assertTrue(updateListener.updatesReceived.containsKey("test::bev:vehicle#proto-update"),
372 "Proto Channel not updated");
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);
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");
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));
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);
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");
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);
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);
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");
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");