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