]> git.basschouten.com Git - openhab-addons.git/blob
678040424f2891a560379daf0011aab3ef6d9576
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.eclipse.jdt.annotation.NonNullByDefault;
21 import org.junit.jupiter.api.Test;
22 import org.openhab.binding.mqtt.generic.values.NumberValue;
23 import org.openhab.core.library.types.DecimalType;
24
25 /**
26  * Tests for {@link Number}
27  *
28  * @author Cody Cutrer - Initial contribution
29  */
30 @NonNullByDefault
31 public class NumberTests extends AbstractComponentTests {
32     public static final String CONFIG_TOPIC = "number/0x0000000000000000_number_zigbee2mqtt";
33
34     @SuppressWarnings("null")
35     @Test
36     public void test() throws InterruptedException {
37         var component = discoverComponent(configTopicToMqtt(CONFIG_TOPIC), """
38                     {
39                         "name": "BWA Link Hot Tub Pump 1",
40                         "availability_topic": "homie/bwa/$state",
41                         "payload_available": "ready",
42                         "payload_not_available": "lost",
43                         "qos": 1,
44                         "icon": "mdi:chart-bubble",
45                         "device": {
46                             "manufacturer": "Balboa Water Group",
47                             "sw_version": "2.1.3",
48                             "model": "BFBP20",
49                             "name": "BWA Link",
50                             "identifiers": "bwa"
51                         },
52                         "state_topic": "homie/bwa/spa/pump1",
53                         "command_topic": "homie/bwa/spa/pump1/set",
54                         "command_template": "{{ value | round(0) }}",
55                         "min": 0,
56                         "max": 2,
57                         "unique_id": "bwa_spa_pump1"
58                     }
59                 """);
60
61         assertThat(component.channels.size(), is(1));
62         assertThat(component.getName(), is("BWA Link Hot Tub Pump 1"));
63
64         assertChannel(component, Number.NUMBER_CHANNEL_ID, "homie/bwa/spa/pump1", "homie/bwa/spa/pump1/set",
65                 "BWA Link Hot Tub Pump 1", NumberValue.class);
66
67         publishMessage("homie/bwa/spa/pump1", "1");
68         assertState(component, Number.NUMBER_CHANNEL_ID, new DecimalType(1));
69         publishMessage("homie/bwa/spa/pump1", "2");
70         assertState(component, Number.NUMBER_CHANNEL_ID, new DecimalType(2));
71
72         component.getChannel(Number.NUMBER_CHANNEL_ID).getState().publishValue(new DecimalType(1.1));
73         assertPublished("homie/bwa/spa/pump1/set", "1");
74     }
75
76     @Override
77     protected Set<String> getConfigTopics() {
78         return Set.of(CONFIG_TOPIC);
79     }
80 }