[somfytahoma] Fixed rssi channels creation & properties updating (#11254)

Signed-off-by: Ondrej Pecta <opecta@gmail.com>
pull/11267/head
Ondrej Pecta 2021-09-18 13:56:36 +02:00 committed by GitHub
parent 805d56dc08
commit cbe537a43b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 6 deletions

View File

@ -129,7 +129,7 @@ You can list all the scenarios IDs with the following console command: `somfytah
### Remarks ### 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 When a roller shutter-like thing receives STOP command, there are two possible behaviours

View 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 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 int TAHOMA_TIMEOUT = 5;
public static final String UNAUTHORIZED = "Not logged in"; 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_PERCENT = 1;
public static final int TYPE_DECIMAL = 2; public static final int TYPE_DECIMAL = 2;
public static final int TYPE_STRING = 3; public static final int TYPE_STRING = 3;

View File

@ -47,6 +47,7 @@ import org.openhab.core.thing.ThingStatusInfo;
import org.openhab.core.thing.binding.BaseThingHandler; import org.openhab.core.thing.binding.BaseThingHandler;
import org.openhab.core.thing.binding.builder.ChannelBuilder; import org.openhab.core.thing.binding.builder.ChannelBuilder;
import org.openhab.core.thing.binding.builder.ThingBuilder; 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.Command;
import org.openhab.core.types.RefreshType; import org.openhab.core.types.RefreshType;
import org.openhab.core.types.State; import org.openhab.core.types.State;
@ -123,13 +124,15 @@ public abstract class SomfyTahomaBaseThingHandler extends BaseThingHandler {
private void createRSSIChannel() { private void createRSSIChannel() {
if (thing.getChannel(RSSI) == null) { if (thing.getChannel(RSSI) == null) {
logger.debug("{} Creating a rssi channel", url); 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(); 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); thingBuilder.withChannel(channel);
updateThing(thingBuilder.build()); updateThing(thingBuilder.build());
} }
@ -423,7 +426,7 @@ public abstract class SomfyTahomaBaseThingHandler extends BaseThingHandler {
Map<String, String> properties = new HashMap<>(); Map<String, String> properties = new HashMap<>();
for (SomfyTahomaState state : states) { for (SomfyTahomaState state : states) {
logger.trace("{} processing state: {} with value: {}", url, state.getName(), state.getValue()); 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())) { if (RSSI_LEVEL_STATE.equals(state.getName())) {
// RSSI channel is a dynamic one // RSSI channel is a dynamic one
updateRSSIChannel(state); updateRSSIChannel(state);

View File

@ -416,4 +416,12 @@
</options> </options>
</state> </state>
</channel-type> </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> </thing:thing-descriptions>