2 * Copyright (c) 2010-2024 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.NumberValue;
23 import org.openhab.core.library.types.DecimalType;
26 * Tests for {@link Number}
28 * @author Cody Cutrer - Initial contribution
31 public class NumberTests extends AbstractComponentTests {
32 public static final String CONFIG_TOPIC = "number/0x0000000000000000_number_zigbee2mqtt";
34 @SuppressWarnings("null")
36 public void test() throws InterruptedException {
37 var component = discoverComponent(configTopicToMqtt(CONFIG_TOPIC), """
39 "name": "BWA Link Hot Tub Pump 1",
40 "availability_topic": "homie/bwa/$state",
41 "payload_available": "ready",
42 "payload_not_available": "lost",
44 "icon": "mdi:chart-bubble",
46 "manufacturer": "Balboa Water Group",
47 "sw_version": "2.1.3",
52 "state_topic": "homie/bwa/spa/pump1",
53 "command_topic": "homie/bwa/spa/pump1/set",
54 "command_template": "{{ value | round(0) }}",
57 "unique_id": "bwa_spa_pump1"
61 assertThat(component.channels.size(), is(1));
62 assertThat(component.getName(), is("BWA Link Hot Tub Pump 1"));
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);
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));
72 component.getChannel(Number.NUMBER_CHANNEL_ID).getState().publishValue(new DecimalType(1.1));
73 assertPublished("homie/bwa/spa/pump1/set", "1");
77 protected Set<String> getConfigTopics() {
78 return Set.of(CONFIG_TOPIC);