<commit_before>/**
 * Copyright (c) 2014-2016 by the respective copyright holders.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */
package org.openhab.binding.milight.handler;

import org.eclipse.smarthome.core.library.types.DecimalType;
import org.eclipse.smarthome.core.library.types.HSBType;
import org.eclipse.smarthome.core.library.types.OnOffType;
import org.eclipse.smarthome.core.library.types.StringType;
import org.eclipse.smarthome.core.thing.Bridge;
import org.eclipse.smarthome.core.thing.ChannelUID;
import org.eclipse.smarthome.core.thing.Thing;
import org.eclipse.smarthome.core.thing.ThingStatusInfo;
import org.eclipse.smarthome.core.thing.binding.BaseThingHandler;
import org.eclipse.smarthome.core.thing.binding.ThingHandler;
import org.eclipse.smarthome.core.types.Command;
import org.openhab.binding.milight.MilightBindingConstants;
import org.openhab.binding.milight.internal.MilightThingState;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * The {@link MilightLedHandler} is responsible for handling commands, which are
 * sent to one of the channels.
 *
 * @author <NAME> - Initial contribution
 */
public class MilightLedHandler extends BaseThingHandler {

    private Logger logger = LoggerFactory.getLogger(MilightLedHandler.class);
    private MilightThingState state;
    private int bulbid;

    public MilightLedHandler(Thing thing) {
        super(thing);
    }

    @Override
    public void handleCommand(ChannelUID channelUID, Command command) {
        if (state == null) {
            logger.debug("Not initalized");
            return;
        }

        switch (channelUID.getId()) {
            case MilightBindingConstants.CHANNEL_COLOR: {
                if (command instanceof HSBType) {
                    HSBType hsb = (HSBType) command;
                    if (hsb.getSaturation().intValue() < 50) {
                        state.setWhiteMode();
                    } else {
                        state.setColor(hsb.getHue().intValue());
                    }
                    state.setBrightness(hsb.getBrightness().intValue());
                } else if (command instanceof OnOffType) {
                    OnOffType hsb = (OnOffType) command;
                    if (hsb == OnOffType.OFF) {
                        state.setOff();
                    } else {
                        state.setOn();
                    }
                }
                break;
            }
            case MilightBindingConstants.CHANNEL_NIGHTMODE: {
                state.setNightMode();
                break;
            }
            case MilightBindingConstants.CHANNEL_BRIGHTNESS: {
                DecimalType d = (DecimalType) command;
                state.setBrightness(d.intValue());
                break;
            }<commit_msg>Added missing command handling in MilightLedHandler (#1322) (#1326)<commit_after>/**
 * Copyright (c) 2014-2016 by the respective copyright holders.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */
package org.openhab.binding.milight.handler;

import org.eclipse.smarthome.core.library.types.DecimalType;
import org.eclipse.smarthome.core.library.types.HSBType;
import org.eclipse.smarthome.core.library.types.OnOffType;
import org.eclipse.smarthome.core.library.types.PercentType;
import org.eclipse.smarthome.core.library.types.StringType;
import org.eclipse.smarthome.core.thing.Bridge;
import org.eclipse.smarthome.core.thing.ChannelUID;
import org.eclipse.smarthome.core.thing.Thing;
import org.eclipse.smarthome.core.thing.ThingStatusInfo;
import org.eclipse.smarthome.core.thing.binding.BaseThingHandler;
import org.eclipse.smarthome.core.thing.binding.ThingHandler;
import org.eclipse.smarthome.core.types.Command;
import org.openhab.binding.milight.MilightBindingConstants;
import org.openhab.binding.milight.internal.MilightThingState;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * The {@link MilightLedHandler} is responsible for handling commands, which are
 * sent to one of the channels.
 *
 * @author <NAME> - Initial contribution
 */
public class MilightLedHandler extends BaseThingHandler {

    private Logger logger = LoggerFactory.getLogger(MilightLedHandler.class);
    private MilightThingState state;
    private int bulbid;

    public MilightLedHandler(Thing thing) {
        super(thing);
    }

    @Override
    public void handleCommand(ChannelUID channelUID, Command command) {
        if (state == null) {
            logger.debug("Not initalized");
            return;
        }

        switch (channelUID.getId()) {
            case MilightBindingConstants.CHANNEL_COLOR: {
                if (command instanceof HSBType) {
                    HSBType hsb = (HSBType) command;
                    if (hsb.getSaturation().intValue() < 50) {
                        state.setWhiteMode();
                    } else {
                        state.setColor(hsb.getHue().intValue());
                    }
                    state.setBrightness(hsb.getBrightness().intValue());
                } else if (command instanceof OnOffType) {
                    OnOffType hsb = (OnOffType) command;
                    if (hsb == OnOffType.OFF) {
                        state.setOff();
                    } else {
                        state.setOn();
                    }
                } else if (command instanceof PercentType) {
                    PercentType p = (PercentType) command;
                    state.setBrightness(p.intValue());
                }
                break;
            }
            case MilightBindingConstants.CHANNEL_NIGHTMODE: {
                state.setNightMode();
                break;
            }
            case MilightBindingConstants.CHANNEL_BRIGHTNESS: {
                if (command instanceof OnOffType) {
                    OnOffType s = (OnOffType) command;
                    if (s == OnOffType.OFF) {
                        state.setOff();
                    } else {
                        state.setOn();
                    }
                } else if (command instanceof PercentType) {
                    PercentType p = (PercentType) command;
                    state.setBrightness(p.intValue());
                }

                break;
            }
{'fraction_non_alphanumeric': 0.09300584094653287, 'fraction_numerical': 0.0059907143926913285, 'mean_word_length': 2.0945319740500463, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3409304', 'n_tokens_mistral': 1866, 'n_tokens_neox': 1757, 'n_words': 378}