diff --git a/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/BindingConstants.java b/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/BindingConstants.java index 595f1716282f6..0cf5c0c0d2cea 100644 --- a/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/BindingConstants.java +++ b/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/BindingConstants.java @@ -15,7 +15,6 @@ import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.core.library.types.PercentType; import org.openhab.core.thing.ThingTypeUID; -import org.openhab.core.thing.type.ChannelTypeUID; /** * The {@link BindingConstants} class defines common constants, which are @@ -120,11 +119,6 @@ public class BindingConstants { public static final String CHANNEL_SCENE = "scene"; public static final String CHANNEL_ONTIME = "ontime"; - // channel uids - public static final ChannelTypeUID CHANNEL_EFFECT_TYPE_UID = new ChannelTypeUID(BINDING_ID, CHANNEL_EFFECT); - public static final ChannelTypeUID CHANNEL_EFFECT_SPEED_TYPE_UID = new ChannelTypeUID(BINDING_ID, - CHANNEL_EFFECT_SPEED); - // Thing configuration public static final String CONFIG_HOST = "host"; public static final String CONFIG_HTTP_PORT = "httpPort"; diff --git a/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/handler/DeconzBaseThingHandler.java b/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/handler/DeconzBaseThingHandler.java index 9f40f49022676..e869fd15cbb5b 100644 --- a/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/handler/DeconzBaseThingHandler.java +++ b/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/handler/DeconzBaseThingHandler.java @@ -12,6 +12,8 @@ */ package org.openhab.binding.deconz.internal.handler; +import static org.openhab.binding.deconz.internal.BindingConstants.*; + import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; import java.util.function.Consumer; @@ -25,12 +27,16 @@ import org.openhab.binding.deconz.internal.netutils.WebSocketMessageListener; import org.openhab.binding.deconz.internal.types.ResourceType; import org.openhab.core.thing.Bridge; +import org.openhab.core.thing.Channel; import org.openhab.core.thing.ChannelUID; import org.openhab.core.thing.Thing; import org.openhab.core.thing.ThingStatus; import org.openhab.core.thing.ThingStatusDetail; import org.openhab.core.thing.ThingStatusInfo; import org.openhab.core.thing.binding.BaseThingHandler; +import org.openhab.core.thing.binding.ThingHandlerCallback; +import org.openhab.core.thing.type.ChannelKind; +import org.openhab.core.thing.type.ChannelTypeUID; import org.openhab.core.types.Command; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -222,4 +228,30 @@ public void initialize() { bridgeStatusChanged(bridge.getStatusInfo()); } } + + protected void createChannel(String channelId, ChannelKind kind) { + if (thing.getChannel(channelId) != null) { + // channel already exists, no update necessary + return; + } + + ThingHandlerCallback callback = getCallback(); + if (callback != null) { + ChannelUID channelUID = new ChannelUID(thing.getUID(), channelId); + ChannelTypeUID channelTypeUID; + switch (channelId) { + case CHANNEL_BATTERY_LEVEL: + channelTypeUID = new ChannelTypeUID("system:battery-level"); + break; + case CHANNEL_BATTERY_LOW: + channelTypeUID = new ChannelTypeUID("system:low-battery"); + break; + default: + channelTypeUID = new ChannelTypeUID(BINDING_ID, channelId); + break; + } + Channel channel = callback.createChannelBuilder(channelUID, channelTypeUID).withKind(kind).build(); + updateThing(editThing().withChannel(channel).build()); + } + } } diff --git a/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/handler/LightThingHandler.java b/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/handler/LightThingHandler.java index dab69ea8100b2..4a6a81328b481 100644 --- a/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/handler/LightThingHandler.java +++ b/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/handler/LightThingHandler.java @@ -46,8 +46,7 @@ import org.openhab.core.thing.ThingStatus; import org.openhab.core.thing.ThingStatusDetail; import org.openhab.core.thing.ThingTypeUID; -import org.openhab.core.thing.binding.builder.ChannelBuilder; -import org.openhab.core.thing.binding.builder.ThingBuilder; +import org.openhab.core.thing.type.ChannelKind; import org.openhab.core.types.Command; import org.openhab.core.types.CommandOption; import org.openhab.core.types.RefreshType; @@ -346,22 +345,13 @@ private void checkAndUpdateEffectChannels(LightMessage lightMessage) { } ChannelUID effectChannelUID = new ChannelUID(thing.getUID(), CHANNEL_EFFECT); - ChannelUID effectSpeedChannelUID = new ChannelUID(thing.getUID(), CHANNEL_EFFECT_SPEED); - - if (thing.getChannel(CHANNEL_EFFECT) == null) { - ThingBuilder thingBuilder = editThing(); - thingBuilder.withChannel( - ChannelBuilder.create(effectChannelUID, "String").withType(CHANNEL_EFFECT_TYPE_UID).build()); - if (model == EffectLightModel.LIDL_MELINARA) { - // additional channels - thingBuilder.withChannel(ChannelBuilder.create(effectSpeedChannelUID, "Number") - .withType(CHANNEL_EFFECT_SPEED_TYPE_UID).build()); - } - updateThing(thingBuilder.build()); - } + createChannel(CHANNEL_EFFECT, ChannelKind.STATE); switch (model) { case LIDL_MELINARA: + // additional channels + createChannel(CHANNEL_EFFECT_SPEED, ChannelKind.STATE); + List options = List.of("none", "steady", "snow", "rainbow", "snake", "tinkle", "fireworks", "flag", "waves", "updown", "vintage", "fading", "collide", "strobe", "sparkles", "carnival", "glow"); diff --git a/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/handler/SensorBaseThingHandler.java b/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/handler/SensorBaseThingHandler.java index 389d8c83f69c8..f54998b58b84a 100644 --- a/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/handler/SensorBaseThingHandler.java +++ b/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/handler/SensorBaseThingHandler.java @@ -38,9 +38,7 @@ import org.openhab.core.thing.Thing; import org.openhab.core.thing.ThingStatus; import org.openhab.core.thing.ThingStatusDetail; -import org.openhab.core.thing.binding.ThingHandlerCallback; import org.openhab.core.thing.type.ChannelKind; -import org.openhab.core.thing.type.ChannelTypeUID; import org.openhab.core.types.Command; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -172,32 +170,6 @@ private void processLastSeen(DeconzBaseMessage stateResponse) { } } - protected void createChannel(String channelId, ChannelKind kind) { - if (thing.getChannel(channelId) != null) { - // channel already exists, no update necessary - return; - } - - ThingHandlerCallback callback = getCallback(); - if (callback != null) { - ChannelUID channelUID = new ChannelUID(thing.getUID(), channelId); - ChannelTypeUID channelTypeUID; - switch (channelId) { - case CHANNEL_BATTERY_LEVEL: - channelTypeUID = new ChannelTypeUID("system:battery-level"); - break; - case CHANNEL_BATTERY_LOW: - channelTypeUID = new ChannelTypeUID("system:low-battery"); - break; - default: - channelTypeUID = new ChannelTypeUID(BINDING_ID, channelId); - break; - } - Channel channel = callback.createChannelBuilder(channelUID, channelTypeUID).withKind(kind).build(); - updateThing(editThing().withChannel(channel).build()); - } - } - /** * Update channel value from {@link SensorConfig} object - override to include further channels * diff --git a/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/handler/SensorThermostatThingHandler.java b/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/handler/SensorThermostatThingHandler.java index a3df6fb063245..f6e83fbb23a87 100644 --- a/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/handler/SensorThermostatThingHandler.java +++ b/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/handler/SensorThermostatThingHandler.java @@ -39,9 +39,7 @@ import org.openhab.core.thing.ChannelUID; import org.openhab.core.thing.Thing; import org.openhab.core.thing.ThingTypeUID; -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.thing.type.ChannelKind; import org.openhab.core.types.Command; import org.openhab.core.types.RefreshType; import org.slf4j.Logger; @@ -201,11 +199,8 @@ protected void processStateResponse(DeconzBaseMessage stateResponse) { SensorMessage sensorMessage = (SensorMessage) stateResponse; SensorState sensorState = sensorMessage.state; - if (sensorState != null && sensorState.windowopen != null && thing.getChannel(CHANNEL_WINDOWOPEN) == null) { - ThingBuilder thingBuilder = editThing(); - thingBuilder.withChannel(ChannelBuilder.create(new ChannelUID(thing.getUID(), CHANNEL_WINDOWOPEN), "String") - .withType(new ChannelTypeUID(BINDING_ID, "open")).build()); - updateThing(thingBuilder.build()); + if (sensorState != null && sensorState.windowopen != null) { + createChannel(CHANNEL_WINDOWOPEN, ChannelKind.STATE); } super.processStateResponse(stateResponse);