From 7ab0d99ddff7f3dcd80fc97e07789b16e612ca0d Mon Sep 17 00:00:00 2001 From: Stefan Triller Date: Sun, 7 Nov 2021 15:13:51 +0100 Subject: [PATCH] Addressed review comments Signed-off-by: Stefan Triller --- .../internal/component/Vacuum.java | 178 +++++++++--------- 1 file changed, 89 insertions(+), 89 deletions(-) diff --git a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Vacuum.java b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Vacuum.java index d3d1734677e92..b708711047ce0 100644 --- a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Vacuum.java +++ b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Vacuum.java @@ -31,35 +31,35 @@ */ @NonNullByDefault public class Vacuum extends AbstractComponent { - public static final String vacuumStateChannelID = "state"; - public static final String vacuumCommandChannelID = "command"; - public static final String vacuumBatteryChannelID = "batteryLevel"; - public static final String vacuumFanSpeedChannelID = "fanSpeed"; + public static final String VACUUM_STATE_CHANNEL_ID = "state"; + public static final String VACUUM_COMMAND_CHANNEL_ID = "command"; + public static final String VACUUM_BATTERY_CHANNEL_ID = "batteryLevel"; + public static final String VACUUM_FAN_SPEED_CHANNEL_ID = "fanSpeed"; // sensor stats - public static final String vacuumMainBrushChannelID = "mainBrushUsage"; - public static final String vacuumSideBrushChannelID = "sideBrushUsage"; - public static final String vacuumFilterChannelID = "filter"; - public static final String vacuumSensorChannelID = "sensor"; - public static final String vacuumCurrentCleanTimeChannelID = "currentCleanTime"; - public static final String vacuumCurrentCleanAreaChannelID = "currentCleanArea"; - public static final String vacuumCleanTimeChannelID = "cleanTime"; - public static final String vacuumCleanAreaChannelID = "cleanArea"; - public static final String vacuumCleanCountChannelID = "cleanCount"; - - public static final String vacuumLastRunStartChannelID = "lastRunStart"; - public static final String vacuumLastRunEndChannelID = "lastRunEnd"; - public static final String vacuumLastRunDurationChannelID = "lastRunDuration"; - public static final String vacuumLastRunAreaChannelID = "lastRunArea"; - public static final String vacuumLastRunErrorCodeChannelID = "lastRunErrorCode"; - public static final String vacuumLastRunErrorDescriptionChannelID = "lastRunErrorDescription"; - public static final String vacuumLastRunFinishedFlagChannelID = "lastRunFinishedFlag"; - - public static final String vacuumBinInTimeChannelID = "binInTime"; - public static final String vacuumLastBinOutChannelID = "lastBinOutTime"; - public static final String vacuumlastBinFullChannelID = "lastBinFullTime"; - - public static final String vacuumCustomCommandChannelID = "customCommand"; + public static final String VACUUM_MAIN_BRUSH_CHANNEL_ID = "mainBrushUsage"; + public static final String VACUUM_SIDE_BRUSH_CHANNEL_ID = "sideBrushUsage"; + public static final String VACUUM_FILTER_CHANNEL_ID = "filter"; + public static final String VACUUM_SENSOR_CHANNEL_ID = "sensor"; + public static final String VACUUM_CURRENT_CLEAN_TIME_CHANNEL_ID = "currentCleanTime"; + public static final String VACUUM_CURRENT_CLEAN_AREA_CHANNEL_ID = "currentCleanArea"; + public static final String VACUUM_CLEAN_TIME_CHANNEL_ID = "cleanTime"; + public static final String VACUUM_CLEAN_AREA_CHANNEL_ID = "cleanArea"; + public static final String VACUUM_CLEAN_COUNT_CHANNEL_ID = "cleanCount"; + + public static final String VACUUM_LAST_RUN_START_CHANNEL_ID = "lastRunStart"; + public static final String VACUUM_LAST_RUN_END_CHANNEL_ID = "lastRunEnd"; + public static final String VACUUM_LAST_RUN_DURATION_CHANNEL_ID = "lastRunDuration"; + public static final String VACUUM_LAST_RUN_AREA_CHANNEL_ID = "lastRunArea"; + public static final String VACUUM_LAST_RUN_ERROR_CODE_CHANNEL_ID = "lastRunErrorCode"; + public static final String VACUUM_LAST_RUN_ERROR_DESCRIPTION_CHANNEL_ID = "lastRunErrorDescription"; + public static final String VACUUM_LAST_RUN_FINISHED_FLAG_CHANNEL_ID = "lastRunFinishedFlag"; + + public static final String VACUUM_BIN_IN_TIME_CHANNEL_ID = "binInTime"; + public static final String VACUUM_LAST_BIN_OUT_TIME_CHANNEL_ID = "lastBinOutTime"; + public static final String VACUUM_LAST_BIN_FULL_TIME_CHANNEL_ID = "lastBinFullTime"; + + public static final String VACUUM_CUSMTOM_COMMAND_CHANNEL_ID = "customCommand"; /** * Configuration class for MQTT component @@ -69,23 +69,23 @@ static class ChannelConfiguration extends AbstractChannelConfiguration { super("MQTT Vacuum"); } - protected @Nullable String command_topic; - protected String state_topic = ""; - protected @Nullable String send_command_topic; // for custom_command + protected @Nullable String commandTopic; + protected String stateTopic = ""; + protected @Nullable String sendCommandTopic; // for custom_command // [start, pause, stop, return_home, battery, status, locate, clean_spot, fan_speed, send_command] - protected String[] supported_features = new String[] {}; - protected @Nullable String set_fan_speed_topic; - protected String[] fan_speed_list = new String[] {}; + protected String[] supportedFeatures = new String[] {}; + protected @Nullable String setFanSpeedTopic; + protected String[] fanSpeedList = new String[] {}; - protected @Nullable String json_attributes_topic; - protected @Nullable String json_attributes_template; + protected @Nullable String jsonAttributesTopic; + protected @Nullable String jsonAttributesTemplate; } public Vacuum(ComponentFactory.ComponentConfiguration componentConfiguration) { super(componentConfiguration, ChannelConfiguration.class); - List features = Arrays.asList(channelConfiguration.supported_features); + List features = Arrays.asList(channelConfiguration.supportedFeatures); // features = [start, pause, stop, return_home, status, locate, clean_spot, fan_speed, send_command] ArrayList possibleCommands = new ArrayList(); @@ -110,156 +110,156 @@ public Vacuum(ComponentFactory.ComponentConfiguration componentConfiguration) { } TextValue value = new TextValue(possibleCommands.toArray(new String[0])); - buildChannel(vacuumCommandChannelID, value, "Command", componentConfiguration.getUpdateListener()) - .stateTopic(channelConfiguration.command_topic) - .commandTopic(channelConfiguration.command_topic, false, 1).build(); + buildChannel(VACUUM_COMMAND_CHANNEL_ID, value, "Command", componentConfiguration.getUpdateListener()) + .stateTopic(channelConfiguration.commandTopic) + .commandTopic(channelConfiguration.commandTopic, false, 1).build(); List vacuumStates = List.of("docked", "cleaning", "returning", "paused", "idle", "error"); TextValue valueState = new TextValue(vacuumStates.toArray(new String[0])); - buildChannel(vacuumStateChannelID, valueState, "State", componentConfiguration.getUpdateListener()) - .stateTopic(channelConfiguration.state_topic, "{{value_json.state}}").build(); + buildChannel(VACUUM_STATE_CHANNEL_ID, valueState, "State", componentConfiguration.getUpdateListener()) + .stateTopic(channelConfiguration.stateTopic, "{{value_json.state}}").build(); if (features.contains("battery")) { // build battery level channel (0-100) NumberValue batValue = new NumberValue(BigDecimal.ZERO, new BigDecimal(100), new BigDecimal(1), "%"); - buildChannel(vacuumBatteryChannelID, batValue, "Battery Level", componentConfiguration.getUpdateListener()) - .stateTopic(channelConfiguration.state_topic, "{{value_json.battery_level}}").build(); + buildChannel(VACUUM_BATTERY_CHANNEL_ID, batValue, "Battery Level", componentConfiguration.getUpdateListener()) + .stateTopic(channelConfiguration.stateTopic, "{{value_json.battery_level}}").build(); } if (features.contains("fan_speed")) { // build fan speed channel with values from channelConfiguration.fan_speed_list - TextValue fanValue = new TextValue(channelConfiguration.fan_speed_list); - buildChannel(vacuumFanSpeedChannelID, fanValue, "Fan speed", componentConfiguration.getUpdateListener()) - .stateTopic(channelConfiguration.state_topic, "{{value_json.fan_speed}}") - .commandTopic(channelConfiguration.set_fan_speed_topic, false, 1).build(); + TextValue fanValue = new TextValue(channelConfiguration.fanSpeedList); + buildChannel(VACUUM_FAN_SPEED_CHANNEL_ID, fanValue, "Fan speed", componentConfiguration.getUpdateListener()) + .stateTopic(channelConfiguration.stateTopic, "{{value_json.fan_speed}}") + .commandTopic(channelConfiguration.setFanSpeedTopic, false, 1).build(); } // {"mainBrush":"220.6","sideBrush":"120.6","filter":"70.6","sensor":"0.0","currentCleanTime":"0.0","currentCleanArea":"0.0","cleanTime":"79.3","cleanArea":"4439.9","cleanCount":183,"last_run_stats":{"startTime":1613503117000,"endTime":1613503136000,"duration":0,"area":"0.0","errorCode":0,"errorDescription":"No // error","finishedFlag":false},"bin_in_time":1000,"last_bin_out":-1,"last_bin_full":-1,"last_loaded_map":null,"state":"docked","valetudo_state":{"id":8,"name":"Charging"}} if (features.contains("status")) { NumberValue currentCleanTimeValue = new NumberValue(null, null, null, null); - buildChannel(vacuumCurrentCleanTimeChannelID, currentCleanTimeValue, "Current Cleaning Time", + buildChannel(VACUUM_CURRENT_CLEAN_TIME_CHANNEL_ID, currentCleanTimeValue, "Current Cleaning Time", componentConfiguration.getUpdateListener()) - .stateTopic(channelConfiguration.json_attributes_topic, "{{value_json.currentCleanTime}}") + .stateTopic(channelConfiguration.jsonAttributesTopic, "{{value_json.currentCleanTime}}") .build(); NumberValue currentCleanAreaValue = new NumberValue(null, null, null, null); - buildChannel(vacuumCurrentCleanAreaChannelID, currentCleanAreaValue, "Current Cleaning Area", + buildChannel(VACUUM_CURRENT_CLEAN_AREA_CHANNEL_ID, currentCleanAreaValue, "Current Cleaning Area", componentConfiguration.getUpdateListener()) - .stateTopic(channelConfiguration.json_attributes_topic, "{{value_json.currentCleanArea}}") + .stateTopic(channelConfiguration.jsonAttributesTopic, "{{value_json.currentCleanArea}}") .build(); NumberValue cleanTimeValue = new NumberValue(null, null, null, null); - buildChannel(vacuumCleanTimeChannelID, cleanTimeValue, "Cleaning Time", + buildChannel(VACUUM_CLEAN_TIME_CHANNEL_ID, cleanTimeValue, "Cleaning Time", componentConfiguration.getUpdateListener()) - .stateTopic(channelConfiguration.json_attributes_topic, "{{value_json.cleanTime}}").build(); + .stateTopic(channelConfiguration.jsonAttributesTopic, "{{value_json.cleanTime}}").build(); NumberValue cleanAreaValue = new NumberValue(null, null, null, null); - buildChannel(vacuumCleanAreaChannelID, cleanAreaValue, "Cleaned Area", + buildChannel(VACUUM_CLEAN_AREA_CHANNEL_ID, cleanAreaValue, "Cleaned Area", componentConfiguration.getUpdateListener()) - .stateTopic(channelConfiguration.json_attributes_topic, "{{value_json.cleanArea}}").build(); + .stateTopic(channelConfiguration.jsonAttributesTopic, "{{value_json.cleanArea}}").build(); NumberValue cleaCountValue = new NumberValue(null, null, null, null); - buildChannel(vacuumCleanCountChannelID, cleaCountValue, "Cleaning Counter", + buildChannel(VACUUM_CLEAN_COUNT_CHANNEL_ID, cleaCountValue, "Cleaning Counter", componentConfiguration.getUpdateListener()) - .stateTopic(channelConfiguration.json_attributes_topic, "{{value_json.cleanCount}}") + .stateTopic(channelConfiguration.jsonAttributesTopic, "{{value_json.cleanCount}}") .build(); DateTimeValue lastStartTime = new DateTimeValue(); - buildChannel(vacuumLastRunStartChannelID, lastStartTime, "Last run start time", + buildChannel(VACUUM_LAST_RUN_START_CHANNEL_ID, lastStartTime, "Last run start time", componentConfiguration.getUpdateListener()) - .stateTopic(channelConfiguration.json_attributes_topic, + .stateTopic(channelConfiguration.jsonAttributesTopic, "{{value_json.last_run_stats.startTime}}") .build(); DateTimeValue lastEndTime = new DateTimeValue(); - buildChannel(vacuumLastRunEndChannelID, lastEndTime, "Last run end time", + buildChannel(VACUUM_LAST_RUN_END_CHANNEL_ID, lastEndTime, "Last run end time", componentConfiguration.getUpdateListener()) - .stateTopic(channelConfiguration.json_attributes_topic, + .stateTopic(channelConfiguration.jsonAttributesTopic, "{{value_json.last_run_stats.endTime}}") .build(); NumberValue lastRunDurationValue = new NumberValue(null, null, null, null); - buildChannel(vacuumLastRunDurationChannelID, lastRunDurationValue, "Last run duration", + buildChannel(VACUUM_LAST_RUN_DURATION_CHANNEL_ID, lastRunDurationValue, "Last run duration", componentConfiguration.getUpdateListener()) - .stateTopic(channelConfiguration.json_attributes_topic, + .stateTopic(channelConfiguration.jsonAttributesTopic, "{{value_json.last_run_stats.duration}}") .build(); NumberValue lastRunAreaValue = new NumberValue(null, null, null, null); - buildChannel(vacuumLastRunAreaChannelID, lastRunAreaValue, "Last run area", + buildChannel(VACUUM_LAST_RUN_AREA_CHANNEL_ID, lastRunAreaValue, "Last run area", componentConfiguration.getUpdateListener()) - .stateTopic(channelConfiguration.json_attributes_topic, + .stateTopic(channelConfiguration.jsonAttributesTopic, "{{value_json.last_run_stats.area}}") .build(); NumberValue lastRunErrorCodeValue = new NumberValue(null, null, null, null); - buildChannel(vacuumLastRunErrorCodeChannelID, lastRunErrorCodeValue, "Last run error code", + buildChannel(VACUUM_LAST_RUN_ERROR_CODE_CHANNEL_ID, lastRunErrorCodeValue, "Last run error code", componentConfiguration.getUpdateListener()) - .stateTopic(channelConfiguration.json_attributes_topic, + .stateTopic(channelConfiguration.jsonAttributesTopic, "{{value_json.last_run_stats.errorCode}}") .build(); TextValue lastRunErrorDescriptionValue = new TextValue(); - buildChannel(vacuumLastRunErrorDescriptionChannelID, lastRunErrorDescriptionValue, + buildChannel(VACUUM_LAST_RUN_ERROR_DESCRIPTION_CHANNEL_ID, lastRunErrorDescriptionValue, "Last run error description", componentConfiguration.getUpdateListener()) - .stateTopic(channelConfiguration.json_attributes_topic, + .stateTopic(channelConfiguration.jsonAttributesTopic, "{{value_json.last_run_stats.errorDescription}}") .build(); // true/false doesnt map to ON/OFF => use TextValue instead of OnOffValue TextValue lastRunFinishedFlagValue = new TextValue(); - buildChannel(vacuumLastRunFinishedFlagChannelID, lastRunFinishedFlagValue, "Last run finished flag", + buildChannel(VACUUM_LAST_RUN_FINISHED_FLAG_CHANNEL_ID, lastRunFinishedFlagValue, "Last run finished flag", componentConfiguration.getUpdateListener()) - .stateTopic(channelConfiguration.json_attributes_topic, + .stateTopic(channelConfiguration.jsonAttributesTopic, "{{value_json.last_run_stats.finishedFlag}}") .build(); // only for valetudo re => advanced channels DateTimeValue binInValue = new DateTimeValue(); - buildChannel(vacuumBinInTimeChannelID, binInValue, "Bin In Time", + buildChannel(VACUUM_BIN_IN_TIME_CHANNEL_ID, binInValue, "Bin In Time", componentConfiguration.getUpdateListener()) - .stateTopic(channelConfiguration.json_attributes_topic, "{{value_json.bin_in_time}}") + .stateTopic(channelConfiguration.jsonAttributesTopic, "{{value_json.bin_in_time}}") .isAdvanced(true).build(); DateTimeValue lastBinOutValue = new DateTimeValue(); - buildChannel(vacuumLastBinOutChannelID, lastBinOutValue, "Last Bin Out Time", + buildChannel(VACUUM_LAST_BIN_OUT_TIME_CHANNEL_ID, lastBinOutValue, "Last Bin Out Time", componentConfiguration.getUpdateListener()) - .stateTopic(channelConfiguration.json_attributes_topic, "{{value_json.last_bin_out}}") + .stateTopic(channelConfiguration.jsonAttributesTopic, "{{value_json.last_bin_out}}") .isAdvanced(true).build(); DateTimeValue lastBinFullValue = new DateTimeValue(); - buildChannel(vacuumlastBinFullChannelID, lastBinFullValue, "Last Bin Full Time", + buildChannel(VACUUM_LAST_BIN_FULL_TIME_CHANNEL_ID, lastBinFullValue, "Last Bin Full Time", componentConfiguration.getUpdateListener()) - .stateTopic(channelConfiguration.json_attributes_topic, "{{value_json.last_bin_full}}") + .stateTopic(channelConfiguration.jsonAttributesTopic, "{{value_json.last_bin_full}}") .isAdvanced(true).build(); } NumberValue mainBrush = new NumberValue(null, null, null, null); - buildChannel(vacuumMainBrushChannelID, mainBrush, "Main brush usage", + buildChannel(VACUUM_MAIN_BRUSH_CHANNEL_ID, mainBrush, "Main brush usage", componentConfiguration.getUpdateListener()) - .stateTopic(channelConfiguration.json_attributes_topic, "{{value_json.mainBrush}}").build(); + .stateTopic(channelConfiguration.jsonAttributesTopic, "{{value_json.mainBrush}}").build(); NumberValue sideBrush = new NumberValue(null, null, null, null); - buildChannel(vacuumSideBrushChannelID, sideBrush, "Side brush usage", + buildChannel(VACUUM_SIDE_BRUSH_CHANNEL_ID, sideBrush, "Side brush usage", componentConfiguration.getUpdateListener()) - .stateTopic(channelConfiguration.json_attributes_topic, "{{value_json.sideBrush}}").build(); + .stateTopic(channelConfiguration.jsonAttributesTopic, "{{value_json.sideBrush}}").build(); NumberValue filterValue = new NumberValue(null, null, null, null); - buildChannel(vacuumFilterChannelID, filterValue, "Filter time", componentConfiguration.getUpdateListener()) - .stateTopic(channelConfiguration.json_attributes_topic, "{{value_json.filter}}").build(); + buildChannel(VACUUM_FILTER_CHANNEL_ID, filterValue, "Filter time", componentConfiguration.getUpdateListener()) + .stateTopic(channelConfiguration.jsonAttributesTopic, "{{value_json.filter}}").build(); NumberValue sensorValue = new NumberValue(null, null, null, null); - buildChannel(vacuumSensorChannelID, sensorValue, "Sensor", componentConfiguration.getUpdateListener()) - .stateTopic(channelConfiguration.json_attributes_topic, "{{value_json.sensor}}").build(); + buildChannel(VACUUM_SENSOR_CHANNEL_ID, sensorValue, "Sensor", componentConfiguration.getUpdateListener()) + .stateTopic(channelConfiguration.jsonAttributesTopic, "{{value_json.sensor}}").build(); // if we have a custom command channel for zone cleanup, etc => create text channel - if (channelConfiguration.send_command_topic != null) { + if (channelConfiguration.sendCommandTopic != null) { TextValue customCommandValue = new TextValue(); - buildChannel(vacuumCustomCommandChannelID, customCommandValue, "Custom Command", + buildChannel(VACUUM_CUSMTOM_COMMAND_CHANNEL_ID, customCommandValue, "Custom Command", componentConfiguration.getUpdateListener()) - .commandTopic(channelConfiguration.send_command_topic, false, 1) - .stateTopic(channelConfiguration.send_command_topic).build(); + .commandTopic(channelConfiguration.sendCommandTopic, false, 1) + .stateTopic(channelConfiguration.sendCommandTopic).build(); } } }