]> git.basschouten.com Git - openhab-addons.git/commitdiff
[somfytahoma] Fixed rssi channels creation & properties updating (#11254)
authorOndrej Pecta <opecta@gmail.com>
Sat, 18 Sep 2021 11:56:36 +0000 (13:56 +0200)
committerGitHub <noreply@github.com>
Sat, 18 Sep 2021 11:56:36 +0000 (13:56 +0200)
Signed-off-by: Ondrej Pecta <opecta@gmail.com>
bundles/org.openhab.binding.somfytahoma/README.md
bundles/org.openhab.binding.somfytahoma/src/main/java/org/openhab/binding/somfytahoma/internal/SomfyTahomaBindingConstants.java
bundles/org.openhab.binding.somfytahoma/src/main/java/org/openhab/binding/somfytahoma/internal/handler/SomfyTahomaBaseThingHandler.java
bundles/org.openhab.binding.somfytahoma/src/main/resources/OH-INF/thing/channels.xml

index f44a5ed69e12230431a0995571f15764c1ef08ca..be25f76e8199c577f1c14d44ed48236e05ac5c39 100644 (file)
@@ -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
 
index 8d27c2f73010b97a02447b9cb62c80db32369be4..ce56a2c2a361ca9906e5f983235afeb8e28ce186 100644 (file)
@@ -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;
index 5fa6b136a4e83e1fa5279306526c9713914b73e6..12d7790010e72a273589bd77778c9ea83e879b09 100644 (file)
@@ -47,6 +47,7 @@ import org.openhab.core.thing.ThingStatusInfo;
 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 abstract class SomfyTahomaBaseThingHandler extends BaseThingHandler {
     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 abstract class SomfyTahomaBaseThingHandler extends BaseThingHandler {
         Map<String, String> 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);
index 44fee7caf86e670c7c96ddcd6095e1b251b6659f..5b607db82ce868dbcbf6567966a362094adaed16 100644 (file)
                        </options>
                </state>
        </channel-type>
+
+       <channel-type id="rssi">
+               <item-type>Number</item-type>
+               <label>RSSI</label>
+               <description>Relative received signal strength state</description>
+               <state pattern="%.1f" readOnly="true"/>
+       </channel-type>
+
 </thing:thing-descriptions>