use of org.openhab.core.types.StateDescriptionFragment in project openhab-addons by openhab.
the class HueStateDescriptionProvider method setStateDescriptionFragment.
public void setStateDescriptionFragment(ChannelUID channelUID, StateDescriptionFragment stateDescriptionFragment) {
StateDescriptionFragment oldStateDescriptionFragment = stateDescriptionFragments.get(channelUID);
if (!stateDescriptionFragment.equals(oldStateDescriptionFragment)) {
stateDescriptionFragments.put(channelUID, stateDescriptionFragment);
postEvent(ThingEventFactory.createChannelDescriptionChangedEvent(channelUID, itemChannelLinkRegistry != null ? itemChannelLinkRegistry.getLinkedItemNames(channelUID) : Set.of(), stateDescriptionFragment, oldStateDescriptionFragment));
}
}
use of org.openhab.core.types.StateDescriptionFragment in project openhab-addons by openhab.
the class LightThingHandler method initialize.
@Override
public void initialize() {
if (thing.getThingTypeUID().equals(THING_TYPE_COLOR_TEMPERATURE_LIGHT) || thing.getThingTypeUID().equals(THING_TYPE_EXTENDED_COLOR_LIGHT)) {
try {
Map<String, String> properties = thing.getProperties();
String ctMaxString = properties.get(PROPERTY_CT_MAX);
ctMax = ctMaxString == null ? ZCL_CT_MAX : Integer.parseInt(ctMaxString);
String ctMinString = properties.get(PROPERTY_CT_MIN);
ctMin = ctMinString == null ? ZCL_CT_MIN : Integer.parseInt(ctMinString);
// minimum and maximum are inverted due to mired/kelvin conversion!
StateDescriptionFragment stateDescriptionFragment = StateDescriptionFragmentBuilder.create().withMinimum(new BigDecimal(miredToKelvin(ctMax))).withMaximum(new BigDecimal(miredToKelvin(ctMin))).build();
stateDescriptionProvider.setDescriptionFragment(new ChannelUID(thing.getUID(), CHANNEL_COLOR_TEMPERATURE), stateDescriptionFragment);
} catch (NumberFormatException e) {
needsPropertyUpdate = true;
}
}
ThingConfig thingConfig = getConfigAs(ThingConfig.class);
colorMode = thingConfig.colormode;
super.initialize();
}
use of org.openhab.core.types.StateDescriptionFragment in project openhab-addons by openhab.
the class DeconzDynamicStateDescriptionProvider method setDescriptionFragment.
/**
* Set a state description for a channel. This description will be used when preparing the channel state by
* the framework for presentation. A previous description, if existed, will be replaced.
*
* @param channelUID
* channel UID
* @param stateDescriptionFragment
* state description for the channel
*/
public void setDescriptionFragment(ChannelUID channelUID, StateDescriptionFragment stateDescriptionFragment) {
StateDescriptionFragment oldStateDescriptionFragment = stateDescriptionFragments.get(channelUID);
if (!stateDescriptionFragment.equals(oldStateDescriptionFragment)) {
logger.trace("adding state description for channel {}", channelUID);
stateDescriptionFragments.put(channelUID, stateDescriptionFragment);
ItemChannelLinkRegistry itemChannelLinkRegistry = this.itemChannelLinkRegistry;
postEvent(ThingEventFactory.createChannelDescriptionChangedEvent(channelUID, itemChannelLinkRegistry != null ? itemChannelLinkRegistry.getLinkedItemNames(channelUID) : Set.of(), stateDescriptionFragment, oldStateDescriptionFragment));
}
}
use of org.openhab.core.types.StateDescriptionFragment in project openhab-addons by openhab.
the class HaywardFilterHandler method setStateDescriptions.
@Override
public void setStateDescriptions() throws HaywardException {
List<StateOption> options = new ArrayList<>();
String option;
Bridge bridge = getBridge();
if (bridge != null) {
HaywardBridgeHandler bridgehandler = (HaywardBridgeHandler) bridge.getHandler();
if (bridgehandler != null) {
// Set Filter Speed % min and max speeds
Channel ch = thing.getChannel(HaywardBindingConstants.CHANNEL_FILTER_SPEEDPERCENT);
if (ch != null) {
StateDescriptionFragment stateDescriptionFragment = StateDescriptionFragmentBuilder.create().withMinimum(new BigDecimal(getThing().getProperties().get(HaywardBindingConstants.PROPERTY_FILTER_MINSPEED))).withMaximum(new BigDecimal(getThing().getProperties().get(HaywardBindingConstants.PROPERTY_FILTER_MAXSPEED))).build();
bridgehandler.updateChannelStateDescriptionFragment(ch, stateDescriptionFragment);
}
// Set Filter Speed RPM min and max speeds
ch = thing.getChannel(HaywardBindingConstants.CHANNEL_FILTER_SPEEDRPM);
if (ch != null) {
StateDescriptionFragment stateDescriptionFragment = StateDescriptionFragmentBuilder.create().withMinimum(new BigDecimal(getThing().getProperties().get(HaywardBindingConstants.PROPERTY_FILTER_MINRPM))).withMaximum(new BigDecimal(getThing().getProperties().get(HaywardBindingConstants.PROPERTY_FILTER_MAXRPM))).build();
bridgehandler.updateChannelStateDescriptionFragment(ch, stateDescriptionFragment);
}
// Set Filter Speed States
ch = thing.getChannel(HaywardBindingConstants.CHANNEL_FILTER_SPEEDSELECT);
if (ch != null) {
options.add(new StateOption("0", "Off"));
option = getThing().getProperties().get(HaywardBindingConstants.PROPERTY_FILTER_LOWSPEED);
if (option != null) {
options.add(new StateOption(option, "Low"));
}
option = getThing().getProperties().get(HaywardBindingConstants.PROPERTY_FILTER_MEDSPEED);
if (option != null) {
options.add(new StateOption(option, "Medium"));
}
option = getThing().getProperties().get(HaywardBindingConstants.PROPERTY_FILTER_HIGHSPEED);
if (option != null) {
options.add(new StateOption(option, "High"));
}
option = getThing().getProperties().get(HaywardBindingConstants.PROPERTY_FILTER_CUSTOMSPEED);
if (option != null) {
options.add(new StateOption(option, "Custom"));
}
StateDescriptionFragment stateDescriptionFragment = StateDescriptionFragmentBuilder.create().withOptions(options).build();
bridgehandler.updateChannelStateDescriptionFragment(ch, stateDescriptionFragment);
}
}
}
}
use of org.openhab.core.types.StateDescriptionFragment in project openhab-addons by openhab.
the class HaywardVirtualHeaterHandler method setStateDescriptions.
@Override
public void setStateDescriptions() throws HaywardException {
Bridge bridge = getBridge();
if (bridge != null) {
HaywardBridgeHandler bridgehandler = (HaywardBridgeHandler) bridge.getHandler();
if (bridgehandler != null) {
// Set heater min and max speeds
Channel ch = thing.getChannel(HaywardBindingConstants.CHANNEL_VIRTUALHEATER_CURRENTSETPOINT);
if (ch != null) {
StateDescriptionFragment stateDescriptionFragment = StateDescriptionFragmentBuilder.create().withMinimum(new BigDecimal(getThing().getProperties().get(HaywardBindingConstants.PROPERTY_VIRTUALHEATER_MINSETTABLEWATERTEMP))).withMaximum(new BigDecimal(getThing().getProperties().get(HaywardBindingConstants.PROPERTY_VIRTUALHEATER_MAXSETTABLEWATERTEMP))).build();
bridgehandler.updateChannelStateDescriptionFragment(ch, stateDescriptionFragment);
}
}
}
}
Aggregations