[hue] recreate missing scene channel (#16038)

Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
This commit is contained in:
Andrew Fiddian-Green 2023-12-16 20:16:02 +00:00 committed by GitHub
parent 413ce0898c
commit d2e271d053
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View File

@ -87,6 +87,7 @@ public class HueBindingConstants {
public static final String CHANNEL_STATUS = "status";
public static final String CHANNEL_FLAG = "flag";
public static final String CHANNEL_SCENE = "scene";
public static final String CHANNEL_TYPE_2_SCENE = "scene-v2";
// List all triggers
public static final String EVENT_DIMMER_SWITCH = "dimmer_switch_event";

View File

@ -82,9 +82,11 @@ import org.openhab.core.thing.ThingUID;
import org.openhab.core.thing.binding.BaseThingHandler;
import org.openhab.core.thing.binding.BridgeHandler;
import org.openhab.core.thing.binding.ThingHandlerService;
import org.openhab.core.thing.binding.builder.ChannelBuilder;
import org.openhab.core.thing.binding.builder.ThingBuilder;
import org.openhab.core.thing.link.ItemChannelLink;
import org.openhab.core.thing.link.ItemChannelLinkRegistry;
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;
@ -1238,6 +1240,14 @@ public class Clip2ThingHandler extends BaseThingHandler {
State state = scenes.stream().filter(s -> s.getSceneActive().orElse(false)).map(s -> s.getSceneState())
.findAny().orElse(UnDefType.UNDEF);
// create scene channel if it is missing
if (getThing().getChannel(CHANNEL_2_SCENE) == null) {
updateThing(editThing()
.withChannel(ChannelBuilder.create(new ChannelUID(getThing().getUID(), CHANNEL_2_SCENE))
.withType(new ChannelTypeUID(BINDING_ID, CHANNEL_TYPE_2_SCENE)).build())
.build());
}
updateState(CHANNEL_2_SCENE, state, true);
stateDescriptionProvider.setStateOptions(new ChannelUID(thing.getUID(), CHANNEL_2_SCENE), scenes