]> git.basschouten.com Git - openhab-addons.git/blob
b1b8b77cf4f1e02c494c45ea66ab23e5f0c2d99b
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.mqtt.homeassistant.internal.component;
14
15 import static org.hamcrest.CoreMatchers.is;
16 import static org.hamcrest.MatcherAssert.assertThat;
17
18 import java.util.Set;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.junit.jupiter.api.Test;
22 import org.openhab.binding.mqtt.generic.values.ImageValue;
23 import org.openhab.core.library.types.RawType;
24
25 /**
26  * Tests for {@link Camera}
27  *
28  * @author Anton Kharuzhy - Initial contribution
29  */
30 @NonNullByDefault
31 public class CameraTests extends AbstractComponentTests {
32     public static final String CONFIG_TOPIC = "camera/0x0000000000000000_camera_zigbee2mqtt";
33
34     @Test
35     public void test() throws InterruptedException {
36         // @formatter:off
37         var component = discoverComponent(configTopicToMqtt(CONFIG_TOPIC),
38                 "{ " +
39                         "  \"availability\": [ " +
40                         "    { " +
41                         "      \"topic\": \"zigbee2mqtt/bridge/state\" " +
42                         "    } " +
43                         "  ], " +
44                         "  \"device\": { " +
45                         "    \"identifiers\": [ " +
46                         "      \"zigbee2mqtt_0x0000000000000000\" " +
47                         "    ], " +
48                         "    \"manufacturer\": \"Cameras inc\", " +
49                         "    \"model\": \"Camera\", " +
50                         "    \"name\": \"camera\", " +
51                         "    \"sw_version\": \"Zigbee2MQTT 1.18.2\" " +
52                         "  }, " +
53                         "  \"name\": \"cam1\", " +
54                         "  \"topic\": \"zigbee2mqtt/cam1/state\"" +
55                         "}");
56         // @formatter:on
57
58         assertThat(component.channels.size(), is(1));
59         assertThat(component.getName(), is("cam1"));
60
61         assertChannel(component, Camera.CAMERA_CHANNEL_ID, "zigbee2mqtt/cam1/state", "", "cam1", ImageValue.class);
62
63         var imageBytes = getResourceAsByteArray("component/image.png");
64         publishMessage("zigbee2mqtt/cam1/state", imageBytes);
65         assertState(component, Camera.CAMERA_CHANNEL_ID, new RawType(imageBytes, "image/png"));
66     }
67
68     @Override
69     protected Set<String> getConfigTopics() {
70         return Set.of(CONFIG_TOPIC);
71     }
72 }