From dba87c6a39d2a067f4a97d29140fc8fc528b2716 Mon Sep 17 00:00:00 2001 From: Ondrej Pecta Date: Sat, 18 Sep 2021 13:56:36 +0200 Subject: [PATCH] [somfytahoma] Fixed rssi channels creation & properties updating (#11254) Signed-off-by: Ondrej Pecta --- bundles/org.openhab.binding.somfytahoma/README.md | 4 ++-- .../internal/SomfyTahomaBindingConstants.java | 1 + .../internal/handler/SomfyTahomaBaseThingHandler.java | 11 +++++++---- .../src/main/resources/OH-INF/thing/channels.xml | 8 ++++++++ 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/bundles/org.openhab.binding.somfytahoma/README.md b/bundles/org.openhab.binding.somfytahoma/README.md index f44a5ed69e122..be25f76e8199c 100644 --- a/bundles/org.openhab.binding.somfytahoma/README.md +++ b/bundles/org.openhab.binding.somfytahoma/README.md @@ -70,7 +70,7 @@ Please see the example below. | roller shutter, screen, venetian blind, garage door, awning, pergola, curtain | control | device controller which reacts to commands UP/DOWN/ON/OFF/OPEN/CLOSE/MY/STOP + closure 0-100 | | window | control | device controller which reacts to commands UP/DOWN/ON/OFF/OPEN/CLOSE/STOP + closure 0-100 | | silent roller shutter | silent_control | similar to control channel but in silent mode | -| venetian blind, adjustable slats roller shutter, bioclimatic pergola | orientation | percentual orientation of the blind's slats, it can have value 0-100. For IO Homecontrol devices only (non RTS) | +| venetian blind, adjustable slats roller shutter, bioclimatic pergola | orientation | percentual orientation of the blind's slats, it can have value 0-100. For IO Homecontrol devices only (non RTS) | | venetian blind, adjustable slats roller shutter | closure_orientation | percentual closure and orientation of the blind's slats, it can have value 0-100. For IO Homecontrol devices only (non RTS) | | adjustable slats roller shutter | rocker | used for setting the rocker position of the roller shutter, the only position allowing the slats control | | bioclimatic pergola | slats | slats state (open/closed) | @@ -129,7 +129,7 @@ You can list all the scenarios IDs with the following console command: `somfytah ### Remarks -All things which have a RSSI (relative received signal) state, expose a channel "rssi". +All things which have a RSSI (received signal strength indication) state, expose a channel "rssi". When a roller shutter-like thing receives STOP command, there are two possible behaviours diff --git a/bundles/org.openhab.binding.somfytahoma/src/main/java/org/openhab/binding/somfytahoma/internal/SomfyTahomaBindingConstants.java b/bundles/org.openhab.binding.somfytahoma/src/main/java/org/openhab/binding/somfytahoma/internal/SomfyTahomaBindingConstants.java index 8d27c2f73010b..ce56a2c2a361c 100644 --- a/bundles/org.openhab.binding.somfytahoma/src/main/java/org/openhab/binding/somfytahoma/internal/SomfyTahomaBindingConstants.java +++ b/bundles/org.openhab.binding.somfytahoma/src/main/java/org/openhab/binding/somfytahoma/internal/SomfyTahomaBindingConstants.java @@ -293,6 +293,7 @@ public class SomfyTahomaBindingConstants { public static final String TAHOMA_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36"; public static final int TAHOMA_TIMEOUT = 5; public static final String UNAUTHORIZED = "Not logged in"; + public static final int TYPE_NONE = 0; public static final int TYPE_PERCENT = 1; public static final int TYPE_DECIMAL = 2; public static final int TYPE_STRING = 3; diff --git a/bundles/org.openhab.binding.somfytahoma/src/main/java/org/openhab/binding/somfytahoma/internal/handler/SomfyTahomaBaseThingHandler.java b/bundles/org.openhab.binding.somfytahoma/src/main/java/org/openhab/binding/somfytahoma/internal/handler/SomfyTahomaBaseThingHandler.java index 5fa6b136a4e83..12d7790010e72 100644 --- a/bundles/org.openhab.binding.somfytahoma/src/main/java/org/openhab/binding/somfytahoma/internal/handler/SomfyTahomaBaseThingHandler.java +++ b/bundles/org.openhab.binding.somfytahoma/src/main/java/org/openhab/binding/somfytahoma/internal/handler/SomfyTahomaBaseThingHandler.java @@ -47,6 +47,7 @@ import org.openhab.core.thing.binding.BaseThingHandler; import org.openhab.core.thing.binding.builder.ChannelBuilder; import org.openhab.core.thing.binding.builder.ThingBuilder; +import org.openhab.core.thing.type.ChannelTypeUID; import org.openhab.core.types.Command; import org.openhab.core.types.RefreshType; import org.openhab.core.types.State; @@ -123,13 +124,15 @@ public void initializeThing(@Nullable ThingStatus bridgeStatus) { private void createRSSIChannel() { if (thing.getChannel(RSSI) == null) { logger.debug("{} Creating a rssi channel", url); - createChannel(RSSI, "Number", "RSSI Level"); + ChannelTypeUID rssi = new ChannelTypeUID(BINDING_ID, "rssi"); + createChannel(RSSI, "Number", "RSSI Level", rssi); } } - private void createChannel(String name, String type, String label) { + private void createChannel(String name, String type, String label, ChannelTypeUID channelType) { ThingBuilder thingBuilder = editThing(); - Channel channel = ChannelBuilder.create(new ChannelUID(thing.getUID(), name), type).withLabel(label).build(); + Channel channel = ChannelBuilder.create(new ChannelUID(thing.getUID(), name), type).withLabel(label) + .withType(channelType).build(); thingBuilder.withChannel(channel); updateThing(thingBuilder.build()); } @@ -423,7 +426,7 @@ public void updateThingChannels(List states) { Map properties = new HashMap<>(); for (SomfyTahomaState state : states) { logger.trace("{} processing state: {} with value: {}", url, state.getName(), state.getValue()); - properties.put(state.getName(), state.getValue().toString()); + properties.put(state.getName(), TYPE_NONE != state.getType() ? state.getValue().toString() : ""); if (RSSI_LEVEL_STATE.equals(state.getName())) { // RSSI channel is a dynamic one updateRSSIChannel(state); diff --git a/bundles/org.openhab.binding.somfytahoma/src/main/resources/OH-INF/thing/channels.xml b/bundles/org.openhab.binding.somfytahoma/src/main/resources/OH-INF/thing/channels.xml index 44fee7caf86e6..5b607db82ce86 100644 --- a/bundles/org.openhab.binding.somfytahoma/src/main/resources/OH-INF/thing/channels.xml +++ b/bundles/org.openhab.binding.somfytahoma/src/main/resources/OH-INF/thing/channels.xml @@ -416,4 +416,12 @@ + + + Number + + Relative received signal strength state + + +