[mqtt-homeassistant] Refactoring: fixed under_score/CamelCase usages and nullable annotations (#11120)

Signed-off-by: Anton Kharuzhy <antroids@gmail.com>
This commit is contained in:
antroids
2021-09-19 23:04:14 +03:00
committed by GitHub
parent 2fb86d7138
commit e1e9f90da1
34 changed files with 672 additions and 556 deletions

View File

@@ -52,7 +52,6 @@ import org.openhab.core.types.State;
/**
* Abstract class for components tests.
* TODO: need a way to test all channel properties, not only topics.
*
* @author Anton Kharuzhy - Initial contribution
*/

View File

@@ -64,27 +64,27 @@ public class AlarmControlPanelTests extends AbstractComponentTests {
assertThat(component.channels.size(), is(4));
assertThat(component.getName(), is("alarm"));
assertChannel(component, AlarmControlPanel.stateChannelID, "zigbee2mqtt/alarm/state", "", "alarm",
assertChannel(component, AlarmControlPanel.STATE_CHANNEL_ID, "zigbee2mqtt/alarm/state", "", "alarm",
TextValue.class);
assertChannel(component, AlarmControlPanel.switchDisarmChannelID, "", "zigbee2mqtt/alarm/set/state", "alarm",
TextValue.class);
assertChannel(component, AlarmControlPanel.switchArmAwayChannelID, "", "zigbee2mqtt/alarm/set/state", "alarm",
TextValue.class);
assertChannel(component, AlarmControlPanel.switchArmHomeChannelID, "", "zigbee2mqtt/alarm/set/state", "alarm",
assertChannel(component, AlarmControlPanel.SWITCH_DISARM_CHANNEL_ID, "", "zigbee2mqtt/alarm/set/state", "alarm",
TextValue.class);
assertChannel(component, AlarmControlPanel.SWITCH_ARM_AWAY_CHANNEL_ID, "", "zigbee2mqtt/alarm/set/state",
"alarm", TextValue.class);
assertChannel(component, AlarmControlPanel.SWITCH_ARM_HOME_CHANNEL_ID, "", "zigbee2mqtt/alarm/set/state",
"alarm", TextValue.class);
publishMessage("zigbee2mqtt/alarm/state", "armed_home");
assertState(component, AlarmControlPanel.stateChannelID, new StringType("armed_home"));
assertState(component, AlarmControlPanel.STATE_CHANNEL_ID, new StringType("armed_home"));
publishMessage("zigbee2mqtt/alarm/state", "armed_away");
assertState(component, AlarmControlPanel.stateChannelID, new StringType("armed_away"));
assertState(component, AlarmControlPanel.STATE_CHANNEL_ID, new StringType("armed_away"));
component.getChannel(AlarmControlPanel.switchDisarmChannelID).getState()
component.getChannel(AlarmControlPanel.SWITCH_DISARM_CHANNEL_ID).getState()
.publishValue(new StringType("DISARM_"));
assertPublished("zigbee2mqtt/alarm/set/state", "DISARM_");
component.getChannel(AlarmControlPanel.switchArmAwayChannelID).getState()
component.getChannel(AlarmControlPanel.SWITCH_ARM_AWAY_CHANNEL_ID).getState()
.publishValue(new StringType("ARM_AWAY_"));
assertPublished("zigbee2mqtt/alarm/set/state", "ARM_AWAY_");
component.getChannel(AlarmControlPanel.switchArmHomeChannelID).getState()
component.getChannel(AlarmControlPanel.SWITCH_ARM_HOME_CHANNEL_ID).getState()
.publishValue(new StringType("ARM_HOME_"));
assertPublished("zigbee2mqtt/alarm/set/state", "ARM_HOME_");
}

View File

@@ -63,17 +63,17 @@ public class BinarySensorTests extends AbstractComponentTests {
assertThat(component.getName(), is("onoffsensor"));
assertThat(component.getGroupUID().getId(), is("sn1"));
assertChannel(component, BinarySensor.sensorChannelID, "zigbee2mqtt/sensor/state", "", "value",
assertChannel(component, BinarySensor.SENSOR_CHANNEL_ID, "zigbee2mqtt/sensor/state", "", "value",
OnOffValue.class);
publishMessage("zigbee2mqtt/sensor/state", "{ \"state\": \"ON_\" }");
assertState(component, BinarySensor.sensorChannelID, OnOffType.ON);
assertState(component, BinarySensor.SENSOR_CHANNEL_ID, OnOffType.ON);
publishMessage("zigbee2mqtt/sensor/state", "{ \"state\": \"ON_\" }");
assertState(component, BinarySensor.sensorChannelID, OnOffType.ON);
assertState(component, BinarySensor.SENSOR_CHANNEL_ID, OnOffType.ON);
publishMessage("zigbee2mqtt/sensor/state", "{ \"state\": \"OFF_\" }");
assertState(component, BinarySensor.sensorChannelID, OnOffType.OFF);
assertState(component, BinarySensor.SENSOR_CHANNEL_ID, OnOffType.OFF);
publishMessage("zigbee2mqtt/sensor/state", "{ \"state\": \"ON_\" }");
assertState(component, BinarySensor.sensorChannelID, OnOffType.ON);
assertState(component, BinarySensor.SENSOR_CHANNEL_ID, OnOffType.ON);
}
@Test
@@ -107,9 +107,9 @@ public class BinarySensorTests extends AbstractComponentTests {
// @formatter:on
publishMessage("zigbee2mqtt/sensor/state", "{ \"state\": \"ON_\" }");
assertState(component, BinarySensor.sensorChannelID, OnOffType.ON);
assertState(component, BinarySensor.SENSOR_CHANNEL_ID, OnOffType.ON);
waitForAssert(() -> assertState(component, BinarySensor.sensorChannelID, OnOffType.OFF), 10000, 200);
waitForAssert(() -> assertState(component, BinarySensor.SENSOR_CHANNEL_ID, OnOffType.OFF), 10000, 200);
}
@Test
@@ -143,9 +143,9 @@ public class BinarySensorTests extends AbstractComponentTests {
// @formatter:on
publishMessage("zigbee2mqtt/sensor/state", "{ \"state\": \"OFF_\" }");
assertState(component, BinarySensor.sensorChannelID, OnOffType.OFF);
assertState(component, BinarySensor.SENSOR_CHANNEL_ID, OnOffType.OFF);
waitForAssert(() -> assertState(component, BinarySensor.sensorChannelID, UnDefType.UNDEF), 10000, 200);
waitForAssert(() -> assertState(component, BinarySensor.SENSOR_CHANNEL_ID, UnDefType.UNDEF), 10000, 200);
}
protected Set<String> getConfigTopics() {

View File

@@ -56,11 +56,11 @@ public class CameraTests extends AbstractComponentTests {
assertThat(component.channels.size(), is(1));
assertThat(component.getName(), is("cam1"));
assertChannel(component, Camera.cameraChannelID, "zigbee2mqtt/cam1/state", "", "cam1", ImageValue.class);
assertChannel(component, Camera.CAMERA_CHANNEL_ID, "zigbee2mqtt/cam1/state", "", "cam1", ImageValue.class);
var imageBytes = getResourceAsByteArray("component/image.png");
publishMessage("zigbee2mqtt/cam1/state", imageBytes);
assertState(component, Camera.cameraChannelID, new RawType(imageBytes, "image/png"));
assertState(component, Camera.CAMERA_CHANNEL_ID, new RawType(imageBytes, "image/png"));
}
protected Set<String> getConfigTopics() {

View File

@@ -62,23 +62,23 @@ public class CoverTests extends AbstractComponentTests {
assertThat(component.channels.size(), is(1));
assertThat(component.getName(), is("cover"));
assertChannel(component, Cover.switchChannelID, "zigbee2mqtt/cover/state", "zigbee2mqtt/cover/set/state",
assertChannel(component, Cover.SWITCH_CHANNEL_ID, "zigbee2mqtt/cover/state", "zigbee2mqtt/cover/set/state",
"cover", RollershutterValue.class);
publishMessage("zigbee2mqtt/cover/state", "100");
assertState(component, Cover.switchChannelID, PercentType.HUNDRED);
assertState(component, Cover.SWITCH_CHANNEL_ID, PercentType.HUNDRED);
publishMessage("zigbee2mqtt/cover/state", "0");
assertState(component, Cover.switchChannelID, PercentType.ZERO);
assertState(component, Cover.SWITCH_CHANNEL_ID, PercentType.ZERO);
component.getChannel(Cover.switchChannelID).getState().publishValue(PercentType.ZERO);
component.getChannel(Cover.SWITCH_CHANNEL_ID).getState().publishValue(PercentType.ZERO);
assertPublished("zigbee2mqtt/cover/set/state", "OPEN_");
component.getChannel(Cover.switchChannelID).getState().publishValue(PercentType.HUNDRED);
component.getChannel(Cover.SWITCH_CHANNEL_ID).getState().publishValue(PercentType.HUNDRED);
assertPublished("zigbee2mqtt/cover/set/state", "CLOSE_");
component.getChannel(Cover.switchChannelID).getState().publishValue(StopMoveType.STOP);
component.getChannel(Cover.SWITCH_CHANNEL_ID).getState().publishValue(StopMoveType.STOP);
assertPublished("zigbee2mqtt/cover/set/state", "STOP_");
component.getChannel(Cover.switchChannelID).getState().publishValue(PercentType.ZERO);
component.getChannel(Cover.SWITCH_CHANNEL_ID).getState().publishValue(PercentType.ZERO);
assertPublished("zigbee2mqtt/cover/set/state", "OPEN_", 2);
component.getChannel(Cover.switchChannelID).getState().publishValue(StopMoveType.STOP);
component.getChannel(Cover.SWITCH_CHANNEL_ID).getState().publishValue(StopMoveType.STOP);
assertPublished("zigbee2mqtt/cover/set/state", "STOP_", 2);
}

View File

@@ -60,21 +60,21 @@ public class FanTests extends AbstractComponentTests {
assertThat(component.channels.size(), is(1));
assertThat(component.getName(), is("fan"));
assertChannel(component, Fan.switchChannelID, "zigbee2mqtt/fan/state", "zigbee2mqtt/fan/set/state", "fan",
assertChannel(component, Fan.SWITCH_CHANNEL_ID, "zigbee2mqtt/fan/state", "zigbee2mqtt/fan/set/state", "fan",
OnOffValue.class);
publishMessage("zigbee2mqtt/fan/state", "ON_");
assertState(component, Fan.switchChannelID, OnOffType.ON);
assertState(component, Fan.SWITCH_CHANNEL_ID, OnOffType.ON);
publishMessage("zigbee2mqtt/fan/state", "ON_");
assertState(component, Fan.switchChannelID, OnOffType.ON);
assertState(component, Fan.SWITCH_CHANNEL_ID, OnOffType.ON);
publishMessage("zigbee2mqtt/fan/state", "OFF_");
assertState(component, Fan.switchChannelID, OnOffType.OFF);
assertState(component, Fan.SWITCH_CHANNEL_ID, OnOffType.OFF);
publishMessage("zigbee2mqtt/fan/state", "ON_");
assertState(component, Fan.switchChannelID, OnOffType.ON);
assertState(component, Fan.SWITCH_CHANNEL_ID, OnOffType.ON);
component.getChannel(Fan.switchChannelID).getState().publishValue(OnOffType.OFF);
component.getChannel(Fan.SWITCH_CHANNEL_ID).getState().publishValue(OnOffType.OFF);
assertPublished("zigbee2mqtt/fan/set/state", "OFF_");
component.getChannel(Fan.switchChannelID).getState().publishValue(OnOffType.ON);
component.getChannel(Fan.SWITCH_CHANNEL_ID).getState().publishValue(OnOffType.ON);
assertPublished("zigbee2mqtt/fan/set/state", "ON_");
}

View File

@@ -98,8 +98,8 @@ public class HAConfigurationTests {
Switch.ChannelConfiguration.class);
assertThat(config.getAvailabilityTopic(), is("D/E"));
assertThat(config.state_topic, is("O/D/"));
assertThat(config.command_topic, is("P~Q"));
assertThat(config.stateTopic, is("O/D/"));
assertThat(config.commandTopic, is("P~Q"));
assertThat(config.getDevice(), is(notNullValue()));
Device device = config.getDevice();
@@ -158,35 +158,35 @@ public class HAConfigurationTests {
assertThat(config.getDevice().getName(), is("th1"));
assertThat(config.getDevice().getSwVersion(), is("Zigbee2MQTT 1.18.2"));
assertThat(config.action_template, is(
assertThat(config.actionTemplate, is(
"{% set values = {'idle':'off','heat':'heating','cool':'cooling','fan only':'fan'} %}{{ values[value_json.running_state] }}"));
assertThat(config.action_topic, is("zigbee2mqtt/th1"));
assertThat(config.away_mode_command_topic, is("zigbee2mqtt/th1/set/away_mode"));
assertThat(config.away_mode_state_template, is("{{ value_json.away_mode }}"));
assertThat(config.away_mode_state_topic, is("zigbee2mqtt/th1"));
assertThat(config.current_temperature_template, is("{{ value_json.local_temperature }}"));
assertThat(config.current_temperature_topic, is("zigbee2mqtt/th1"));
assertThat(config.hold_command_topic, is("zigbee2mqtt/th1/set/preset"));
assertThat(config.hold_modes, is(List.of("schedule", "manual", "boost", "complex", "comfort", "eco")));
assertThat(config.hold_state_template, is("{{ value_json.preset }}"));
assertThat(config.hold_state_topic, is("zigbee2mqtt/th1"));
assertThat(config.json_attributes_topic, is("zigbee2mqtt/th1"));
assertThat(config.max_temp, is(35f));
assertThat(config.min_temp, is(5f));
assertThat(config.mode_command_topic, is("zigbee2mqtt/th1/set/system_mode"));
assertThat(config.mode_state_template, is("{{ value_json.system_mode }}"));
assertThat(config.mode_state_topic, is("zigbee2mqtt/th1"));
assertThat(config.actionTopic, is("zigbee2mqtt/th1"));
assertThat(config.awayModeCommandTopic, is("zigbee2mqtt/th1/set/away_mode"));
assertThat(config.awayModeStateTemplate, is("{{ value_json.away_mode }}"));
assertThat(config.awayModeStateTopic, is("zigbee2mqtt/th1"));
assertThat(config.currentTemperatureTemplate, is("{{ value_json.local_temperature }}"));
assertThat(config.currentTemperatureTopic, is("zigbee2mqtt/th1"));
assertThat(config.holdCommandTopic, is("zigbee2mqtt/th1/set/preset"));
assertThat(config.holdModes, is(List.of("schedule", "manual", "boost", "complex", "comfort", "eco")));
assertThat(config.holdStateTemplate, is("{{ value_json.preset }}"));
assertThat(config.holdStateTopic, is("zigbee2mqtt/th1"));
assertThat(config.jsonAttributesTopic, is("zigbee2mqtt/th1"));
assertThat(config.maxTemp, is(35f));
assertThat(config.minTemp, is(5f));
assertThat(config.modeCommandTopic, is("zigbee2mqtt/th1/set/system_mode"));
assertThat(config.modeStateTemplate, is("{{ value_json.system_mode }}"));
assertThat(config.modeStateTopic, is("zigbee2mqtt/th1"));
assertThat(config.modes, is(List.of("heat", "auto", "off")));
assertThat(config.getName(), is("th1"));
assertThat(config.temp_step, is(0.5f));
assertThat(config.temperature_command_topic, is("zigbee2mqtt/th1/set/current_heating_setpoint"));
assertThat(config.temperature_state_template, is("{{ value_json.current_heating_setpoint }}"));
assertThat(config.temperature_state_topic, is("zigbee2mqtt/th1"));
assertThat(config.temperature_unit, is("C"));
assertThat(config.tempStep, is(0.5f));
assertThat(config.temperatureCommandTopic, is("zigbee2mqtt/th1/set/current_heating_setpoint"));
assertThat(config.temperatureStateTemplate, is("{{ value_json.current_heating_setpoint }}"));
assertThat(config.temperatureStateTopic, is("zigbee2mqtt/th1"));
assertThat(config.temperatureUnit, is("C"));
assertThat(config.getUniqueId(), is("0x847127fffe11dd6a_climate_zigbee2mqtt"));
assertThat(config.initial, is(21));
assertThat(config.send_if_off, is(true));
assertThat(config.sendIfOff, is(true));
}
@Test
@@ -194,57 +194,57 @@ public class HAConfigurationTests {
String json = readTestJson("configClimate.json");
Climate.ChannelConfiguration config = AbstractChannelConfiguration.fromString(json, gson,
Climate.ChannelConfiguration.class);
assertThat(config.action_template, is("a"));
assertThat(config.action_topic, is("b"));
assertThat(config.aux_command_topic, is("c"));
assertThat(config.aux_state_template, is("d"));
assertThat(config.aux_state_topic, is("e"));
assertThat(config.away_mode_command_topic, is("f"));
assertThat(config.away_mode_state_template, is("g"));
assertThat(config.away_mode_state_topic, is("h"));
assertThat(config.current_temperature_template, is("i"));
assertThat(config.current_temperature_topic, is("j"));
assertThat(config.fan_mode_command_template, is("k"));
assertThat(config.fan_mode_command_topic, is("l"));
assertThat(config.fan_mode_state_template, is("m"));
assertThat(config.fan_mode_state_topic, is("n"));
assertThat(config.fan_modes, is(List.of("p1", "p2")));
assertThat(config.hold_command_template, is("q"));
assertThat(config.hold_command_topic, is("r"));
assertThat(config.hold_state_template, is("s"));
assertThat(config.hold_state_topic, is("t"));
assertThat(config.hold_modes, is(List.of("u1", "u2", "u3")));
assertThat(config.json_attributes_template, is("v"));
assertThat(config.json_attributes_topic, is("w"));
assertThat(config.mode_command_template, is("x"));
assertThat(config.mode_command_topic, is("y"));
assertThat(config.mode_state_template, is("z"));
assertThat(config.mode_state_topic, is("A"));
assertThat(config.actionTemplate, is("a"));
assertThat(config.actionTopic, is("b"));
assertThat(config.auxCommandTopic, is("c"));
assertThat(config.auxStateTemplate, is("d"));
assertThat(config.auxStateTopic, is("e"));
assertThat(config.awayModeCommandTopic, is("f"));
assertThat(config.awayModeStateTemplate, is("g"));
assertThat(config.awayModeStateTopic, is("h"));
assertThat(config.currentTemperatureTemplate, is("i"));
assertThat(config.currentTemperatureTopic, is("j"));
assertThat(config.fanModeCommandTemplate, is("k"));
assertThat(config.fanModeCommandTopic, is("l"));
assertThat(config.fanModeStateTemplate, is("m"));
assertThat(config.fanModeStateTopic, is("n"));
assertThat(config.fanModes, is(List.of("p1", "p2")));
assertThat(config.holdCommandTemplate, is("q"));
assertThat(config.holdCommandTopic, is("r"));
assertThat(config.holdStateTemplate, is("s"));
assertThat(config.holdStateTopic, is("t"));
assertThat(config.holdModes, is(List.of("u1", "u2", "u3")));
assertThat(config.jsonAttributesTemplate, is("v"));
assertThat(config.jsonAttributesTopic, is("w"));
assertThat(config.modeCommandTemplate, is("x"));
assertThat(config.modeCommandTopic, is("y"));
assertThat(config.modeStateTemplate, is("z"));
assertThat(config.modeStateTopic, is("A"));
assertThat(config.modes, is(List.of("B1", "B2")));
assertThat(config.swing_command_template, is("C"));
assertThat(config.swing_command_topic, is("D"));
assertThat(config.swing_state_template, is("E"));
assertThat(config.swing_state_topic, is("F"));
assertThat(config.swing_modes, is(List.of("G1")));
assertThat(config.temperature_command_template, is("H"));
assertThat(config.temperature_command_topic, is("I"));
assertThat(config.temperature_state_template, is("J"));
assertThat(config.temperature_state_topic, is("K"));
assertThat(config.temperature_high_command_template, is("L"));
assertThat(config.temperature_high_command_topic, is("N"));
assertThat(config.temperature_high_state_template, is("O"));
assertThat(config.temperature_high_state_topic, is("P"));
assertThat(config.temperature_low_command_template, is("Q"));
assertThat(config.temperature_low_command_topic, is("R"));
assertThat(config.temperature_low_state_template, is("S"));
assertThat(config.temperature_low_state_topic, is("T"));
assertThat(config.power_command_topic, is("U"));
assertThat(config.swingCommandTemplate, is("C"));
assertThat(config.swingCommandTopic, is("D"));
assertThat(config.swingStateTemplate, is("E"));
assertThat(config.swingStateTopic, is("F"));
assertThat(config.swingModes, is(List.of("G1")));
assertThat(config.temperatureCommandTemplate, is("H"));
assertThat(config.temperatureCommandTopic, is("I"));
assertThat(config.temperatureStateTemplate, is("J"));
assertThat(config.temperatureStateTopic, is("K"));
assertThat(config.temperatureHighCommandTemplate, is("L"));
assertThat(config.temperatureHighCommandTopic, is("N"));
assertThat(config.temperatureHighStateTemplate, is("O"));
assertThat(config.temperatureHighStateTopic, is("P"));
assertThat(config.temperatureLowCommandTemplate, is("Q"));
assertThat(config.temperatureLowCommandTopic, is("R"));
assertThat(config.temperatureLowStateTemplate, is("S"));
assertThat(config.temperatureLowStateTopic, is("T"));
assertThat(config.powerCommandTopic, is("U"));
assertThat(config.initial, is(10));
assertThat(config.max_temp, is(40f));
assertThat(config.min_temp, is(0f));
assertThat(config.temperature_unit, is("F"));
assertThat(config.temp_step, is(1f));
assertThat(config.maxTemp, is(40f));
assertThat(config.minTemp, is(0f));
assertThat(config.temperatureUnit, is("F"));
assertThat(config.tempStep, is(1f));
assertThat(config.precision, is(0.5f));
assertThat(config.send_if_off, is(false));
assertThat(config.sendIfOff, is(false));
}
}

View File

@@ -68,7 +68,7 @@ public class LightTests extends AbstractComponentTests {
assertThat(component.channels.size(), is(1));
assertThat(component.getName(), is("light"));
assertChannel(component, Light.colorChannelID, "zigbee2mqtt/light/rgb", "zigbee2mqtt/light/set/rgb", "light",
assertChannel(component, Light.COLOR_CHANNEL_ID, "zigbee2mqtt/light/rgb", "zigbee2mqtt/light/set/rgb", "light",
ColorValue.class);
assertChannel(component.switchChannel, "zigbee2mqtt/light/state", "zigbee2mqtt/light/set/state", "light",
@@ -77,9 +77,9 @@ public class LightTests extends AbstractComponentTests {
"light", ColorValue.class);
publishMessage("zigbee2mqtt/light/rgb", "{\"rgb\": \"255,255,255\"}");
assertState(component, Light.colorChannelID, HSBType.fromRGB(255, 255, 255));
assertState(component, Light.COLOR_CHANNEL_ID, HSBType.fromRGB(255, 255, 255));
publishMessage("zigbee2mqtt/light/rgb", "{\"rgb\": \"10,20,30\"}");
assertState(component, Light.colorChannelID, HSBType.fromRGB(10, 20, 30));
assertState(component, Light.COLOR_CHANNEL_ID, HSBType.fromRGB(10, 20, 30));
component.switchChannel.getState().publishValue(OnOffType.OFF);
assertPublished("zigbee2mqtt/light/set/state", "0,0,0");

View File

@@ -65,21 +65,21 @@ public class LockTests extends AbstractComponentTests {
assertThat(component.channels.size(), is(1));
assertThat(component.getName(), is("lock"));
assertChannel(component, Lock.switchChannelID, "zigbee2mqtt/lock/state", "zigbee2mqtt/lock/set/state", "lock",
assertChannel(component, Lock.SWITCH_CHANNEL_ID, "zigbee2mqtt/lock/state", "zigbee2mqtt/lock/set/state", "lock",
OnOffValue.class);
publishMessage("zigbee2mqtt/lock/state", "LOCK_");
assertState(component, Lock.switchChannelID, OnOffType.ON);
assertState(component, Lock.SWITCH_CHANNEL_ID, OnOffType.ON);
publishMessage("zigbee2mqtt/lock/state", "LOCK_");
assertState(component, Lock.switchChannelID, OnOffType.ON);
assertState(component, Lock.SWITCH_CHANNEL_ID, OnOffType.ON);
publishMessage("zigbee2mqtt/lock/state", "UNLOCK_");
assertState(component, Lock.switchChannelID, OnOffType.OFF);
assertState(component, Lock.SWITCH_CHANNEL_ID, OnOffType.OFF);
publishMessage("zigbee2mqtt/lock/state", "LOCK_");
assertState(component, Lock.switchChannelID, OnOffType.ON);
assertState(component, Lock.SWITCH_CHANNEL_ID, OnOffType.ON);
component.getChannel(Lock.switchChannelID).getState().publishValue(OnOffType.OFF);
component.getChannel(Lock.SWITCH_CHANNEL_ID).getState().publishValue(OnOffType.OFF);
assertPublished("zigbee2mqtt/lock/set/state", "UNLOCK_");
component.getChannel(Lock.switchChannelID).getState().publishValue(OnOffType.ON);
component.getChannel(Lock.SWITCH_CHANNEL_ID).getState().publishValue(OnOffType.ON);
assertPublished("zigbee2mqtt/lock/set/state", "LOCK_");
}

View File

@@ -63,16 +63,17 @@ public class SensorTests extends AbstractComponentTests {
assertThat(component.getName(), is("sensor1"));
assertThat(component.getGroupUID().getId(), is("sn1"));
assertChannel(component, Sensor.sensorChannelID, "zigbee2mqtt/sensor/state", "", "sensor1", NumberValue.class);
assertChannel(component, Sensor.SENSOR_CHANNEL_ID, "zigbee2mqtt/sensor/state", "", "sensor1",
NumberValue.class);
publishMessage("zigbee2mqtt/sensor/state", "10");
assertState(component, Sensor.sensorChannelID, DecimalType.valueOf("10"));
assertState(component, Sensor.SENSOR_CHANNEL_ID, DecimalType.valueOf("10"));
publishMessage("zigbee2mqtt/sensor/state", "20");
assertState(component, Sensor.sensorChannelID, DecimalType.valueOf("20"));
assertThat(component.getChannel(Sensor.sensorChannelID).getState().getCache().createStateDescription(true)
assertState(component, Sensor.SENSOR_CHANNEL_ID, DecimalType.valueOf("20"));
assertThat(component.getChannel(Sensor.SENSOR_CHANNEL_ID).getState().getCache().createStateDescription(true)
.build().getPattern(), is("%s W"));
waitForAssert(() -> assertState(component, Sensor.sensorChannelID, UnDefType.UNDEF), 10000, 200);
waitForAssert(() -> assertState(component, Sensor.SENSOR_CHANNEL_ID, UnDefType.UNDEF), 10000, 200);
}
protected Set<String> getConfigTopics() {

View File

@@ -50,17 +50,17 @@ public class SwitchTests extends AbstractComponentTests {
assertThat(component.channels.size(), is(1));
assertThat(component.getName(), is("th1 auto lock"));
assertChannel(component, Switch.switchChannelID, "zigbee2mqtt/th1", "zigbee2mqtt/th1/set/auto_lock", "state",
assertChannel(component, Switch.SWITCH_CHANNEL_ID, "zigbee2mqtt/th1", "zigbee2mqtt/th1/set/auto_lock", "state",
OnOffValue.class);
publishMessage("zigbee2mqtt/th1", "{\"auto_lock\": \"MANUAL\"}");
assertState(component, Switch.switchChannelID, OnOffType.OFF);
assertState(component, Switch.SWITCH_CHANNEL_ID, OnOffType.OFF);
publishMessage("zigbee2mqtt/th1", "{\"auto_lock\": \"AUTO\"}");
assertState(component, Switch.switchChannelID, OnOffType.ON);
assertState(component, Switch.SWITCH_CHANNEL_ID, OnOffType.ON);
component.getChannel(Switch.switchChannelID).getState().publishValue(OnOffType.OFF);
component.getChannel(Switch.SWITCH_CHANNEL_ID).getState().publishValue(OnOffType.OFF);
assertPublished("zigbee2mqtt/th1/set/auto_lock", "MANUAL");
component.getChannel(Switch.switchChannelID).getState().publishValue(OnOffType.ON);
component.getChannel(Switch.SWITCH_CHANNEL_ID).getState().publishValue(OnOffType.ON);
assertPublished("zigbee2mqtt/th1/set/auto_lock", "AUTO");
}
@@ -82,12 +82,12 @@ public class SwitchTests extends AbstractComponentTests {
assertThat(component.channels.size(), is(1));
assertThat(component.getName(), is("th1 auto lock"));
assertChannel(component, Switch.switchChannelID, "zigbee2mqtt/th1", "", "state", OnOffValue.class);
assertChannel(component, Switch.SWITCH_CHANNEL_ID, "zigbee2mqtt/th1", "", "state", OnOffValue.class);
publishMessage("zigbee2mqtt/th1", "{\"auto_lock\": \"MANUAL\"}");
assertState(component, Switch.switchChannelID, OnOffType.OFF);
assertState(component, Switch.SWITCH_CHANNEL_ID, OnOffType.OFF);
publishMessage("zigbee2mqtt/th1", "{\"auto_lock\": \"AUTO\"}");
assertState(component, Switch.switchChannelID, OnOffType.ON);
assertState(component, Switch.SWITCH_CHANNEL_ID, OnOffType.ON);
}
@Test
@@ -108,12 +108,12 @@ public class SwitchTests extends AbstractComponentTests {
assertThat(component.channels.size(), is(1));
assertThat(component.getName(), is("th1 auto lock"));
assertChannel(component, Switch.switchChannelID, "", "zigbee2mqtt/th1/set/auto_lock", "state",
assertChannel(component, Switch.SWITCH_CHANNEL_ID, "", "zigbee2mqtt/th1/set/auto_lock", "state",
OnOffValue.class);
component.getChannel(Switch.switchChannelID).getState().publishValue(OnOffType.OFF);
component.getChannel(Switch.SWITCH_CHANNEL_ID).getState().publishValue(OnOffType.OFF);
assertPublished("zigbee2mqtt/th1/set/auto_lock", "MANUAL");
component.getChannel(Switch.switchChannelID).getState().publishValue(OnOffType.ON);
component.getChannel(Switch.SWITCH_CHANNEL_ID).getState().publishValue(OnOffType.ON);
assertPublished("zigbee2mqtt/th1/set/auto_lock", "AUTO");
}

View File

@@ -47,8 +47,8 @@ import org.openhab.core.thing.binding.ThingHandlerCallback;
@SuppressWarnings({ "ConstantConditions" })
@ExtendWith(MockitoExtension.class)
public class HomeAssistantThingHandlerTests extends AbstractHomeAssistantTests {
private final static int SUBSCRIBE_TIMEOUT = 10000;
private final static int ATTRIBUTE_RECEIVE_TIMEOUT = 2000;
private static final int SUBSCRIBE_TIMEOUT = 10000;
private static final int ATTRIBUTE_RECEIVE_TIMEOUT = 2000;
private static final List<String> CONFIG_TOPICS = Arrays.asList("climate/0x847127fffe11dd6a_climate_zigbee2mqtt",
"switch/0x847127fffe11dd6a_auto_lock_zigbee2mqtt",

View File

@@ -1,60 +0,0 @@
/**
* Copyright (c) 2010-2021 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.mqtt.homeassistant.internal.handler;
import static org.openhab.binding.mqtt.homeassistant.generic.internal.MqttBindingConstants.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.thing.Channel;
import org.openhab.core.thing.ThingUID;
import org.openhab.core.thing.type.ChannelTypeUID;
/**
* Static test definitions, like thing, bridge and channel definitions
*
* @author David Graeff - Initial contribution
*/
@NonNullByDefault
public class ThingChannelConstants {
// Common ThingUID and ChannelUIDs
public static final ThingUID testHomeAssistantThing = new ThingUID(HOMEASSISTANT_MQTT_THING, "device234");
public static final ChannelTypeUID unknownChannel = new ChannelTypeUID(BINDING_ID, "unknown");
public static final String jsonPathJSON = "{ \"device\": { \"status\": { \"temperature\": 23.2 }}}";
public static final String jsonPathPattern = "$.device.status.temperature";
public static final List<Channel> thingChannelList = new ArrayList<>();
public static final List<Channel> thingChannelListWithJson = new ArrayList<>();
static Configuration textConfiguration() {
Map<String, Object> data = new HashMap<>();
data.put("stateTopic", "test/state");
data.put("commandTopic", "test/command");
return new Configuration(data);
}
static Configuration textConfigurationWithJson() {
Map<String, Object> data = new HashMap<>();
data.put("stateTopic", "test/state");
data.put("commandTopic", "test/command");
data.put("transformationPattern", "JSONPATH:" + jsonPathPattern);
return new Configuration(data);
}
}