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
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";
*/
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;
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;
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());
+ }
+ }
}
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;
}
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<String> options = List.of("none", "steady", "snow", "rainbow", "snake", "tinkle", "fireworks",
"flag", "waves", "updown", "vintage", "fading", "collide", "strobe", "sparkles", "carnival",
"glow");
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;
}
}
- 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
*
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;
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);