Search in sources :

Example 1 with FullLight

use of org.eclipse.smarthome.binding.hue.internal.FullLight in project smarthome by eclipse.

the class HueLightHandler method initializeProperties.

private synchronized void initializeProperties() {
    if (!propertiesInitializedSuccessfully) {
        FullLight fullLight = getLight();
        if (fullLight != null) {
            String modelId = fullLight.getModelID().replaceAll(NORMALIZE_ID_REGEX, "_");
            updateProperty(Thing.PROPERTY_MODEL_ID, modelId);
            updateProperty(Thing.PROPERTY_FIRMWARE_VERSION, fullLight.getSoftwareVersion());
            String vendor = getVendor(modelId);
            if (vendor != null) {
                updateProperty(Thing.PROPERTY_VENDOR, vendor);
            }
            updateProperty(LIGHT_UNIQUE_ID, fullLight.getUniqueID());
            isOsramPar16 = OSRAM_PAR16_50_TW_MODEL_ID.equals(modelId);
            propertiesInitializedSuccessfully = true;
        }
    }
}
Also used : FullLight(org.eclipse.smarthome.binding.hue.internal.FullLight)

Example 2 with FullLight

use of org.eclipse.smarthome.binding.hue.internal.FullLight in project smarthome by eclipse.

the class HueLightHandler method handleCommand.

@Override
public void handleCommand(ChannelUID channelUID, Command command) {
    HueBridgeHandler hueBridge = getHueBridgeHandler();
    if (hueBridge == null) {
        logger.warn("hue bridge handler not found. Cannot handle command without bridge.");
        return;
    }
    FullLight light = getLight();
    if (light == null) {
        logger.debug("hue light not known on bridge. Cannot handle command.");
        return;
    }
    StateUpdate lightState = null;
    switch(channelUID.getId()) {
        case CHANNEL_COLORTEMPERATURE:
            if (command instanceof PercentType) {
                lightState = LightStateConverter.toColorTemperatureLightState((PercentType) command);
            } else if (command instanceof OnOffType) {
                lightState = LightStateConverter.toOnOffLightState((OnOffType) command);
                if (isOsramPar16) {
                    lightState = addOsramSpecificCommands(lightState, (OnOffType) command);
                }
            } else if (command instanceof IncreaseDecreaseType) {
                lightState = convertColorTempChangeToStateUpdate((IncreaseDecreaseType) command, light);
            }
            break;
        case CHANNEL_BRIGHTNESS:
            if (command instanceof PercentType) {
                lightState = LightStateConverter.toBrightnessLightState((PercentType) command);
            } else if (command instanceof OnOffType) {
                lightState = LightStateConverter.toOnOffLightState((OnOffType) command);
                if (isOsramPar16) {
                    lightState = addOsramSpecificCommands(lightState, (OnOffType) command);
                }
            } else if (command instanceof IncreaseDecreaseType) {
                lightState = convertBrightnessChangeToStateUpdate((IncreaseDecreaseType) command, light);
            }
            break;
        case CHANNEL_SWITCH:
            logger.trace("CHANNEL_SWITCH handling command {}", command);
            if (command instanceof OnOffType) {
                lightState = LightStateConverter.toOnOffLightState((OnOffType) command);
                if (isOsramPar16) {
                    lightState = addOsramSpecificCommands(lightState, (OnOffType) command);
                }
            }
            break;
        case CHANNEL_COLOR:
            if (command instanceof HSBType) {
                HSBType hsbCommand = (HSBType) command;
                if (hsbCommand.getBrightness().intValue() == 0) {
                    lightState = LightStateConverter.toOnOffLightState(OnOffType.OFF);
                } else {
                    lightState = LightStateConverter.toColorLightState(hsbCommand);
                }
            } else if (command instanceof PercentType) {
                lightState = LightStateConverter.toBrightnessLightState((PercentType) command);
            } else if (command instanceof OnOffType) {
                lightState = LightStateConverter.toOnOffLightState((OnOffType) command);
            } else if (command instanceof IncreaseDecreaseType) {
                lightState = convertBrightnessChangeToStateUpdate((IncreaseDecreaseType) command, light);
            }
            break;
        case CHANNEL_ALERT:
            if (command instanceof StringType) {
                lightState = LightStateConverter.toAlertState((StringType) command);
                if (lightState == null) {
                    // Unsupported StringType is passed. Log a warning
                    // message and return.
                    logger.warn("Unsupported String command: {}. Supported commands are: {}, {}, {} ", command, LightStateConverter.ALERT_MODE_NONE, LightStateConverter.ALERT_MODE_SELECT, LightStateConverter.ALERT_MODE_LONG_SELECT);
                    return;
                } else {
                    scheduleAlertStateRestore(command);
                }
            }
            break;
        case CHANNEL_EFFECT:
            if (command instanceof OnOffType) {
                lightState = LightStateConverter.toOnOffEffectState((OnOffType) command);
            }
            break;
    }
    if (lightState != null) {
        hueBridge.updateLightState(light, lightState);
    } else {
        logger.warn("Command sent to an unknown channel id: {}", channelUID);
    }
}
Also used : StateUpdate(org.eclipse.smarthome.binding.hue.internal.StateUpdate) OnOffType(org.eclipse.smarthome.core.library.types.OnOffType) StringType(org.eclipse.smarthome.core.library.types.StringType) IncreaseDecreaseType(org.eclipse.smarthome.core.library.types.IncreaseDecreaseType) FullLight(org.eclipse.smarthome.binding.hue.internal.FullLight) PercentType(org.eclipse.smarthome.core.library.types.PercentType) HSBType(org.eclipse.smarthome.core.library.types.HSBType)

Example 3 with FullLight

use of org.eclipse.smarthome.binding.hue.internal.FullLight in project smarthome by eclipse.

the class HueLightDiscoveryService method startScan.

@Override
public void startScan() {
    List<FullLight> lights = hueBridgeHandler.getFullLights();
    for (FullLight l : lights) {
        onLightAddedInternal(l);
    }
    // search for unpaired lights
    hueBridgeHandler.startSearch();
}
Also used : FullLight(org.eclipse.smarthome.binding.hue.internal.FullLight)

Aggregations

FullLight (org.eclipse.smarthome.binding.hue.internal.FullLight)3 StateUpdate (org.eclipse.smarthome.binding.hue.internal.StateUpdate)1 HSBType (org.eclipse.smarthome.core.library.types.HSBType)1 IncreaseDecreaseType (org.eclipse.smarthome.core.library.types.IncreaseDecreaseType)1 OnOffType (org.eclipse.smarthome.core.library.types.OnOffType)1 PercentType (org.eclipse.smarthome.core.library.types.PercentType)1 StringType (org.eclipse.smarthome.core.library.types.StringType)1