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.OnOffValue;
23 import org.openhab.core.library.types.OnOffType;
26 * Tests for {@link Fan}
28 * @author Anton Kharuzhy - Initial contribution
31 public class FanTests extends AbstractComponentTests {
32 public static final String CONFIG_TOPIC = "fan/0x0000000000000000_fan_zigbee2mqtt";
34 @SuppressWarnings("null")
36 public void test() throws InterruptedException {
38 var component = discoverComponent(configTopicToMqtt(CONFIG_TOPIC),
40 " \"availability\": [ " +
42 " \"topic\": \"zigbee2mqtt/bridge/state\" " +
46 " \"identifiers\": [ " +
47 " \"zigbee2mqtt_0x0000000000000000\" " +
49 " \"manufacturer\": \"Fans inc\", " +
50 " \"model\": \"Fan\", " +
51 " \"name\": \"FanBlower\", " +
52 " \"sw_version\": \"Zigbee2MQTT 1.18.2\" " +
54 " \"name\": \"fan\", " +
55 " \"payload_off\": \"OFF_\", " +
56 " \"payload_on\": \"ON_\", " +
57 " \"state_topic\": \"zigbee2mqtt/fan/state\", " +
58 " \"command_topic\": \"zigbee2mqtt/fan/set/state\" " +
62 assertThat(component.channels.size(), is(1));
63 assertThat(component.getName(), is("fan"));
65 assertChannel(component, Fan.SWITCH_CHANNEL_ID, "zigbee2mqtt/fan/state", "zigbee2mqtt/fan/set/state", "fan",
68 publishMessage("zigbee2mqtt/fan/state", "ON_");
69 assertState(component, Fan.SWITCH_CHANNEL_ID, OnOffType.ON);
70 publishMessage("zigbee2mqtt/fan/state", "ON_");
71 assertState(component, Fan.SWITCH_CHANNEL_ID, OnOffType.ON);
72 publishMessage("zigbee2mqtt/fan/state", "OFF_");
73 assertState(component, Fan.SWITCH_CHANNEL_ID, OnOffType.OFF);
74 publishMessage("zigbee2mqtt/fan/state", "ON_");
75 assertState(component, Fan.SWITCH_CHANNEL_ID, OnOffType.ON);
77 component.getChannel(Fan.SWITCH_CHANNEL_ID).getState().publishValue(OnOffType.OFF);
78 assertPublished("zigbee2mqtt/fan/set/state", "OFF_");
79 component.getChannel(Fan.SWITCH_CHANNEL_ID).getState().publishValue(OnOffType.ON);
80 assertPublished("zigbee2mqtt/fan/set/state", "ON_");
84 protected Set<String> getConfigTopics() {
85 return Set.of(CONFIG_TOPIC);