2 * Copyright (c) 2010-2022 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.mqtt.homeassistant.internal.component;
15 import static org.hamcrest.CoreMatchers.is;
16 import static org.hamcrest.MatcherAssert.assertThat;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.junit.jupiter.api.Test;
22 import org.openhab.binding.mqtt.generic.values.ColorValue;
23 import org.openhab.core.library.types.HSBType;
24 import org.openhab.core.library.types.OnOffType;
27 * Tests for {@link Light}
28 * The current {@link Light} is non-compliant with the Specification and must be rewritten from scratch.
30 * @author Anton Kharuzhy - Initial contribution
33 public class LightTests extends AbstractComponentTests {
34 public static final String CONFIG_TOPIC = "light/0x0000000000000000_light_zigbee2mqtt";
37 public void test() throws InterruptedException {
39 var component = (Light) discoverComponent(configTopicToMqtt(CONFIG_TOPIC),
41 " \"availability\": [ " +
43 " \"topic\": \"zigbee2mqtt/bridge/state\" " +
47 " \"identifiers\": [ " +
48 " \"zigbee2mqtt_0x0000000000000000\" " +
50 " \"manufacturer\": \"Lights inc\", " +
51 " \"model\": \"light v1\", " +
52 " \"name\": \"Light\", " +
53 " \"sw_version\": \"Zigbee2MQTT 1.18.2\" " +
55 " \"name\": \"light\", " +
56 " \"state_topic\": \"zigbee2mqtt/light/state\", " +
57 " \"command_topic\": \"zigbee2mqtt/light/set/state\", " +
58 " \"state_value_template\": \"{{ value_json.power }}\", " +
59 " \"payload_on\": \"ON_\", " +
60 " \"payload_off\": \"OFF_\", " +
61 " \"rgb_state_topic\": \"zigbee2mqtt/light/rgb\", " +
62 " \"rgb_command_topic\": \"zigbee2mqtt/light/set/rgb\", " +
63 " \"rgb_value_template\": \"{{ value_json.rgb }}\", " +
64 " \"brightness_state_topic\": \"zigbee2mqtt/light/brightness\", " +
65 " \"brightness_command_topic\": \"zigbee2mqtt/light/set/brightness\", " +
66 " \"brightness_value_template\": \"{{ value_json.br }}\" " +
70 assertThat(component.channels.size(), is(1));
71 assertThat(component.getName(), is("light"));
73 assertChannel(component, Light.COLOR_CHANNEL_ID, "zigbee2mqtt/light/rgb", "zigbee2mqtt/light/set/rgb", "light",
76 assertChannel(component.switchChannel, "zigbee2mqtt/light/state", "zigbee2mqtt/light/set/state", "light",
78 assertChannel(component.brightnessChannel, "zigbee2mqtt/light/brightness", "zigbee2mqtt/light/set/brightness",
79 "light", ColorValue.class);
81 publishMessage("zigbee2mqtt/light/rgb", "{\"rgb\": \"255,255,255\"}");
82 assertState(component, Light.COLOR_CHANNEL_ID, HSBType.fromRGB(255, 255, 255));
83 publishMessage("zigbee2mqtt/light/rgb", "{\"rgb\": \"10,20,30\"}");
84 assertState(component, Light.COLOR_CHANNEL_ID, HSBType.fromRGB(10, 20, 30));
86 component.switchChannel.getState().publishValue(OnOffType.OFF);
87 assertPublished("zigbee2mqtt/light/set/state", "0,0,0");
91 protected Set<String> getConfigTopics() {
92 return Set.of(CONFIG_TOPIC);