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()]));
}
}
}
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());
}
}
}
Aggregations