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.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.RollershutterValue;
23 import org.openhab.core.library.types.PercentType;
24 import org.openhab.core.library.types.StopMoveType;
27 * Tests for {@link Cover}
29 * @author Anton Kharuzhy - Initial contribution
32 public class CoverTests extends AbstractComponentTests {
33 public static final String CONFIG_TOPIC = "cover/0x0000000000000000_cover_zigbee2mqtt";
35 @SuppressWarnings("null")
37 public void test() throws InterruptedException {
39 var component = discoverComponent(configTopicToMqtt(CONFIG_TOPIC),
41 " \"availability\": [ " +
43 " \"topic\": \"zigbee2mqtt/bridge/state\" " +
47 " \"identifiers\": [ " +
48 " \"zigbee2mqtt_0x0000000000000000\" " +
50 " \"manufacturer\": \"Covers inc\", " +
51 " \"model\": \"cover v1\", " +
52 " \"name\": \"Cover\", " +
53 " \"sw_version\": \"Zigbee2MQTT 1.18.2\" " +
55 " \"name\": \"cover\", " +
56 " \"payload_open\": \"OPEN_\", " +
57 " \"payload_close\": \"CLOSE_\", " +
58 " \"payload_stop\": \"STOP_\", " +
59 " \"state_topic\": \"zigbee2mqtt/cover/state\", " +
60 " \"command_topic\": \"zigbee2mqtt/cover/set/state\" " +
64 assertThat(component.channels.size(), is(1));
65 assertThat(component.getName(), is("cover"));
67 assertChannel(component, Cover.SWITCH_CHANNEL_ID, "zigbee2mqtt/cover/state", "zigbee2mqtt/cover/set/state",
68 "cover", RollershutterValue.class);
70 publishMessage("zigbee2mqtt/cover/state", "100");
71 assertState(component, Cover.SWITCH_CHANNEL_ID, PercentType.HUNDRED);
72 publishMessage("zigbee2mqtt/cover/state", "0");
73 assertState(component, Cover.SWITCH_CHANNEL_ID, PercentType.ZERO);
75 component.getChannel(Cover.SWITCH_CHANNEL_ID).getState().publishValue(PercentType.ZERO);
76 assertPublished("zigbee2mqtt/cover/set/state", "OPEN_");
77 component.getChannel(Cover.SWITCH_CHANNEL_ID).getState().publishValue(PercentType.HUNDRED);
78 assertPublished("zigbee2mqtt/cover/set/state", "CLOSE_");
79 component.getChannel(Cover.SWITCH_CHANNEL_ID).getState().publishValue(StopMoveType.STOP);
80 assertPublished("zigbee2mqtt/cover/set/state", "STOP_");
81 component.getChannel(Cover.SWITCH_CHANNEL_ID).getState().publishValue(PercentType.ZERO);
82 assertPublished("zigbee2mqtt/cover/set/state", "OPEN_", 2);
83 component.getChannel(Cover.SWITCH_CHANNEL_ID).getState().publishValue(StopMoveType.STOP);
84 assertPublished("zigbee2mqtt/cover/set/state", "STOP_", 2);
88 protected Set<String> getConfigTopics() {
89 return Set.of(CONFIG_TOPIC);