change states of a channel [message #1778076] |
Sat, 09 December 2017 03:53  |
Eclipse User |
|
|
|
hi,
I want to change state values of a channels (e.g. like in YamahaZoneThingHandler.java from yamahareceiver binding).
That's my channel and channel-type:
...
<channel id="movepreset" typeId="movepreset-channel" />
...
<channel-type id="movepreset-channel">
<item-type>String</item-type>
<label>Move to preset</label>
<description>Moving to preset</description>
<state pattern="%s">
<options>
<option value="HOME">home</option>
</options>
</state>
</channel-type>
....
That's my code to cahnge the states:
protected void thingStructureChanged() {
final ChannelTypeUID channelTypePresetUID = new ChannelTypeUID(
MyBindingConstants.BINDING_ID, "movepreset-channel");
ChannelType templateType = TypeResolver.resolve(channelTypePresetUID);
List<StateOption> options = new ArrayList<>();
options.add(new StateOption("TEST1", "Test 1"));
options.add(new StateOption("TEST2", "Test 2"));
StateDescription state = new StateDescription(null, null, null, "%s", false, options);
ChannelUID movepresetChannelUID = new ChannelUID(thing.getUID(), "movepreset");
ChannelTypeUID channelTypeUID = new ChannelTypeUID(movepresetChannelUID.getAsString());
ChannelType channelType = new ChannelType(channelTypeUID, false, "String", templateType.getKind(),
templateType.getLabel(), templateType.getDescription(), templateType.getCategory(),
templateType.getTags(), state, templateType.getEvent(), templateType.getConfigDescriptionURI());
Channel channel = ChannelBuilder.create(movepresetChannelUID, "String").withType(channelTypeUID).build();
// Remove the old channel and add the new channel
updateThing(editThing().withoutChannel(movepresetChannelUID).withChannel(channel).build());
}
The original channel seems to be removed and a new empty channel was added.
In PaperUI it looks like that:

when I click on it:

I don't understand it! Can anyone explain to me what I'm doing wrong?
Attachment: paperui1.jpg
(Size: 3.89KB, Downloaded 562 times)
Attachment: paperui2.jpg
(Size: 4.48KB, Downloaded 561 times)
[Updated on: Sat, 09 December 2017 03:54] by Moderator
|
|
|
|
|
|
|
|
|
|
|
Re: change states of a channel [message #1791663 is a reply to message #1791650] |
Tue, 03 July 2018 09:45  |
Eclipse User |
|
|
|
Hello Nils,
glad you found a solution. I was actually on the wrong track with configurations...
Are you planning to create a PR to ESh or openhab2-addons with your new binding? Would be cool to see it as a contribution!
Regards,
Stefan
|
|
|
Powered by
FUDForum. Page generated in 0.04936 seconds