2 * Copyright (c) 2010-2023 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.max.internal.message;
15 import static org.junit.jupiter.api.Assertions.*;
17 import java.util.ArrayList;
18 import java.util.Collection;
19 import java.util.HashMap;
20 import java.util.List;
23 import org.eclipse.jdt.annotation.NonNullByDefault;
24 import org.junit.jupiter.api.BeforeEach;
25 import org.junit.jupiter.api.Test;
26 import org.openhab.binding.max.internal.device.Device;
27 import org.openhab.binding.max.internal.device.DeviceConfiguration;
28 import org.openhab.binding.max.internal.device.DeviceInformation;
29 import org.openhab.binding.max.internal.device.DeviceType;
30 import org.openhab.binding.max.internal.device.HeatingThermostat;
31 import org.openhab.binding.max.internal.device.ShutterContact;
34 * Tests cases for {@link LMessage}.
36 * @author Dominic Lerbs - Initial contribution
37 * @author Christoph Weitkamp - OH2 Version and updates
40 public class LMessageTest {
42 private static final String RAWDATA = "L:BgVPngkSEAsLhBkJEhkLJQDAAAsLhwwJEhkRJwDKAAYO8ZIJEhAGBU+kCRIQCwxuRPEaGQMmAMcACwxuQwkSGQgnAM8ACwQd5t0SGQ0oAMsA";
44 private final Map<String, Device> testDevices = new HashMap<>();
46 private final LMessage message = new LMessage(RAWDATA);
47 private final List<DeviceConfiguration> configurations = new ArrayList<>();
54 private void createTestDevices() {
55 addShutterContact("054f9e");
56 addShutterContact("0ef192");
57 addShutterContact("054fa4");
58 addHeatingThermostat("0b8419");
59 addHeatingThermostat("0b870c");
60 addHeatingThermostat("0c6e43");
61 addHeatingThermostat("041de6");
62 addHeatingThermostat("0c6e44").setError(true);
65 private ShutterContact addShutterContact(String rfAddress) {
66 ShutterContact device = new ShutterContact(createConfiguration(DeviceType.ShutterContact, rfAddress));
67 testDevices.put(rfAddress, device);
71 private HeatingThermostat addHeatingThermostat(String rfAddress) {
72 HeatingThermostat device = new HeatingThermostat(createConfiguration(DeviceType.HeatingThermostat, rfAddress));
73 testDevices.put(rfAddress, device);
77 private DeviceConfiguration createConfiguration(DeviceType type, String rfAddress) {
78 DeviceConfiguration configuration = DeviceConfiguration
79 .create(new DeviceInformation(type, "", rfAddress, "", 1));
80 configurations.add(configuration);
85 public void isCorrectMessageType() {
86 MessageType messageType = ((Message) message).getType();
87 assertEquals(MessageType.L, messageType);
91 public void allDevicesCreatedFromMessage() {
92 Collection<? extends Device> devices = message.getDevices(configurations);
93 assertEquals(testDevices.size(), devices.size(), "Incorrect number of devices created");
94 for (Device device : devices) {
95 assertTrue(testDevices.containsKey(device.getRFAddress()),
96 "Unexpected device created: " + device.getRFAddress());
101 public void isCorrectErrorState() {
102 for (Device device : message.getDevices(configurations)) {
103 Device testDevice = testDevices.get(device.getRFAddress());
104 assertEquals(testDevice.isError(), device.isError(), "Error set incorrectly in Device");