Search in sources :

Example 1 with GroupAction

use of org.openhab.binding.deconz.internal.dto.GroupAction in project openhab-addons by openhab.

the class GroupThingHandler method handleCommand.

@Override
public void handleCommand(ChannelUID channelUID, Command command) {
    String channelId = channelUID.getId();
    GroupAction newGroupAction = new GroupAction();
    switch(channelId) {
        case CHANNEL_ALL_ON:
        case CHANNEL_ANY_ON:
            if (command instanceof RefreshType) {
                valueUpdated(channelUID.getId(), groupStateCache);
                return;
            }
            break;
        case CHANNEL_ALERT:
            if (command instanceof StringType) {
                newGroupAction.alert = command.toString();
            } else {
                return;
            }
            break;
        case CHANNEL_COLOR:
            if (command instanceof HSBType) {
                HSBType hsbCommand = (HSBType) command;
                // is in CT mode or iii) already in XY mode. Only if the bulb is in HS mode, use this one.
                if ("hs".equals(colorMode)) {
                    newGroupAction.hue = (int) (hsbCommand.getHue().doubleValue() * HUE_FACTOR);
                    newGroupAction.sat = Util.fromPercentType(hsbCommand.getSaturation());
                } else {
                    PercentType[] xy = hsbCommand.toXY();
                    if (xy.length < 2) {
                        logger.warn("Failed to convert {} to xy-values", command);
                    }
                    newGroupAction.xy = new double[] { xy[0].doubleValue() / 100.0, xy[1].doubleValue() / 100.0 };
                }
            } else if (command instanceof PercentType) {
                newGroupAction.bri = Util.fromPercentType((PercentType) command);
            } else if (command instanceof DecimalType) {
                newGroupAction.bri = ((DecimalType) command).intValue();
            } else if (command instanceof OnOffType) {
                newGroupAction.on = OnOffType.ON.equals(command);
            } else {
                return;
            }
            break;
        case CHANNEL_COLOR_TEMPERATURE:
            if (command instanceof DecimalType) {
                int miredValue = Util.kelvinToMired(((DecimalType) command).intValue());
                newGroupAction.ct = Util.constrainToRange(miredValue, ZCL_CT_MIN, ZCL_CT_MAX);
            } else {
                return;
            }
            break;
        case CHANNEL_SCENE:
            if (command instanceof StringType) {
                String sceneId = scenes.get(command.toString());
                if (sceneId != null) {
                    sendCommand(null, command, channelUID, "scenes/" + sceneId + "/recall", null);
                } else {
                    logger.debug("Ignoring command {} for {}, scene is not found in available scenes: {}", command, channelUID, scenes);
                }
            }
            return;
        default:
            return;
    }
    Integer bri = newGroupAction.bri;
    if (bri != null) {
        newGroupAction.on = (bri > 0);
    }
    sendCommand(newGroupAction, command, channelUID, null);
}
Also used : GroupAction(org.openhab.binding.deconz.internal.dto.GroupAction) StringType(org.openhab.core.library.types.StringType) OnOffType(org.openhab.core.library.types.OnOffType) DecimalType(org.openhab.core.library.types.DecimalType) PercentType(org.openhab.core.library.types.PercentType) RefreshType(org.openhab.core.types.RefreshType) HSBType(org.openhab.core.library.types.HSBType)

Example 2 with GroupAction

use of org.openhab.binding.deconz.internal.dto.GroupAction in project openhab-addons by openhab.

the class GroupThingHandler method messageReceived.

@Override
public void messageReceived(String sensorID, DeconzBaseMessage message) {
    if (message instanceof GroupMessage) {
        GroupMessage groupMessage = (GroupMessage) message;
        logger.trace("{} received {}", thing.getUID(), groupMessage);
        GroupState groupState = groupMessage.state;
        if (groupState != null) {
            updateStatus(ThingStatus.ONLINE);
            thing.getChannels().stream().map(c -> c.getUID().getId()).forEach(c -> valueUpdated(c, groupState));
            groupStateCache = groupState;
        }
        GroupAction groupAction = groupMessage.action;
        if (groupAction != null) {
            if (colorMode.isEmpty()) {
                String cmode = groupAction.colormode;
                if (cmode != null && ("hs".equals(cmode) || "xy".equals(cmode))) {
                    // only set the color mode if it is hs or xy, not ct
                    colorMode = cmode;
                }
            }
        }
    }
}
Also used : DeconzDynamicCommandDescriptionProvider(org.openhab.binding.deconz.internal.DeconzDynamicCommandDescriptionProvider) BindingConstants(org.openhab.binding.deconz.internal.BindingConstants) StringType(org.openhab.core.library.types.StringType) LoggerFactory(org.slf4j.LoggerFactory) OnOffType(org.openhab.core.library.types.OnOffType) GroupMessage(org.openhab.binding.deconz.internal.dto.GroupMessage) Scene(org.openhab.binding.deconz.internal.dto.Scene) Thing(org.openhab.core.thing.Thing) Gson(com.google.gson.Gson) Map(java.util.Map) GroupState(org.openhab.binding.deconz.internal.dto.GroupState) ChannelUID(org.openhab.core.thing.ChannelUID) ThingTypeUID(org.openhab.core.thing.ThingTypeUID) DecimalType(org.openhab.core.library.types.DecimalType) NonNullByDefault(org.eclipse.jdt.annotation.NonNullByDefault) ThingStatus(org.openhab.core.thing.ThingStatus) Command(org.openhab.core.types.Command) Logger(org.slf4j.Logger) ResourceType(org.openhab.binding.deconz.internal.types.ResourceType) Util(org.openhab.binding.deconz.internal.Util) RefreshType(org.openhab.core.types.RefreshType) Set(java.util.Set) DeconzBaseMessage(org.openhab.binding.deconz.internal.dto.DeconzBaseMessage) Collectors(java.util.stream.Collectors) PercentType(org.openhab.core.library.types.PercentType) GroupAction(org.openhab.binding.deconz.internal.dto.GroupAction) HSBType(org.openhab.core.library.types.HSBType) GroupAction(org.openhab.binding.deconz.internal.dto.GroupAction) GroupMessage(org.openhab.binding.deconz.internal.dto.GroupMessage) GroupState(org.openhab.binding.deconz.internal.dto.GroupState)

Aggregations

GroupAction (org.openhab.binding.deconz.internal.dto.GroupAction)2 DecimalType (org.openhab.core.library.types.DecimalType)2 HSBType (org.openhab.core.library.types.HSBType)2 OnOffType (org.openhab.core.library.types.OnOffType)2 PercentType (org.openhab.core.library.types.PercentType)2 StringType (org.openhab.core.library.types.StringType)2 RefreshType (org.openhab.core.types.RefreshType)2 Gson (com.google.gson.Gson)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 NonNullByDefault (org.eclipse.jdt.annotation.NonNullByDefault)1 BindingConstants (org.openhab.binding.deconz.internal.BindingConstants)1 DeconzDynamicCommandDescriptionProvider (org.openhab.binding.deconz.internal.DeconzDynamicCommandDescriptionProvider)1 Util (org.openhab.binding.deconz.internal.Util)1 DeconzBaseMessage (org.openhab.binding.deconz.internal.dto.DeconzBaseMessage)1 GroupMessage (org.openhab.binding.deconz.internal.dto.GroupMessage)1 GroupState (org.openhab.binding.deconz.internal.dto.GroupState)1 Scene (org.openhab.binding.deconz.internal.dto.Scene)1 ResourceType (org.openhab.binding.deconz.internal.types.ResourceType)1