Search in sources :

Example 1 with StateDescriptionFragment

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));
    }
}
Also used : StateDescriptionFragment(org.openhab.core.types.StateDescriptionFragment)

Example 2 with StateDescriptionFragment

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();
}
Also used : ChannelUID(org.openhab.core.thing.ChannelUID) StateDescriptionFragment(org.openhab.core.types.StateDescriptionFragment) BigDecimal(java.math.BigDecimal)

Example 3 with StateDescriptionFragment

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));
    }
}
Also used : ItemChannelLinkRegistry(org.openhab.core.thing.link.ItemChannelLinkRegistry) StateDescriptionFragment(org.openhab.core.types.StateDescriptionFragment)

Example 4 with StateDescriptionFragment

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);
            }
        }
    }
}
Also used : Channel(org.openhab.core.thing.Channel) ArrayList(java.util.ArrayList) StateDescriptionFragment(org.openhab.core.types.StateDescriptionFragment) StateOption(org.openhab.core.types.StateOption) Bridge(org.openhab.core.thing.Bridge) BigDecimal(java.math.BigDecimal)

Example 5 with 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);
            }
        }
    }
}
Also used : Channel(org.openhab.core.thing.Channel) StateDescriptionFragment(org.openhab.core.types.StateDescriptionFragment) Bridge(org.openhab.core.thing.Bridge) BigDecimal(java.math.BigDecimal)

Aggregations

StateDescriptionFragment (org.openhab.core.types.StateDescriptionFragment)31 BigDecimal (java.math.BigDecimal)12 Test (org.junit.jupiter.api.Test)11 StateOption (org.openhab.core.types.StateOption)11 ChannelTypeUID (org.openhab.core.thing.type.ChannelTypeUID)8 StateDescription (org.openhab.core.types.StateDescription)8 ChannelUID (org.openhab.core.thing.ChannelUID)7 ArrayList (java.util.ArrayList)6 Channel (org.openhab.core.thing.Channel)5 Bridge (org.openhab.core.thing.Bridge)4 ItemChannelLinkRegistry (org.openhab.core.thing.link.ItemChannelLinkRegistry)4 Locale (java.util.Locale)3 Nullable (org.eclipse.jdt.annotation.Nullable)3 URI (java.net.URI)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 List (java.util.List)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 KM200ServiceObject (org.openhab.binding.km200.internal.KM200ServiceObject)2 Item (org.openhab.core.items.Item)2