Search in sources :

Example 1 with SetColorRequest

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

the class LifxLightStateChanger method handleColorsChange.

@Override
public void handleColorsChange(HSBK[] oldColors, HSBK[] newColors) {
    if (sameColors(newColors)) {
        SetColorRequest packet = new SetColorRequest(pendingLightState.getColors()[0], fadeTime.toMillis());
        removePacketsByType(SetColorZonesRequest.TYPE);
        replacePacketsInMap(packet);
    } else {
        List<SetColorZonesRequest> packets = new ArrayList<>();
        for (int i = 0; i < newColors.length; i++) {
            if (newColors[i] != null && !newColors[i].equals(oldColors[i])) {
                packets.add(new SetColorZonesRequest(i, newColors[i], fadeTime.toMillis(), ApplicationRequest.APPLY));
            }
        }
        if (!packets.isEmpty()) {
            removePacketsByType(SetColorRequest.TYPE);
            addPacketsToMap(packets.toArray(new SetColorZonesRequest[packets.size()]));
        }
    }
}
Also used : SetColorZonesRequest(org.eclipse.smarthome.binding.lifx.internal.protocol.SetColorZonesRequest) ArrayList(java.util.ArrayList) SetColorRequest(org.eclipse.smarthome.binding.lifx.internal.protocol.SetColorRequest)

Example 2 with SetColorRequest

use of org.eclipse.smarthome.binding.lifx.internal.protocol.SetColorRequest 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

SetColorRequest (org.eclipse.smarthome.binding.lifx.internal.protocol.SetColorRequest)2 SetColorZonesRequest (org.eclipse.smarthome.binding.lifx.internal.protocol.SetColorZonesRequest)2 ArrayList (java.util.ArrayList)1 AcknowledgementResponse (org.eclipse.smarthome.binding.lifx.internal.protocol.AcknowledgementResponse)1 GetLightInfraredRequest (org.eclipse.smarthome.binding.lifx.internal.protocol.GetLightInfraredRequest)1 GetLightPowerRequest (org.eclipse.smarthome.binding.lifx.internal.protocol.GetLightPowerRequest)1 GetRequest (org.eclipse.smarthome.binding.lifx.internal.protocol.GetRequest)1 Packet (org.eclipse.smarthome.binding.lifx.internal.protocol.Packet)1 SetLightInfraredRequest (org.eclipse.smarthome.binding.lifx.internal.protocol.SetLightInfraredRequest)1 SetPowerRequest (org.eclipse.smarthome.binding.lifx.internal.protocol.SetPowerRequest)1