Search in sources :

Example 1 with GetLightInfraredRequest

use of org.eclipse.smarthome.binding.lifx.internal.protocol.GetLightInfraredRequest in project smarthome by eclipse.

the class LifxLightHandler method handleCommand.

@Override
public void handleCommand(ChannelUID channelUID, Command command) {
    if (command instanceof RefreshType) {
        switch(channelUID.getId()) {
            case CHANNEL_COLOR:
            case CHANNEL_BRIGHTNESS:
                sendPacket(new GetLightPowerRequest());
                sendPacket(new GetRequest());
                break;
            case CHANNEL_TEMPERATURE:
                sendPacket(new GetRequest());
                break;
            case CHANNEL_INFRARED:
                sendPacket(new GetLightInfraredRequest());
                break;
            case CHANNEL_SIGNAL_STRENGTH:
                sendPacket(new GetWifiInfoRequest());
                break;
            default:
                break;
        }
    } else {
        boolean supportedCommand = true;
        switch(channelUID.getId()) {
            case CHANNEL_COLOR:
                if (command instanceof HSBType) {
                    handleHSBCommand((HSBType) command);
                } else if (command instanceof PercentType) {
                    handlePercentCommand((PercentType) command);
                } else if (command instanceof OnOffType) {
                    handleOnOffCommand((OnOffType) command);
                } else if (command instanceof IncreaseDecreaseType) {
                    handleIncreaseDecreaseCommand((IncreaseDecreaseType) command);
                } else {
                    supportedCommand = false;
                }
                break;
            case CHANNEL_BRIGHTNESS:
                if (command instanceof PercentType) {
                    handlePercentCommand((PercentType) command);
                } else if (command instanceof OnOffType) {
                    handleOnOffCommand((OnOffType) command);
                } else if (command instanceof IncreaseDecreaseType) {
                    handleIncreaseDecreaseCommand((IncreaseDecreaseType) command);
                } else {
                    supportedCommand = false;
                }
                break;
            case CHANNEL_TEMPERATURE:
                if (command instanceof PercentType) {
                    handleTemperatureCommand((PercentType) command);
                } else if (command instanceof IncreaseDecreaseType) {
                    handleIncreaseDecreaseTemperatureCommand((IncreaseDecreaseType) command);
                } else {
                    supportedCommand = false;
                }
                break;
            case CHANNEL_INFRARED:
                if (command instanceof PercentType) {
                    handleInfraredCommand((PercentType) command);
                } else if (command instanceof IncreaseDecreaseType) {
                    handleIncreaseDecreaseInfraredCommand((IncreaseDecreaseType) command);
                } else {
                    supportedCommand = false;
                }
                break;
            default:
                try {
                    if (channelUID.getId().startsWith(CHANNEL_COLOR_ZONE)) {
                        int zoneIndex = Integer.parseInt(channelUID.getId().replace(CHANNEL_COLOR_ZONE, ""));
                        if (command instanceof HSBType) {
                            handleHSBCommand((HSBType) command, zoneIndex);
                        } else if (command instanceof PercentType) {
                            handlePercentCommand((PercentType) command, zoneIndex);
                        } else if (command instanceof IncreaseDecreaseType) {
                            handleIncreaseDecreaseCommand((IncreaseDecreaseType) command, zoneIndex);
                        } else {
                            supportedCommand = false;
                        }
                    } else if (channelUID.getId().startsWith(CHANNEL_TEMPERATURE_ZONE)) {
                        int zoneIndex = Integer.parseInt(channelUID.getId().replace(CHANNEL_TEMPERATURE_ZONE, ""));
                        if (command instanceof PercentType) {
                            handleTemperatureCommand((PercentType) command, zoneIndex);
                        } else if (command instanceof IncreaseDecreaseType) {
                            handleIncreaseDecreaseTemperatureCommand((IncreaseDecreaseType) command, zoneIndex);
                        } else {
                            supportedCommand = false;
                        }
                    } else {
                        supportedCommand = false;
                    }
                } catch (NumberFormatException e) {
                    logger.error("Failed to parse zone index for a command of a light ({}) : {}", logId, e.getMessage());
                    supportedCommand = false;
                }
                break;
        }
        if (supportedCommand && !(command instanceof OnOffType) && !CHANNEL_INFRARED.equals(channelUID.getId())) {
            getLightStateForCommand().setPowerState(PowerState.ON);
        }
    }
}
Also used : OnOffType(org.eclipse.smarthome.core.library.types.OnOffType) GetWifiInfoRequest(org.eclipse.smarthome.binding.lifx.internal.protocol.GetWifiInfoRequest) GetRequest(org.eclipse.smarthome.binding.lifx.internal.protocol.GetRequest) GetLightInfraredRequest(org.eclipse.smarthome.binding.lifx.internal.protocol.GetLightInfraredRequest) IncreaseDecreaseType(org.eclipse.smarthome.core.library.types.IncreaseDecreaseType) PercentType(org.eclipse.smarthome.core.library.types.PercentType) LifxMessageUtil.increaseDecreasePercentType(org.eclipse.smarthome.binding.lifx.internal.util.LifxMessageUtil.increaseDecreasePercentType) RefreshType(org.eclipse.smarthome.core.types.RefreshType) GetLightPowerRequest(org.eclipse.smarthome.binding.lifx.internal.protocol.GetLightPowerRequest) HSBType(org.eclipse.smarthome.core.library.types.HSBType)

Example 2 with GetLightInfraredRequest

use of org.eclipse.smarthome.binding.lifx.internal.protocol.GetLightInfraredRequest in project smarthome by eclipse.

the class LifxLightStateChanger method handleResponsePacket.

public void handleResponsePacket(Packet packet) {
    if (packet instanceof AcknowledgementResponse) {
        long ackTimestamp = System.currentTimeMillis();
        PendingPacket pendingPacket;
        try {
            lock.lock();
            pendingPacket = removeAcknowledgedPacket(packet.getSequence());
        } finally {
            lock.unlock();
        }
        if (pendingPacket != null) {
            Packet sentPacket = pendingPacket.packet;
            logger.debug("{} : {} packet was acknowledged in {}ms", logId, sentPacket.getClass().getSimpleName(), ackTimestamp - pendingPacket.lastSend);
            // LifxLightCurrentStateUpdater
            if (sentPacket instanceof SetPowerRequest) {
                GetLightPowerRequest powerPacket = new GetLightPowerRequest();
                communicationHandler.sendPacket(powerPacket);
            } else if (sentPacket instanceof SetColorRequest) {
                GetRequest colorPacket = new GetRequest();
                communicationHandler.sendPacket(colorPacket);
                getZonesIfZonesAreSet();
            } else if (sentPacket instanceof SetColorZonesRequest) {
                getZonesIfZonesAreSet();
            } else if (sentPacket instanceof SetLightInfraredRequest) {
                GetLightInfraredRequest infraredPacket = new GetLightInfraredRequest();
                communicationHandler.sendPacket(infraredPacket);
            }
        } else {
            logger.debug("{} : No pending packet found for ack with sequence number: {}", logId, packet.getSequence());
        }
    }
}
Also used : Packet(org.eclipse.smarthome.binding.lifx.internal.protocol.Packet) SetLightInfraredRequest(org.eclipse.smarthome.binding.lifx.internal.protocol.SetLightInfraredRequest) GetRequest(org.eclipse.smarthome.binding.lifx.internal.protocol.GetRequest) SetColorZonesRequest(org.eclipse.smarthome.binding.lifx.internal.protocol.SetColorZonesRequest) AcknowledgementResponse(org.eclipse.smarthome.binding.lifx.internal.protocol.AcknowledgementResponse) GetLightInfraredRequest(org.eclipse.smarthome.binding.lifx.internal.protocol.GetLightInfraredRequest) GetLightPowerRequest(org.eclipse.smarthome.binding.lifx.internal.protocol.GetLightPowerRequest) SetPowerRequest(org.eclipse.smarthome.binding.lifx.internal.protocol.SetPowerRequest) SetColorRequest(org.eclipse.smarthome.binding.lifx.internal.protocol.SetColorRequest)

Aggregations

GetLightInfraredRequest (org.eclipse.smarthome.binding.lifx.internal.protocol.GetLightInfraredRequest)2 GetLightPowerRequest (org.eclipse.smarthome.binding.lifx.internal.protocol.GetLightPowerRequest)2 GetRequest (org.eclipse.smarthome.binding.lifx.internal.protocol.GetRequest)2 AcknowledgementResponse (org.eclipse.smarthome.binding.lifx.internal.protocol.AcknowledgementResponse)1 GetWifiInfoRequest (org.eclipse.smarthome.binding.lifx.internal.protocol.GetWifiInfoRequest)1 Packet (org.eclipse.smarthome.binding.lifx.internal.protocol.Packet)1 SetColorRequest (org.eclipse.smarthome.binding.lifx.internal.protocol.SetColorRequest)1 SetColorZonesRequest (org.eclipse.smarthome.binding.lifx.internal.protocol.SetColorZonesRequest)1 SetLightInfraredRequest (org.eclipse.smarthome.binding.lifx.internal.protocol.SetLightInfraredRequest)1 SetPowerRequest (org.eclipse.smarthome.binding.lifx.internal.protocol.SetPowerRequest)1 LifxMessageUtil.increaseDecreasePercentType (org.eclipse.smarthome.binding.lifx.internal.util.LifxMessageUtil.increaseDecreasePercentType)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 RefreshType (org.eclipse.smarthome.core.types.RefreshType)1