2 * Copyright (c) 2010-2021 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.junit.jupiter.api.Test;
21 import org.openhab.binding.mqtt.generic.values.ColorValue;
22 import org.openhab.core.library.types.HSBType;
23 import org.openhab.core.library.types.OnOffType;
26 * Tests for {@link Light}
27 * The current {@link Light} is non-compliant with the Specification and must be rewritten from scratch.
29 * @author Anton Kharuzhy - Initial contribution
31 public class LightTests extends AbstractComponentTests {
32 public static final String CONFIG_TOPIC = "light/0x0000000000000000_light_zigbee2mqtt";
35 public void test() throws InterruptedException {
37 var component = (Light) discoverComponent(configTopicToMqtt(CONFIG_TOPIC),
39 " \"availability\": [ " +
41 " \"topic\": \"zigbee2mqtt/bridge/state\" " +
45 " \"identifiers\": [ " +
46 " \"zigbee2mqtt_0x0000000000000000\" " +
48 " \"manufacturer\": \"Lights inc\", " +
49 " \"model\": \"light v1\", " +
50 " \"name\": \"Light\", " +
51 " \"sw_version\": \"Zigbee2MQTT 1.18.2\" " +
53 " \"name\": \"light\", " +
54 " \"state_topic\": \"zigbee2mqtt/light/state\", " +
55 " \"command_topic\": \"zigbee2mqtt/light/set/state\", " +
56 " \"state_value_template\": \"{{ value_json.power }}\", " +
57 " \"payload_on\": \"ON_\", " +
58 " \"payload_off\": \"OFF_\", " +
59 " \"rgb_state_topic\": \"zigbee2mqtt/light/rgb\", " +
60 " \"rgb_command_topic\": \"zigbee2mqtt/light/set/rgb\", " +
61 " \"rgb_value_template\": \"{{ value_json.rgb }}\", " +
62 " \"brightness_state_topic\": \"zigbee2mqtt/light/brightness\", " +
63 " \"brightness_command_topic\": \"zigbee2mqtt/light/set/brightness\", " +
64 " \"brightness_value_template\": \"{{ value_json.br }}\" " +
68 assertThat(component.channels.size(), is(1));
69 assertThat(component.getName(), is("light"));
71 assertChannel(component, Light.COLOR_CHANNEL_ID, "zigbee2mqtt/light/rgb", "zigbee2mqtt/light/set/rgb", "light",
74 assertChannel(component.switchChannel, "zigbee2mqtt/light/state", "zigbee2mqtt/light/set/state", "light",
76 assertChannel(component.brightnessChannel, "zigbee2mqtt/light/brightness", "zigbee2mqtt/light/set/brightness",
77 "light", ColorValue.class);
79 publishMessage("zigbee2mqtt/light/rgb", "{\"rgb\": \"255,255,255\"}");
80 assertState(component, Light.COLOR_CHANNEL_ID, HSBType.fromRGB(255, 255, 255));
81 publishMessage("zigbee2mqtt/light/rgb", "{\"rgb\": \"10,20,30\"}");
82 assertState(component, Light.COLOR_CHANNEL_ID, HSBType.fromRGB(10, 20, 30));
84 component.switchChannel.getState().publishValue(OnOffType.OFF);
85 assertPublished("zigbee2mqtt/light/set/state", "0,0,0");
88 protected Set<String> getConfigTopics() {
89 return Set.of(CONFIG_TOPIC);