]> git.basschouten.com Git - openhab-addons.git/commitdiff
[lifx] Fix all SAT findings (#10307)
authorWouter Born <github@maindrain.net>
Wed, 10 Mar 2021 08:52:39 +0000 (09:52 +0100)
committerGitHub <noreply@github.com>
Wed, 10 Mar 2021 08:52:39 +0000 (09:52 +0100)
* Remove dependency on commons-lang classes
* Use HexUtils
* Fix/add missing initial contribution author lines
* Add unit test for MACAddress
* Rename protocol package to dto

Signed-off-by: Wouter Born <github@maindrain.net>
155 files changed:
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/LifxChannelFactory.java
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/LifxChannelFactoryImpl.java
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/LifxLightCommunicationHandler.java
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/LifxLightConfig.java
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/LifxLightContext.java
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/LifxLightCurrentStateUpdater.java
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/LifxLightDiscovery.java
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/LifxLightOnlineStateUpdater.java
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/LifxLightPropertiesUpdater.java
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/LifxLightState.java
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/LifxLightStateChanger.java
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/LifxProduct.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/LifxSelectorContext.java
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/LifxSequenceNumberSupplier.java
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/AcknowledgementResponse.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/ApplicationRequest.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/EchoRequestResponse.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/Effect.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GenericHandler.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GenericPacket.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetColorZonesRequest.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetEchoRequest.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetGroupRequest.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetHostFirmwareRequest.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetHostInfoRequest.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetInfoRequest.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetLabelRequest.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetLightInfraredRequest.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetLightPowerRequest.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetLocationRequest.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetPowerRequest.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetRequest.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetServiceRequest.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetTagLabelsRequest.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetTagsRequest.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetTileEffectRequest.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetVersionRequest.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetWifiFirmwareRequest.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetWifiInfoRequest.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/Packet.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/PacketFactory.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/PacketHandler.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/PowerState.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/SetColorRequest.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/SetColorZonesRequest.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/SetDimAbsoluteRequest.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/SetLabelRequest.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/SetLightInfraredRequest.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/SetLightPowerRequest.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/SetPowerRequest.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/SetTagsRequest.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/SetTileEffectRequest.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/SignalStrength.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/StateGroupResponse.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/StateHostFirmwareResponse.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/StateHostInfoResponse.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/StateInfoResponse.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/StateLabelResponse.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/StateLightInfraredResponse.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/StateLightPowerResponse.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/StateLocationResponse.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/StateMultiZoneResponse.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/StatePowerResponse.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/StateResponse.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/StateServiceResponse.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/StateTileEffectResponse.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/StateVersionResponse.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/StateWifiFirmwareResponse.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/StateWifiInfoResponse.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/StateZoneResponse.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/TagLabelsResponse.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/TagsResponse.java [new file with mode: 0644]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/fields/ByteField.java
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/fields/Field.java
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/fields/FloatField.java
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/fields/HSBK.java
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/fields/HSBKField.java
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/fields/LittleField.java
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/fields/MACAddress.java
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/fields/MACAddressField.java
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/fields/StringField.java
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/fields/UInt16Field.java
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/fields/UInt32Field.java
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/fields/UInt64Field.java
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/fields/UInt8Field.java
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/fields/Version.java
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/fields/VersionField.java
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/handler/LifxLightHandler.java
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/listener/LifxLightStateListener.java
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/listener/LifxPropertiesUpdateListener.java
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/listener/LifxResponsePacketListener.java
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/AcknowledgementResponse.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/ApplicationRequest.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/EchoRequestResponse.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/Effect.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GenericHandler.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GenericPacket.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetColorZonesRequest.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetEchoRequest.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetGroupRequest.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetHostFirmwareRequest.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetHostInfoRequest.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetInfoRequest.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetLabelRequest.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetLightInfraredRequest.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetLightPowerRequest.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetLocationRequest.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetPowerRequest.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetRequest.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetServiceRequest.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetTagLabelsRequest.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetTagsRequest.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetTileEffectRequest.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetVersionRequest.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetWifiFirmwareRequest.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetWifiInfoRequest.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/Packet.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/PacketFactory.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/PacketHandler.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/PowerState.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/Product.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/SetColorRequest.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/SetColorZonesRequest.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/SetDimAbsoluteRequest.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/SetLabelRequest.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/SetLightInfraredRequest.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/SetLightPowerRequest.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/SetPowerRequest.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/SetTagsRequest.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/SetTileEffectRequest.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/SignalStrength.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/StateGroupResponse.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/StateHostFirmwareResponse.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/StateHostInfoResponse.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/StateInfoResponse.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/StateLabelResponse.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/StateLightInfraredResponse.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/StateLightPowerResponse.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/StateLocationResponse.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/StateMultiZoneResponse.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/StatePowerResponse.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/StateResponse.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/StateServiceResponse.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/StateTileEffectResponse.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/StateVersionResponse.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/StateWifiFirmwareResponse.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/StateWifiInfoResponse.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/StateZoneResponse.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/TagLabelsResponse.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/TagsResponse.java [deleted file]
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/util/LifxMessageUtil.java
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/util/LifxNetworkUtil.java
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/util/LifxSelectorUtil.java
bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/util/LifxThrottlingUtil.java
bundles/org.openhab.binding.lifx/src/test/java/org/openhab/binding/lifx/internal/fields/MACAddressTest.java [new file with mode: 0644]

index dca40a8ef1fb536b70aa14d5f6437235a57e3c1a..b507648a71f7dcaf72b46588b17f7289ec291440 100644 (file)
@@ -19,7 +19,7 @@ import org.openhab.core.thing.ThingUID;
 /**
  * The {@link LifxChannelFactory} creates dynamic LIFX channels.
  *
- * @author Wouter Born - Add i18n support
+ * @author Wouter Born - Initial contribution
  */
 @NonNullByDefault
 public interface LifxChannelFactory {
index 7c8c3b12ecca448ad2f5453a60171caa0cee03e2..333c610a7486fd352678bf357f95aa19fc2bee1c 100644 (file)
@@ -34,7 +34,7 @@ import org.osgi.service.component.annotations.Reference;
 /**
  * The {@link LifxChannelFactoryImpl} creates dynamic LIFX channels.
  *
- * @author Wouter Born - Add i18n support
+ * @author Wouter Born - Initial contribution
  */
 @NonNullByDefault
 @Component(service = LifxChannelFactory.class)
index 375ff33aa8bed14aafd2ce0d257861086fa2227f..bd27a3a7a83fc196e3a88cd9ef9370657dd181f1 100644 (file)
@@ -32,12 +32,12 @@ import java.util.function.Supplier;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
+import org.openhab.binding.lifx.internal.dto.GetServiceRequest;
+import org.openhab.binding.lifx.internal.dto.Packet;
+import org.openhab.binding.lifx.internal.dto.StateServiceResponse;
 import org.openhab.binding.lifx.internal.fields.MACAddress;
 import org.openhab.binding.lifx.internal.handler.LifxLightHandler.CurrentLightState;
 import org.openhab.binding.lifx.internal.listener.LifxResponsePacketListener;
-import org.openhab.binding.lifx.internal.protocol.GetServiceRequest;
-import org.openhab.binding.lifx.internal.protocol.Packet;
-import org.openhab.binding.lifx.internal.protocol.StateServiceResponse;
 import org.openhab.binding.lifx.internal.util.LifxNetworkUtil;
 import org.openhab.binding.lifx.internal.util.LifxSelectorUtil;
 import org.slf4j.Logger;
@@ -46,7 +46,7 @@ import org.slf4j.LoggerFactory;
 /**
  * The {@link LifxLightCommunicationHandler} is responsible for the communications with a light.
  *
- * @author Wouter Born - Extracted class from LifxLightHandler
+ * @author Wouter Born - Initial contribution
  */
 @NonNullByDefault
 public class LifxLightCommunicationHandler {
index f39c6fbf5162d450fa8e78cbf9b5e409166610c8..4b193398c824a938b9fee3042026611bcff42c1c 100644 (file)
@@ -33,7 +33,7 @@ public class LifxLightConfig {
 
     public @Nullable MACAddress getMACAddress() {
         String localDeviceId = deviceId;
-        return localDeviceId == null ? null : new MACAddress(localDeviceId, true);
+        return localDeviceId == null ? null : new MACAddress(localDeviceId);
     }
 
     public @Nullable InetSocketAddress getHost() {
index 254d87921c8b19c46c53981355ac053a3d69cc95..633960006b2fa67ae6acb70cb44bdeb8212c6ddf 100644 (file)
@@ -17,12 +17,11 @@ import java.util.concurrent.ScheduledExecutorService;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.openhab.binding.lifx.internal.handler.LifxLightHandler;
 import org.openhab.binding.lifx.internal.handler.LifxLightHandler.CurrentLightState;
-import org.openhab.binding.lifx.internal.protocol.Product;
 
 /**
  * The {@link LifxLightContext} shares the context of a light with {@link LifxLightHandler} helper objects.
  *
- * @author Wouter Born - Add optional host configuration parameter
+ * @author Wouter Born - Initial contribution
  */
 @NonNullByDefault
 public class LifxLightContext {
@@ -31,10 +30,10 @@ public class LifxLightContext {
     private final LifxLightConfig configuration;
     private final CurrentLightState currentLightState;
     private final LifxLightState pendingLightState;
-    private final Product product;
+    private final LifxProduct product;
     private final ScheduledExecutorService scheduler;
 
-    public LifxLightContext(String logId, Product product, LifxLightConfig configuration,
+    public LifxLightContext(String logId, LifxProduct product, LifxLightConfig configuration,
             CurrentLightState currentLightState, LifxLightState pendingLightState, ScheduledExecutorService scheduler) {
         this.logId = logId;
         this.configuration = configuration;
@@ -52,7 +51,7 @@ public class LifxLightContext {
         return configuration;
     }
 
-    public Product getProduct() {
+    public LifxProduct getProduct() {
         return product;
     }
 
index ad94aa26514f5ead8aa2b4be82cdb2affd1f5493..910c8b778783f0614c45fc741092ae6ea8b0bea6 100644 (file)
@@ -13,7 +13,7 @@
 package org.openhab.binding.lifx.internal;
 
 import static org.openhab.binding.lifx.internal.LifxBindingConstants.MIN_ZONE_INDEX;
-import static org.openhab.binding.lifx.internal.protocol.Product.Feature.*;
+import static org.openhab.binding.lifx.internal.LifxProduct.Feature.*;
 import static org.openhab.binding.lifx.internal.util.LifxMessageUtil.infraredToPercentType;
 
 import java.util.concurrent.ScheduledExecutorService;
@@ -23,22 +23,21 @@ import java.util.concurrent.locks.ReentrantLock;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
+import org.openhab.binding.lifx.internal.dto.GetColorZonesRequest;
+import org.openhab.binding.lifx.internal.dto.GetLightInfraredRequest;
+import org.openhab.binding.lifx.internal.dto.GetRequest;
+import org.openhab.binding.lifx.internal.dto.GetTileEffectRequest;
+import org.openhab.binding.lifx.internal.dto.GetWifiInfoRequest;
+import org.openhab.binding.lifx.internal.dto.Packet;
+import org.openhab.binding.lifx.internal.dto.StateLightInfraredResponse;
+import org.openhab.binding.lifx.internal.dto.StateLightPowerResponse;
+import org.openhab.binding.lifx.internal.dto.StateMultiZoneResponse;
+import org.openhab.binding.lifx.internal.dto.StatePowerResponse;
+import org.openhab.binding.lifx.internal.dto.StateResponse;
+import org.openhab.binding.lifx.internal.dto.StateTileEffectResponse;
+import org.openhab.binding.lifx.internal.dto.StateWifiInfoResponse;
 import org.openhab.binding.lifx.internal.fields.HSBK;
 import org.openhab.binding.lifx.internal.handler.LifxLightHandler.CurrentLightState;
-import org.openhab.binding.lifx.internal.protocol.GetColorZonesRequest;
-import org.openhab.binding.lifx.internal.protocol.GetLightInfraredRequest;
-import org.openhab.binding.lifx.internal.protocol.GetRequest;
-import org.openhab.binding.lifx.internal.protocol.GetTileEffectRequest;
-import org.openhab.binding.lifx.internal.protocol.GetWifiInfoRequest;
-import org.openhab.binding.lifx.internal.protocol.Packet;
-import org.openhab.binding.lifx.internal.protocol.Product;
-import org.openhab.binding.lifx.internal.protocol.StateLightInfraredResponse;
-import org.openhab.binding.lifx.internal.protocol.StateLightPowerResponse;
-import org.openhab.binding.lifx.internal.protocol.StateMultiZoneResponse;
-import org.openhab.binding.lifx.internal.protocol.StatePowerResponse;
-import org.openhab.binding.lifx.internal.protocol.StateResponse;
-import org.openhab.binding.lifx.internal.protocol.StateTileEffectResponse;
-import org.openhab.binding.lifx.internal.protocol.StateWifiInfoResponse;
 import org.openhab.core.library.types.PercentType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -47,7 +46,7 @@ import org.slf4j.LoggerFactory;
  * The {@link LifxLightCurrentStateUpdater} sends packets to a light in order to update the {@code currentLightState} to
  * the actual light state.
  *
- * @author Wouter Born - Extracted class from LifxLightHandler
+ * @author Wouter Born - Initial contribution
  */
 @NonNullByDefault
 public class LifxLightCurrentStateUpdater {
@@ -57,7 +56,7 @@ public class LifxLightCurrentStateUpdater {
     private final Logger logger = LoggerFactory.getLogger(LifxLightCurrentStateUpdater.class);
 
     private final String logId;
-    private final Product product;
+    private final LifxProduct product;
     private final CurrentLightState currentLightState;
     private final ScheduledExecutorService scheduler;
     private final LifxLightCommunicationHandler communicationHandler;
index 21011010dbe4870f94289b73c69670233c0f43c6..cfadb13a671b912fe5337039904c5b4eda99af2c 100644 (file)
@@ -26,18 +26,16 @@ import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.TimeUnit;
 import java.util.function.Supplier;
 
-import org.apache.commons.lang.StringUtils;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
+import org.openhab.binding.lifx.internal.dto.GetLabelRequest;
+import org.openhab.binding.lifx.internal.dto.GetServiceRequest;
+import org.openhab.binding.lifx.internal.dto.GetVersionRequest;
+import org.openhab.binding.lifx.internal.dto.Packet;
+import org.openhab.binding.lifx.internal.dto.StateLabelResponse;
+import org.openhab.binding.lifx.internal.dto.StateServiceResponse;
+import org.openhab.binding.lifx.internal.dto.StateVersionResponse;
 import org.openhab.binding.lifx.internal.fields.MACAddress;
-import org.openhab.binding.lifx.internal.protocol.GetLabelRequest;
-import org.openhab.binding.lifx.internal.protocol.GetServiceRequest;
-import org.openhab.binding.lifx.internal.protocol.GetVersionRequest;
-import org.openhab.binding.lifx.internal.protocol.Packet;
-import org.openhab.binding.lifx.internal.protocol.Product;
-import org.openhab.binding.lifx.internal.protocol.StateLabelResponse;
-import org.openhab.binding.lifx.internal.protocol.StateServiceResponse;
-import org.openhab.binding.lifx.internal.protocol.StateVersionResponse;
 import org.openhab.binding.lifx.internal.util.LifxSelectorUtil;
 import org.openhab.core.config.discovery.AbstractDiscoveryService;
 import org.openhab.core.config.discovery.DiscoveryResult;
@@ -87,7 +85,7 @@ public class LifxLightDiscovery extends AbstractDiscoveryService {
         private InetSocketAddress socketAddress;
         private String logId;
         private @Nullable String label;
-        private @Nullable Product product;
+        private @Nullable LifxProduct product;
         private long productVersion;
         private boolean supportedProduct = true;
         private LifxSelectorContext selectorContext;
@@ -300,7 +298,8 @@ public class LifxLightDiscovery extends AbstractDiscoveryService {
                     light.label = ((StateLabelResponse) packet).getLabel().trim();
                 } else if (packet instanceof StateVersionResponse) {
                     try {
-                        light.product = Product.getProductFromProductID(((StateVersionResponse) packet).getProduct());
+                        light.product = LifxProduct
+                                .getProductFromProductID(((StateVersionResponse) packet).getProduct());
                         light.productVersion = ((StateVersionResponse) packet).getVersion();
                     } catch (IllegalArgumentException e) {
                         logger.debug("Discovered an unsupported light ({}): {}", light.macAddress.getAsLabel(),
@@ -322,7 +321,7 @@ public class LifxLightDiscovery extends AbstractDiscoveryService {
     }
 
     private DiscoveryResult createDiscoveryResult(DiscoveredLight light) throws IllegalArgumentException {
-        Product product = light.product;
+        LifxProduct product = light.product;
         if (product == null) {
             throw new IllegalArgumentException("Product of discovered light is null");
         }
@@ -331,7 +330,7 @@ public class LifxLightDiscovery extends AbstractDiscoveryService {
         ThingUID thingUID = new ThingUID(product.getThingTypeUID(), macAsLabel);
 
         String label = light.label;
-        if (StringUtils.isBlank(label)) {
+        if (label == null || label.isBlank()) {
             label = product.getName();
         }
 
index c40400e3678bafe11b61cc660b76c535506284ee..62ef83091cdf911a3fa6393e3e84739e11fc6112 100644 (file)
@@ -21,17 +21,17 @@ import java.util.concurrent.locks.ReentrantLock;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
+import org.openhab.binding.lifx.internal.dto.GetEchoRequest;
+import org.openhab.binding.lifx.internal.dto.GetServiceRequest;
+import org.openhab.binding.lifx.internal.dto.Packet;
 import org.openhab.binding.lifx.internal.handler.LifxLightHandler.CurrentLightState;
-import org.openhab.binding.lifx.internal.protocol.GetEchoRequest;
-import org.openhab.binding.lifx.internal.protocol.GetServiceRequest;
-import org.openhab.binding.lifx.internal.protocol.Packet;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
  * The {@link LifxLightOnlineStateUpdater} sets the state of a light offline when it no longer responds to echo packets.
  *
- * @author Wouter Born - Extracted class from LifxLightHandler
+ * @author Wouter Born - Initial contribution
  */
 @NonNullByDefault
 public class LifxLightOnlineStateUpdater {
index 7be78cffbd52c1b6dc0efb4d2cbeca924fc285ae..9de0a75ff6f6a8d126142ece9a9be2d15c4c7760 100644 (file)
@@ -27,17 +27,16 @@ import java.util.concurrent.locks.ReentrantLock;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
+import org.openhab.binding.lifx.internal.dto.GetHostFirmwareRequest;
+import org.openhab.binding.lifx.internal.dto.GetVersionRequest;
+import org.openhab.binding.lifx.internal.dto.GetWifiFirmwareRequest;
+import org.openhab.binding.lifx.internal.dto.Packet;
+import org.openhab.binding.lifx.internal.dto.StateHostFirmwareResponse;
+import org.openhab.binding.lifx.internal.dto.StateVersionResponse;
+import org.openhab.binding.lifx.internal.dto.StateWifiFirmwareResponse;
 import org.openhab.binding.lifx.internal.fields.MACAddress;
 import org.openhab.binding.lifx.internal.handler.LifxLightHandler.CurrentLightState;
 import org.openhab.binding.lifx.internal.listener.LifxPropertiesUpdateListener;
-import org.openhab.binding.lifx.internal.protocol.GetHostFirmwareRequest;
-import org.openhab.binding.lifx.internal.protocol.GetVersionRequest;
-import org.openhab.binding.lifx.internal.protocol.GetWifiFirmwareRequest;
-import org.openhab.binding.lifx.internal.protocol.Packet;
-import org.openhab.binding.lifx.internal.protocol.Product;
-import org.openhab.binding.lifx.internal.protocol.StateHostFirmwareResponse;
-import org.openhab.binding.lifx.internal.protocol.StateVersionResponse;
-import org.openhab.binding.lifx.internal.protocol.StateWifiFirmwareResponse;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -45,7 +44,7 @@ import org.slf4j.LoggerFactory;
  * The {@link LifxLightPropertiesUpdater} updates the light properties when a light goes online. When packets get lost
  * the requests are resent when the {@code UPDATE_INTERVAL} elapses.
  *
- * @author Wouter Born - Update light properties when online
+ * @author Wouter Born - Initial contribution
  */
 @NonNullByDefault
 public class LifxLightPropertiesUpdater {
@@ -157,7 +156,7 @@ public class LifxLightPropertiesUpdater {
             properties.put(LifxBindingConstants.PROPERTY_PRODUCT_VERSION, Long.toString(productVersion));
 
             try {
-                Product product = Product.getProductFromProductID(productId);
+                LifxProduct product = LifxProduct.getProductFromProductID(productId);
                 properties.put(LifxBindingConstants.PROPERTY_PRODUCT_NAME, product.getName());
                 properties.put(LifxBindingConstants.PROPERTY_VENDOR_ID, Long.toString(product.getVendor().getID()));
                 properties.put(LifxBindingConstants.PROPERTY_VENDOR_NAME, product.getVendor().getName());
index a4db52c45cfe6dadbf9f2286f7592f283869af60..b3bbefaf201a732406e1499d0d13023e29d09eb5 100644 (file)
@@ -22,11 +22,11 @@ import java.util.concurrent.CopyOnWriteArrayList;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
+import org.openhab.binding.lifx.internal.dto.Effect;
+import org.openhab.binding.lifx.internal.dto.PowerState;
+import org.openhab.binding.lifx.internal.dto.SignalStrength;
 import org.openhab.binding.lifx.internal.fields.HSBK;
 import org.openhab.binding.lifx.internal.listener.LifxLightStateListener;
-import org.openhab.binding.lifx.internal.protocol.Effect;
-import org.openhab.binding.lifx.internal.protocol.PowerState;
-import org.openhab.binding.lifx.internal.protocol.SignalStrength;
 import org.openhab.core.library.types.HSBType;
 import org.openhab.core.library.types.OnOffType;
 import org.openhab.core.library.types.PercentType;
@@ -34,7 +34,7 @@ import org.openhab.core.library.types.PercentType;
 /**
  * The {@link LifxLightState} stores the properties that represent the state of a light.
  *
- * @author Wouter Born - Extracted class from LifxLightHandler, added listener logic
+ * @author Wouter Born - Initial contribution
  */
 @NonNullByDefault
 public class LifxLightState {
index 4e2ccd16ab8ecc4788acb65840ee09a13e1d8cba..c2ee8d1c9ba423687d0ee721ebf6993851363993 100644 (file)
@@ -13,7 +13,7 @@
 package org.openhab.binding.lifx.internal;
 
 import static org.openhab.binding.lifx.internal.LifxBindingConstants.PACKET_INTERVAL;
-import static org.openhab.binding.lifx.internal.protocol.Product.Feature.MULTIZONE;
+import static org.openhab.binding.lifx.internal.LifxProduct.Feature.MULTIZONE;
 import static org.openhab.binding.lifx.internal.util.LifxMessageUtil.*;
 
 import java.time.Duration;
@@ -29,25 +29,24 @@ import java.util.concurrent.locks.ReentrantLock;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
+import org.openhab.binding.lifx.internal.dto.AcknowledgementResponse;
+import org.openhab.binding.lifx.internal.dto.ApplicationRequest;
+import org.openhab.binding.lifx.internal.dto.Effect;
+import org.openhab.binding.lifx.internal.dto.GetColorZonesRequest;
+import org.openhab.binding.lifx.internal.dto.GetLightInfraredRequest;
+import org.openhab.binding.lifx.internal.dto.GetLightPowerRequest;
+import org.openhab.binding.lifx.internal.dto.GetRequest;
+import org.openhab.binding.lifx.internal.dto.Packet;
+import org.openhab.binding.lifx.internal.dto.PowerState;
+import org.openhab.binding.lifx.internal.dto.SetColorRequest;
+import org.openhab.binding.lifx.internal.dto.SetColorZonesRequest;
+import org.openhab.binding.lifx.internal.dto.SetLightInfraredRequest;
+import org.openhab.binding.lifx.internal.dto.SetLightPowerRequest;
+import org.openhab.binding.lifx.internal.dto.SetPowerRequest;
+import org.openhab.binding.lifx.internal.dto.SetTileEffectRequest;
+import org.openhab.binding.lifx.internal.dto.SignalStrength;
 import org.openhab.binding.lifx.internal.fields.HSBK;
 import org.openhab.binding.lifx.internal.listener.LifxLightStateListener;
-import org.openhab.binding.lifx.internal.protocol.AcknowledgementResponse;
-import org.openhab.binding.lifx.internal.protocol.ApplicationRequest;
-import org.openhab.binding.lifx.internal.protocol.Effect;
-import org.openhab.binding.lifx.internal.protocol.GetColorZonesRequest;
-import org.openhab.binding.lifx.internal.protocol.GetLightInfraredRequest;
-import org.openhab.binding.lifx.internal.protocol.GetLightPowerRequest;
-import org.openhab.binding.lifx.internal.protocol.GetRequest;
-import org.openhab.binding.lifx.internal.protocol.Packet;
-import org.openhab.binding.lifx.internal.protocol.PowerState;
-import org.openhab.binding.lifx.internal.protocol.Product;
-import org.openhab.binding.lifx.internal.protocol.SetColorRequest;
-import org.openhab.binding.lifx.internal.protocol.SetColorZonesRequest;
-import org.openhab.binding.lifx.internal.protocol.SetLightInfraredRequest;
-import org.openhab.binding.lifx.internal.protocol.SetLightPowerRequest;
-import org.openhab.binding.lifx.internal.protocol.SetPowerRequest;
-import org.openhab.binding.lifx.internal.protocol.SetTileEffectRequest;
-import org.openhab.binding.lifx.internal.protocol.SignalStrength;
 import org.openhab.core.library.types.PercentType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -57,7 +56,7 @@ import org.slf4j.LoggerFactory;
  * light so the change the actual light state to that of the {@code pendingLightState}. When the light does not
  * acknowledge a packet, it resends it (max 3 times).
  *
- * @author Wouter Born - Extracted class from LifxLightHandler, added logic for handling packet loss
+ * @author Wouter Born - Initial contribution
  */
 @NonNullByDefault
 public class LifxLightStateChanger implements LifxLightStateListener {
@@ -75,7 +74,7 @@ public class LifxLightStateChanger implements LifxLightStateListener {
     private final Logger logger = LoggerFactory.getLogger(LifxLightStateChanger.class);
 
     private final String logId;
-    private final Product product;
+    private final LifxProduct product;
     private final Duration fadeTime;
     private final LifxLightState pendingLightState;
     private final ScheduledExecutorService scheduler;
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/LifxProduct.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/LifxProduct.java
new file mode 100644 (file)
index 0000000..0416d37
--- /dev/null
@@ -0,0 +1,311 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal;
+
+import static org.openhab.binding.lifx.internal.LifxProduct.Feature.*;
+import static org.openhab.binding.lifx.internal.LifxProduct.TemperatureRange.*;
+import static org.openhab.binding.lifx.internal.LifxProduct.Vendor.LIFX;
+
+import java.util.Arrays;
+import java.util.EnumSet;
+
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.openhab.core.thing.ThingTypeUID;
+
+/**
+ * Enumerates the LIFX products, their IDs and feature set.
+ *
+ * @see https://lan.developer.lifx.com/docs/lifx-products
+ *
+ * @author Wouter Born - Initial contribution
+ * @author Wouter Born - Add temperature ranges and simplify feature definitions
+ */
+@NonNullByDefault
+public enum LifxProduct {
+
+    PRODUCT_1(1, "LIFX Original 1000", TR_2500_9000, COLOR),
+    PRODUCT_3(3, "LIFX Color 650", TR_2500_9000, COLOR),
+    PRODUCT_10(10, "LIFX White 800 (Low Voltage)", TR_2700_6500),
+    PRODUCT_11(11, "LIFX White 800 (High Voltage)", TR_2700_6500),
+    PRODUCT_15(15, "LIFX Color 1000", TR_2500_9000, COLOR),
+    PRODUCT_18(18, "LIFX White 900 BR30 (Low Voltage)", TR_2700_6500),
+    PRODUCT_19(19, "LIFX White 900 BR30 (High Voltage)", TR_2700_6500),
+    PRODUCT_20(20, "LIFX Color 1000 BR30", TR_2500_9000, COLOR),
+    PRODUCT_22(22, "LIFX Color 1000", TR_2500_9000, COLOR),
+    PRODUCT_27(27, "LIFX A19", TR_2500_9000, COLOR),
+    PRODUCT_28(28, "LIFX BR30", TR_2500_9000, COLOR),
+    PRODUCT_29(29, "LIFX A19 Night Vision", TR_2500_9000, COLOR, INFRARED),
+    PRODUCT_30(30, "LIFX BR30 Night Vision", TR_2500_9000, COLOR, INFRARED),
+    PRODUCT_31(31, "LIFX Z", TR_2500_9000, COLOR, MULTIZONE),
+    PRODUCT_32(32, "LIFX Z", TR_2500_9000, COLOR, MULTIZONE),
+    PRODUCT_36(36, "LIFX Downlight", TR_2500_9000, COLOR),
+    PRODUCT_37(37, "LIFX Downlight", TR_2500_9000, COLOR),
+    PRODUCT_38(38, "LIFX Beam", TR_2500_9000, COLOR, MULTIZONE),
+    PRODUCT_39(39, "LIFX Downlight White to Warm", TR_1500_9000),
+    PRODUCT_40(40, "LIFX Downlight", TR_2500_9000, COLOR),
+    PRODUCT_43(43, "LIFX A19", TR_2500_9000, COLOR),
+    PRODUCT_44(44, "LIFX BR30", TR_2500_9000, COLOR),
+    PRODUCT_45(45, "LIFX A19 Night Vision", TR_2500_9000, COLOR, INFRARED),
+    PRODUCT_46(46, "LIFX BR30 Night Vision", TR_2500_9000, COLOR, INFRARED),
+    PRODUCT_49(49, "LIFX Mini Color", TR_2500_9000, COLOR),
+    PRODUCT_50(50, "LIFX Mini White to Warm", TR_1500_4000),
+    PRODUCT_51(51, "LIFX Mini White", TR_2700_2700),
+    PRODUCT_52(52, "LIFX GU10", TR_2500_9000, COLOR),
+    PRODUCT_53(53, "LIFX GU10", TR_2500_9000, COLOR),
+    PRODUCT_55(55, "LIFX Tile", TR_2500_9000, CHAIN, COLOR, MATRIX, TILE_EFFECT),
+    PRODUCT_57(57, "LIFX Candle", TR_1500_9000, COLOR, MATRIX),
+    PRODUCT_59(59, "LIFX Mini Color", TR_2500_9000, COLOR),
+    PRODUCT_60(60, "LIFX Mini White to Warm", TR_1500_4000),
+    PRODUCT_61(61, "LIFX Mini White", TR_2700_2700),
+    PRODUCT_62(62, "LIFX A19", TR_2500_9000, COLOR),
+    PRODUCT_63(63, "LIFX BR30", TR_2500_9000, COLOR),
+    PRODUCT_64(64, "LIFX A19 Night Vision", TR_2500_9000, COLOR, INFRARED),
+    PRODUCT_65(65, "LIFX BR30 Night Vision", TR_2500_9000, COLOR, INFRARED),
+    PRODUCT_66(66, "LIFX Mini White", TR_2700_2700),
+    PRODUCT_68(68, "LIFX Candle", TR_1500_9000, MATRIX),
+    PRODUCT_81(81, "LIFX Candle White to Warm", TR_2200_6500),
+    PRODUCT_82(82, "LIFX Filament Clear", TR_2100_2100),
+    PRODUCT_85(85, "LIFX Filament Amber", TR_2000_2000),
+    PRODUCT_87(87, "LIFX Mini White", TR_2700_2700),
+    PRODUCT_88(88, "LIFX Mini White", TR_2700_2700),
+    PRODUCT_90(90, "LIFX Clean", TR_2500_9000, HEV),
+    PRODUCT_91(91, "LIFX Color", TR_2500_9000, COLOR),
+    PRODUCT_92(92, "LIFX Color", TR_2500_9000, COLOR),
+    PRODUCT_94(94, "LIFX BR30", TR_2500_9000, COLOR),
+    PRODUCT_96(96, "LIFX Candle White to Warm", TR_2200_6500),
+    PRODUCT_97(97, "LIFX A19", TR_2500_9000, COLOR),
+    PRODUCT_98(98, "LIFX BR30", TR_2500_9000, COLOR),
+    PRODUCT_99(99, "LIFX Clean", TR_2500_9000, HEV),
+    PRODUCT_100(100, "LIFX Filament Clear", TR_2100_2100),
+    PRODUCT_101(101, "LIFX Filament Amber", TR_2000_2000),
+    PRODUCT_109(109, "LIFX A19 Night Vision", TR_2500_9000, COLOR, INFRARED),
+    PRODUCT_110(110, "LIFX BR30 Night Vision", TR_2500_9000, COLOR, INFRARED),
+    PRODUCT_111(111, "LIFX A19 Night Vision", TR_2500_9000, COLOR, INFRARED);
+
+    /**
+     * Enumerates the product features.
+     */
+    public enum Feature {
+        CHAIN,
+        COLOR,
+        HEV,
+        INFRARED,
+        MATRIX,
+        MULTIZONE,
+        TILE_EFFECT
+    }
+
+    /**
+     * Enumerates the product vendors.
+     */
+    public enum Vendor {
+        LIFX(1, "LIFX");
+
+        private final int id;
+        private final String name;
+
+        Vendor(int id, String name) {
+            this.id = id;
+            this.name = name;
+        }
+
+        public int getID() {
+            return id;
+        }
+
+        public String getName() {
+            return name;
+        }
+    }
+
+    /**
+     * Enumerates the color temperature ranges of lights.
+     */
+    public enum TemperatureRange {
+        /**
+         * 1500-4000K
+         */
+        TR_1500_4000(1500, 4000),
+
+        /**
+         * 1500-9000K
+         */
+        TR_1500_9000(1500, 9000),
+
+        /**
+         * 2000-2000K
+         */
+        TR_2000_2000(2000, 2000),
+
+        /**
+         * 2100-2100K
+         */
+        TR_2100_2100(2100, 2100),
+
+        /**
+         * 2200-6500K
+         */
+        TR_2200_6500(2200, 6500),
+
+        /**
+         * 2500-9000K
+         */
+        TR_2500_9000(2500, 9000),
+
+        /**
+         * 2700-2700K
+         */
+        TR_2700_2700(2700, 2700),
+
+        /**
+         * 2700-6500K
+         */
+        TR_2700_6500(2700, 6500);
+
+        private final int minimum;
+        private final int maximum;
+
+        TemperatureRange(int minimum, int maximum) {
+            this.minimum = minimum;
+            this.maximum = maximum;
+        }
+
+        /**
+         * The minimum color temperature in degrees Kelvin.
+         *
+         * @return minimum color temperature (K)
+         */
+        public int getMinimum() {
+            return minimum;
+        }
+
+        /**
+         * The maxiumum color temperature in degrees Kelvin.
+         *
+         * @return maximum color temperature (K)
+         */
+        public int getMaximum() {
+            return maximum;
+        }
+
+        /**
+         * The color temperature range in degrees Kelvin.
+         *
+         * @return difference between maximum and minimum color temperature values
+         */
+        public int getRange() {
+            return maximum - minimum;
+        }
+    }
+
+    private final Vendor vendor;
+    private final long id;
+    private final String name;
+    private final TemperatureRange temperatureRange;
+    private final EnumSet<Feature> features = EnumSet.noneOf(Feature.class);
+
+    private LifxProduct(long id, String name, TemperatureRange temperatureRange) {
+        this(LIFX, id, name, temperatureRange);
+    }
+
+    private LifxProduct(long id, String name, TemperatureRange temperatureRange, Feature... features) {
+        this(LIFX, id, name, temperatureRange, features);
+    }
+
+    private LifxProduct(Vendor vendor, long id, String name, TemperatureRange temperatureRange) {
+        this(vendor, id, name, temperatureRange, new Feature[0]);
+    }
+
+    private LifxProduct(Vendor vendor, long id, String name, TemperatureRange temperatureRange, Feature... features) {
+        this.vendor = vendor;
+        this.id = id;
+        this.name = name;
+        this.temperatureRange = temperatureRange;
+        this.features.addAll(Arrays.asList(features));
+    }
+
+    @Override
+    public String toString() {
+        return name;
+    }
+
+    public Vendor getVendor() {
+        return vendor;
+    }
+
+    public long getID() {
+        return id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public TemperatureRange getTemperatureRange() {
+        return temperatureRange;
+    }
+
+    public ThingTypeUID getThingTypeUID() {
+        if (hasFeature(COLOR)) {
+            if (hasFeature(TILE_EFFECT)) {
+                return LifxBindingConstants.THING_TYPE_TILELIGHT;
+            } else if (hasFeature(INFRARED)) {
+                return LifxBindingConstants.THING_TYPE_COLORIRLIGHT;
+            } else if (hasFeature(MULTIZONE)) {
+                return LifxBindingConstants.THING_TYPE_COLORMZLIGHT;
+            } else {
+                return LifxBindingConstants.THING_TYPE_COLORLIGHT;
+            }
+        } else {
+            return LifxBindingConstants.THING_TYPE_WHITELIGHT;
+        }
+    }
+
+    public boolean hasFeature(Feature feature) {
+        return features.contains(feature);
+    }
+
+    /**
+     * Returns a product that has the given thing type UID.
+     *
+     * @param uid a thing type UID
+     * @return a product that has the given thing type UID
+     * @throws IllegalArgumentException when <code>uid</code> is not a valid LIFX thing type UID
+     */
+    public static LifxProduct getLikelyProduct(ThingTypeUID uid) throws IllegalArgumentException {
+        for (LifxProduct product : LifxProduct.values()) {
+            if (product.getThingTypeUID().equals(uid)) {
+                return product;
+            }
+        }
+
+        throw new IllegalArgumentException(uid + " is not a valid product thing type UID");
+    }
+
+    /**
+     * Returns the product that has the given product ID.
+     *
+     * @param id the product ID
+     * @return the product that has the given product ID
+     * @throws IllegalArgumentException when <code>id</code> is not a valid LIFX product ID
+     */
+    public static LifxProduct getProductFromProductID(long id) throws IllegalArgumentException {
+        for (LifxProduct product : LifxProduct.values()) {
+            if (product.id == id) {
+                return product;
+            }
+        }
+
+        throw new IllegalArgumentException(id + " is not a valid product ID");
+    }
+}
index 0cd6f671959a4c6aa665c637a697c7636afa433b..bc7f3ffd3a59c1dc339f71cca12b6146b89d120b 100644 (file)
@@ -25,7 +25,7 @@ import org.openhab.binding.lifx.internal.fields.MACAddress;
  * The {@link LifxSelectorContext} stores the context that is used for broadcast and unicast communications with a
  * light using a {@link Selector}.
  *
- * @author Wouter Born - Make selector logic reusable between discovery and handlers
+ * @author Wouter Born - Initial contribution
  */
 @NonNullByDefault
 public class LifxSelectorContext {
index 5f9e10899153a14a5603188125bfd7ae3cab0560..1d94e146389b52036ba6de37aef01aadae72fff6 100644 (file)
@@ -20,7 +20,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
 /**
  * Supplies sequence numbers for packets in the range [0, 255].
  *
- * @author Wouter Born - Make selector logic reusable between discovery and handlers
+ * @author Wouter Born - Initial contribution
  */
 @NonNullByDefault
 public class LifxSequenceNumberSupplier implements Supplier<Integer> {
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/AcknowledgementResponse.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/AcknowledgementResponse.java
new file mode 100644 (file)
index 0000000..74ace86
--- /dev/null
@@ -0,0 +1,52 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import java.nio.ByteBuffer;
+
+/**
+ * @author Tim Buckley - Initial contribution
+ * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
+ */
+public class AcknowledgementResponse extends Packet {
+
+    public static final int TYPE = 0x2D;
+
+    public AcknowledgementResponse() {
+    }
+
+    @Override
+    public int packetType() {
+        return TYPE;
+    }
+
+    @Override
+    protected int packetLength() {
+        return 0;
+    }
+
+    @Override
+    protected void parsePacket(ByteBuffer bytes) {
+        // do nothing
+    }
+
+    @Override
+    protected ByteBuffer packetBytes() {
+        return ByteBuffer.allocate(0);
+    }
+
+    @Override
+    public int[] expectedResponses() {
+        return new int[] {};
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/ApplicationRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/ApplicationRequest.java
new file mode 100644 (file)
index 0000000..9e53718
--- /dev/null
@@ -0,0 +1,66 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+/**
+ * @author Wouter Born - Initial contribution
+ */
+public enum ApplicationRequest {
+
+    /**
+     * Don't apply the requested changes until a message with APPLY or APPLY_ONLY is sent.
+     */
+    NO_APPLY(0x00),
+
+    /**
+     * Apply the changes immediately and apply any pending changes.
+     */
+    APPLY(0x01),
+
+    /**
+     * Ignore the requested changes in this message and only apply pending changes.
+     */
+    APPLY_ONLY(0x02);
+
+    private final int value;
+
+    private ApplicationRequest(int value) {
+        this.value = value;
+    }
+
+    /**
+     * Gets the integer value of this application request.
+     *
+     * @return the integer value
+     */
+    public int getValue() {
+        return value;
+    }
+
+    /**
+     * Returns the {@link ApplicationRequest} for the given integer value.
+     *
+     * @param value the integer value
+     * @return the {@link ApplicationRequest} or <code>null</code>, if no {@link ApplicationRequest} exists for the
+     *         given value
+     */
+    public static ApplicationRequest fromValue(int value) {
+        for (ApplicationRequest ar : values()) {
+            if (ar.getValue() == value) {
+                return ar;
+            }
+        }
+
+        return null;
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/EchoRequestResponse.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/EchoRequestResponse.java
new file mode 100644 (file)
index 0000000..058a760
--- /dev/null
@@ -0,0 +1,67 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import java.nio.ByteBuffer;
+
+import org.openhab.binding.lifx.internal.fields.ByteField;
+import org.openhab.binding.lifx.internal.fields.Field;
+
+/**
+ * @author Tim Buckley - Initial contribution
+ * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
+ */
+public class EchoRequestResponse extends Packet {
+
+    public static final int TYPE = 0x3B;
+
+    public static final Field<ByteBuffer> FIELD_PAYLOAD = new ByteField(64);
+
+    private ByteBuffer payload;
+
+    public EchoRequestResponse() {
+    }
+
+    public ByteBuffer getPayload() {
+        return payload;
+    }
+
+    public void setPayload(ByteBuffer location) {
+        this.payload = location;
+    }
+
+    @Override
+    public int packetType() {
+        return TYPE;
+    }
+
+    @Override
+    protected int packetLength() {
+        return 64;
+    }
+
+    @Override
+    protected void parsePacket(ByteBuffer bytes) {
+        payload = FIELD_PAYLOAD.value(bytes);
+    }
+
+    @Override
+    protected ByteBuffer packetBytes() {
+        return ByteBuffer.allocate(packetLength()).put(FIELD_PAYLOAD.bytes(payload));
+    }
+
+    @Override
+    public int[] expectedResponses() {
+        return new int[] {};
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/Effect.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/Effect.java
new file mode 100644 (file)
index 0000000..2490e22
--- /dev/null
@@ -0,0 +1,169 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
+import org.openhab.binding.lifx.internal.LifxBindingConstants;
+import org.openhab.binding.lifx.internal.fields.HSBK;
+
+/**
+ * This class represents LIFX Tile effect
+ *
+ * @author Pawel Pieczul - Initial contribution
+ */
+@NonNullByDefault
+public class Effect {
+    public enum EffectType {
+        OFF(0),
+        MORPH(2),
+        FLAME(3);
+
+        Integer type;
+
+        EffectType(Integer type) {
+            this.type = type;
+        }
+
+        public static EffectType fromValue(Integer value) {
+            switch (value) {
+                case 0:
+                    return OFF;
+                case 2:
+                    return MORPH;
+                case 3:
+                    return FLAME;
+                default:
+                    throw new IllegalArgumentException("Unknown effect type");
+            }
+        }
+
+        public static EffectType fromValue(String value) {
+            if (LifxBindingConstants.CHANNEL_TYPE_EFFECT_OPTION_OFF.equals(value)) {
+                return OFF;
+            } else if (LifxBindingConstants.CHANNEL_TYPE_EFFECT_OPTION_MORPH.equals(value)) {
+                return MORPH;
+            } else if (LifxBindingConstants.CHANNEL_TYPE_EFFECT_OPTION_FLAME.equals(value)) {
+                return FLAME;
+            }
+            throw new IllegalArgumentException("Unknown effect type");
+        }
+
+        public Integer intValue() {
+            return type;
+        }
+
+        public String stringValue() {
+            switch (type) {
+                case 2:
+                    return LifxBindingConstants.CHANNEL_TYPE_EFFECT_OPTION_MORPH;
+                case 3:
+                    return LifxBindingConstants.CHANNEL_TYPE_EFFECT_OPTION_FLAME;
+                default:
+                    return LifxBindingConstants.CHANNEL_TYPE_EFFECT_OPTION_OFF;
+            }
+        }
+    }
+
+    final EffectType type;
+    final Long speed;
+    final Long duration;
+    final HSBK[] palette;
+
+    public EffectType getType() {
+        return type;
+    }
+
+    public Long getSpeed() {
+        return speed;
+    }
+
+    public Long getDuration() {
+        return duration;
+    }
+
+    HSBK[] getPalette() {
+        return palette;
+    }
+
+    public Effect(EffectType type, Long speed, Long duration, HSBK[] palette) {
+        this.type = type;
+        this.palette = palette;
+        this.duration = duration;
+        this.speed = speed;
+    }
+
+    public Effect(Integer type, Long speed, Long duration, HSBK[] palette) {
+        this(EffectType.fromValue(type), speed, duration, palette);
+    }
+
+    public Effect() {
+        this(EffectType.OFF, 3000L, 0L, new HSBK[0]);
+    }
+
+    public static Effect createDefault(String type, @Nullable Long morphSpeed, @Nullable Long flameSpeed) {
+        Long speed;
+        EffectType effectType = EffectType.fromValue(type);
+        switch (effectType) {
+            case OFF:
+                return new Effect(effectType, 0L, 0L, new HSBK[0]);
+            case MORPH:
+                if (morphSpeed == null) {
+                    speed = 3000L;
+                } else {
+                    speed = morphSpeed;
+                }
+                HSBK[] p = { new HSBK(0, 65535, 65535, 3500), new HSBK(7281, 65535, 65535, 3500),
+                        new HSBK(10922, 65535, 65535, 3500), new HSBK(22209, 65535, 65535, 3500),
+                        new HSBK(43507, 65535, 65535, 3500), new HSBK(49333, 65535, 65535, 3500),
+                        new HSBK(53520, 65535, 65535, 3500) };
+                return new Effect(effectType, speed, 0L, p);
+            case FLAME:
+                if (flameSpeed == null) {
+                    speed = 4000L;
+                } else {
+                    speed = flameSpeed;
+                }
+                return new Effect(effectType, speed, 0L, new HSBK[0]);
+            default:
+                throw new IllegalArgumentException("Unknown effect type");
+        }
+    }
+
+    @Override
+    public boolean equals(@Nullable Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (o == null) {
+            return false;
+        }
+        if (o.getClass() != getClass()) {
+            return false;
+        }
+        Effect n = (Effect) o;
+        return n.getType().equals(this.getType()) && n.duration.equals(this.duration) && n.speed.equals(this.speed)
+                && n.palette == this.palette;
+    }
+
+    @Override
+    public int hashCode() {
+        Long hash = 1L;
+        int prime = 31;
+        hash = prime * hash + type.hashCode();
+        hash = prime * hash + duration;
+        hash = prime * hash + speed;
+        hash = prime * hash + palette.hashCode();
+        return hash.intValue();
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GenericHandler.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GenericHandler.java
new file mode 100644 (file)
index 0000000..8447c2d
--- /dev/null
@@ -0,0 +1,76 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.nio.ByteBuffer;
+
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
+/**
+ * A generic handler that dynamically creates "standard" packet instances.
+ *
+ * <p>
+ * Packet types must have an empty constructor and cannot require any
+ * additional logic (other than parsing).
+ *
+ * @param <T> the packet subtype this handler constructs
+ *
+ * @author Tim Buckley - Initial contribution
+ * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
+ */
+@NonNullByDefault
+public class GenericHandler<T extends Packet> implements PacketHandler<T> {
+
+    private Constructor<T> constructor;
+
+    private boolean typeFound;
+    private int type;
+
+    public boolean isTypeFound() {
+        return typeFound;
+    }
+
+    public int getType() {
+        return type;
+    }
+
+    public GenericHandler(Class<T> clazz) {
+        try {
+            constructor = clazz.getConstructor();
+        } catch (NoSuchMethodException ex) {
+            throw new IllegalArgumentException("Packet class cannot be handled by GenericHandler", ex);
+        }
+
+        try {
+            Field typeField = clazz.getField("TYPE");
+            type = (int) typeField.get(null);
+            typeFound = true;
+        } catch (NoSuchFieldException | IllegalAccessException ex) {
+            // silently ignore
+            typeFound = false;
+        }
+    }
+
+    @Override
+    public T handle(ByteBuffer buf) {
+        try {
+            T ret = constructor.newInstance();
+            ret.parse(buf);
+            return ret;
+        } catch (ReflectiveOperationException ex) {
+            throw new IllegalArgumentException("Unable to instantiate empty packet", ex);
+        }
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GenericPacket.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GenericPacket.java
new file mode 100644 (file)
index 0000000..b0a7380
--- /dev/null
@@ -0,0 +1,46 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import java.nio.ByteBuffer;
+
+/**
+ * @author Tim Buckley - Initial contribution
+ * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
+ */
+public class GenericPacket extends Packet {
+
+    @Override
+    public int packetType() {
+        return 0;
+    }
+
+    @Override
+    protected int packetLength() {
+        return 0;
+    }
+
+    @Override
+    protected void parsePacket(ByteBuffer bytes) {
+    }
+
+    @Override
+    protected ByteBuffer packetBytes() {
+        return ByteBuffer.allocate(0);
+    }
+
+    @Override
+    public int[] expectedResponses() {
+        return new int[] {};
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetColorZonesRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetColorZonesRequest.java
new file mode 100644 (file)
index 0000000..fbdc0dd
--- /dev/null
@@ -0,0 +1,85 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import static org.openhab.binding.lifx.internal.LifxBindingConstants.*;
+
+import java.nio.ByteBuffer;
+
+import org.openhab.binding.lifx.internal.fields.Field;
+import org.openhab.binding.lifx.internal.fields.UInt8Field;
+
+/**
+ * @author Wouter Born - Initial contribution
+ */
+public class GetColorZonesRequest extends Packet {
+
+    public static final int TYPE = 0x1F6;
+
+    public static final Field<Integer> FIELD_START_INDEX = new UInt8Field();
+    public static final Field<Integer> FIELD_END_INDEX = new UInt8Field();
+
+    private int startIndex = MIN_ZONE_INDEX;
+    private int endIndex = MAX_ZONE_INDEX;
+
+    public GetColorZonesRequest() {
+        setTagged(false);
+        setAddressable(true);
+        setResponseRequired(true);
+    }
+
+    public GetColorZonesRequest(int index) {
+        this(index, index);
+    }
+
+    public GetColorZonesRequest(int startIndex, int endIndex) {
+        this();
+        this.startIndex = startIndex;
+        this.endIndex = endIndex;
+    }
+
+    public int getStartIndex() {
+        return startIndex;
+    }
+
+    public int getEndIndex() {
+        return endIndex;
+    }
+
+    @Override
+    public int packetType() {
+        return TYPE;
+    }
+
+    @Override
+    protected int packetLength() {
+        return 2;
+    }
+
+    @Override
+    protected void parsePacket(ByteBuffer bytes) {
+        startIndex = FIELD_START_INDEX.value(bytes);
+        endIndex = FIELD_END_INDEX.value(bytes);
+    }
+
+    @Override
+    protected ByteBuffer packetBytes() {
+        return ByteBuffer.allocate(packetLength()).put(FIELD_START_INDEX.bytes(startIndex))
+                .put(FIELD_END_INDEX.bytes(endIndex));
+    }
+
+    @Override
+    public int[] expectedResponses() {
+        return new int[] { StateMultiZoneResponse.TYPE, StateZoneResponse.TYPE };
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetEchoRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetEchoRequest.java
new file mode 100644 (file)
index 0000000..be09a90
--- /dev/null
@@ -0,0 +1,80 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import java.nio.ByteBuffer;
+
+import org.openhab.binding.lifx.internal.fields.ByteField;
+import org.openhab.binding.lifx.internal.fields.Field;
+
+/**
+ * @author Tim Buckley - Initial contribution
+ * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
+ */
+public class GetEchoRequest extends Packet {
+
+    public static final int TYPE = 0x3A;
+
+    public static final Field<ByteBuffer> FIELD_PAYLOAD = new ByteField(64);
+
+    private ByteBuffer payload;
+
+    public GetEchoRequest() {
+        setTagged(false);
+        setAddressable(true);
+        setResponseRequired(true);
+    }
+
+    public ByteBuffer getPayload() {
+        return payload;
+    }
+
+    public void setPayload(ByteBuffer payload) {
+        this.payload = payload;
+    }
+
+    @Override
+    public int packetType() {
+        return TYPE;
+    }
+
+    @Override
+    protected int packetLength() {
+        return 64;
+    }
+
+    @Override
+    protected void parsePacket(ByteBuffer bytes) {
+        // do nothing
+    }
+
+    @Override
+    protected ByteBuffer packetBytes() {
+        return ByteBuffer.allocate(packetLength()).put(FIELD_PAYLOAD.bytes(payload));
+    }
+
+    @Override
+    public int[] expectedResponses() {
+        return new int[] { EchoRequestResponse.TYPE };
+    }
+
+    public static GetEchoRequest currentTimeEchoRequest() {
+        ByteBuffer payload = ByteBuffer.allocate(Long.SIZE / 8);
+        payload.putLong(System.currentTimeMillis());
+
+        GetEchoRequest request = new GetEchoRequest();
+        request.setResponseRequired(true);
+        request.setPayload(payload);
+        return request;
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetGroupRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetGroupRequest.java
new file mode 100644 (file)
index 0000000..a6f8e13
--- /dev/null
@@ -0,0 +1,55 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import java.nio.ByteBuffer;
+
+/**
+ * @author Tim Buckley - Initial contribution
+ * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
+ */
+public class GetGroupRequest extends Packet {
+
+    public static final int TYPE = 0x33;
+
+    public GetGroupRequest() {
+        setTagged(false);
+        setAddressable(true);
+        setResponseRequired(true);
+    }
+
+    @Override
+    public int packetType() {
+        return TYPE;
+    }
+
+    @Override
+    protected int packetLength() {
+        return 0;
+    }
+
+    @Override
+    protected void parsePacket(ByteBuffer bytes) {
+        // do nothing
+    }
+
+    @Override
+    protected ByteBuffer packetBytes() {
+        return ByteBuffer.allocate(0);
+    }
+
+    @Override
+    public int[] expectedResponses() {
+        return new int[] { StateGroupResponse.TYPE };
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetHostFirmwareRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetHostFirmwareRequest.java
new file mode 100644 (file)
index 0000000..814f873
--- /dev/null
@@ -0,0 +1,55 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import java.nio.ByteBuffer;
+
+/**
+ * @author Tim Buckley - Initial contribution
+ * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
+ */
+public class GetHostFirmwareRequest extends Packet {
+
+    public static final int TYPE = 0x0E;
+
+    public GetHostFirmwareRequest() {
+        setTagged(false);
+        setAddressable(true);
+        setResponseRequired(true);
+    }
+
+    @Override
+    public int packetType() {
+        return TYPE;
+    }
+
+    @Override
+    protected int packetLength() {
+        return 0;
+    }
+
+    @Override
+    protected void parsePacket(ByteBuffer bytes) {
+        // do nothing
+    }
+
+    @Override
+    protected ByteBuffer packetBytes() {
+        return ByteBuffer.allocate(0);
+    }
+
+    @Override
+    public int[] expectedResponses() {
+        return new int[] { StateHostFirmwareResponse.TYPE };
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetHostInfoRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetHostInfoRequest.java
new file mode 100644 (file)
index 0000000..a2f1b51
--- /dev/null
@@ -0,0 +1,55 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import java.nio.ByteBuffer;
+
+/**
+ * @author Tim Buckley - Initial contribution
+ * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
+ */
+public class GetHostInfoRequest extends Packet {
+
+    public static final int TYPE = 0x0C;
+
+    public GetHostInfoRequest() {
+        setTagged(false);
+        setAddressable(true);
+        setResponseRequired(true);
+    }
+
+    @Override
+    public int packetType() {
+        return TYPE;
+    }
+
+    @Override
+    protected int packetLength() {
+        return 0;
+    }
+
+    @Override
+    protected void parsePacket(ByteBuffer bytes) {
+        // do nothing
+    }
+
+    @Override
+    protected ByteBuffer packetBytes() {
+        return ByteBuffer.allocate(0);
+    }
+
+    @Override
+    public int[] expectedResponses() {
+        return new int[] { StateHostInfoResponse.TYPE };
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetInfoRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetInfoRequest.java
new file mode 100644 (file)
index 0000000..47212e8
--- /dev/null
@@ -0,0 +1,55 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import java.nio.ByteBuffer;
+
+/**
+ * @author Tim Buckley - Initial contribution
+ * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
+ */
+public class GetInfoRequest extends Packet {
+
+    public static final int TYPE = 0x22;
+
+    public GetInfoRequest() {
+        setTagged(false);
+        setAddressable(true);
+        setResponseRequired(true);
+    }
+
+    @Override
+    public int packetType() {
+        return TYPE;
+    }
+
+    @Override
+    protected int packetLength() {
+        return 0;
+    }
+
+    @Override
+    protected void parsePacket(ByteBuffer bytes) {
+        // do nothing
+    }
+
+    @Override
+    protected ByteBuffer packetBytes() {
+        return ByteBuffer.allocate(0);
+    }
+
+    @Override
+    public int[] expectedResponses() {
+        return new int[] { StateInfoResponse.TYPE };
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetLabelRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetLabelRequest.java
new file mode 100644 (file)
index 0000000..681ac98
--- /dev/null
@@ -0,0 +1,55 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import java.nio.ByteBuffer;
+
+/**
+ * @author Tim Buckley - Initial contribution
+ * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
+ */
+public class GetLabelRequest extends Packet {
+
+    public static final int TYPE = 0x17;
+
+    public GetLabelRequest() {
+        setTagged(false);
+        setAddressable(true);
+        setResponseRequired(true);
+    }
+
+    @Override
+    public int packetType() {
+        return TYPE;
+    }
+
+    @Override
+    protected int packetLength() {
+        return 0;
+    }
+
+    @Override
+    protected void parsePacket(ByteBuffer bytes) {
+        // do nothing
+    }
+
+    @Override
+    protected ByteBuffer packetBytes() {
+        return ByteBuffer.allocate(0);
+    }
+
+    @Override
+    public int[] expectedResponses() {
+        return new int[] { StateLabelResponse.TYPE };
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetLightInfraredRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetLightInfraredRequest.java
new file mode 100644 (file)
index 0000000..f4b2ce1
--- /dev/null
@@ -0,0 +1,54 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import java.nio.ByteBuffer;
+
+/**
+ * @author Wouter Born - Initial contribution
+ */
+public class GetLightInfraredRequest extends Packet {
+
+    public static final int TYPE = 0x78;
+
+    public GetLightInfraredRequest() {
+        setTagged(false);
+        setAddressable(true);
+        setResponseRequired(true);
+    }
+
+    @Override
+    public int packetType() {
+        return TYPE;
+    }
+
+    @Override
+    protected int packetLength() {
+        return 0;
+    }
+
+    @Override
+    protected void parsePacket(ByteBuffer bytes) {
+        // do nothing
+    }
+
+    @Override
+    protected ByteBuffer packetBytes() {
+        return ByteBuffer.allocate(0);
+    }
+
+    @Override
+    public int[] expectedResponses() {
+        return new int[] { StateLightInfraredResponse.TYPE };
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetLightPowerRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetLightPowerRequest.java
new file mode 100644 (file)
index 0000000..2fe6936
--- /dev/null
@@ -0,0 +1,55 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import java.nio.ByteBuffer;
+
+/**
+ * @author Tim Buckley - Initial contribution
+ * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
+ */
+public class GetLightPowerRequest extends Packet {
+
+    public static final int TYPE = 0x74;
+
+    public GetLightPowerRequest() {
+        setTagged(false);
+        setAddressable(true);
+        setResponseRequired(true);
+    }
+
+    @Override
+    public int packetType() {
+        return TYPE;
+    }
+
+    @Override
+    protected int packetLength() {
+        return 0;
+    }
+
+    @Override
+    protected void parsePacket(ByteBuffer bytes) {
+        // do nothing
+    }
+
+    @Override
+    protected ByteBuffer packetBytes() {
+        return ByteBuffer.allocate(0);
+    }
+
+    @Override
+    public int[] expectedResponses() {
+        return new int[] { StateLightPowerResponse.TYPE };
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetLocationRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetLocationRequest.java
new file mode 100644 (file)
index 0000000..af75939
--- /dev/null
@@ -0,0 +1,55 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import java.nio.ByteBuffer;
+
+/**
+ * @author Tim Buckley - Initial contribution
+ * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
+ */
+public class GetLocationRequest extends Packet {
+
+    public static final int TYPE = 0x30;
+
+    public GetLocationRequest() {
+        setTagged(false);
+        setAddressable(true);
+        setResponseRequired(true);
+    }
+
+    @Override
+    public int packetType() {
+        return TYPE;
+    }
+
+    @Override
+    protected int packetLength() {
+        return 0;
+    }
+
+    @Override
+    protected void parsePacket(ByteBuffer bytes) {
+        // do nothing
+    }
+
+    @Override
+    protected ByteBuffer packetBytes() {
+        return ByteBuffer.allocate(0);
+    }
+
+    @Override
+    public int[] expectedResponses() {
+        return new int[] { StateLocationResponse.TYPE };
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetPowerRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetPowerRequest.java
new file mode 100644 (file)
index 0000000..2b9bfdd
--- /dev/null
@@ -0,0 +1,55 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import java.nio.ByteBuffer;
+
+/**
+ * @author Tim Buckley - Initial contribution
+ * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
+ */
+public class GetPowerRequest extends Packet {
+
+    public static final int TYPE = 0x14;
+
+    public GetPowerRequest() {
+        setTagged(false);
+        setAddressable(true);
+        setResponseRequired(true);
+    }
+
+    @Override
+    public int packetType() {
+        return TYPE;
+    }
+
+    @Override
+    protected int packetLength() {
+        return 0;
+    }
+
+    @Override
+    protected void parsePacket(ByteBuffer bytes) {
+        // do nothing
+    }
+
+    @Override
+    protected ByteBuffer packetBytes() {
+        return ByteBuffer.allocate(0);
+    }
+
+    @Override
+    public int[] expectedResponses() {
+        return new int[] { StatePowerResponse.TYPE };
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetRequest.java
new file mode 100644 (file)
index 0000000..ab64dc6
--- /dev/null
@@ -0,0 +1,55 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import java.nio.ByteBuffer;
+
+/**
+ * @author Tim Buckley - Initial contribution
+ * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
+ */
+public class GetRequest extends Packet {
+
+    public static final int TYPE = 0x65;
+
+    public GetRequest() {
+        setTagged(false);
+        setAddressable(true);
+        setResponseRequired(true);
+    }
+
+    @Override
+    public int packetType() {
+        return TYPE;
+    }
+
+    @Override
+    protected int packetLength() {
+        return 0;
+    }
+
+    @Override
+    protected void parsePacket(ByteBuffer bytes) {
+        // do nothing
+    }
+
+    @Override
+    protected ByteBuffer packetBytes() {
+        return ByteBuffer.allocate(0);
+    }
+
+    @Override
+    public int[] expectedResponses() {
+        return new int[] { StateResponse.TYPE };
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetServiceRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetServiceRequest.java
new file mode 100644 (file)
index 0000000..b0b8d74
--- /dev/null
@@ -0,0 +1,54 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import java.nio.ByteBuffer;
+
+/**
+ * @author Tim Buckley - Initial contribution
+ * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
+ */
+public class GetServiceRequest extends Packet {
+
+    public static final int TYPE = 0x02;
+
+    public GetServiceRequest() {
+        setTagged(true);
+        setAddressable(true);
+    }
+
+    @Override
+    public int packetLength() {
+        return 0;
+    }
+
+    @Override
+    public int packetType() {
+        return TYPE;
+    }
+
+    @Override
+    protected void parsePacket(ByteBuffer bytes) {
+        // empty
+    }
+
+    @Override
+    protected ByteBuffer packetBytes() {
+        return ByteBuffer.allocate(0);
+    }
+
+    @Override
+    public int[] expectedResponses() {
+        return new int[] { StateServiceResponse.TYPE };
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetTagLabelsRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetTagLabelsRequest.java
new file mode 100644 (file)
index 0000000..c3c313e
--- /dev/null
@@ -0,0 +1,67 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import java.nio.ByteBuffer;
+
+import org.openhab.binding.lifx.internal.fields.Field;
+import org.openhab.binding.lifx.internal.fields.UInt64Field;
+
+/**
+ * @author Tim Buckley - Initial contribution
+ * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
+ */
+public class GetTagLabelsRequest extends Packet {
+
+    public static final int TYPE = 0x1D;
+
+    public static final Field<Long> FIELD_TAGS = new UInt64Field();
+
+    private long tags;
+
+    public long getTags() {
+        return tags;
+    }
+
+    public GetTagLabelsRequest() {
+    }
+
+    public GetTagLabelsRequest(long tags) {
+        this.tags = tags;
+    }
+
+    @Override
+    public int packetType() {
+        return TYPE;
+    }
+
+    @Override
+    protected int packetLength() {
+        return 8;
+    }
+
+    @Override
+    protected void parsePacket(ByteBuffer bytes) {
+        tags = FIELD_TAGS.value(bytes);
+    }
+
+    @Override
+    protected ByteBuffer packetBytes() {
+        return ByteBuffer.allocate(packetLength()).put(FIELD_TAGS.bytes(tags));
+    }
+
+    @Override
+    public int[] expectedResponses() {
+        return new int[] { TagLabelsResponse.TYPE };
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetTagsRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetTagsRequest.java
new file mode 100644 (file)
index 0000000..c0570cc
--- /dev/null
@@ -0,0 +1,49 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import java.nio.ByteBuffer;
+
+/**
+ * @author Tim Buckley - Initial contribution
+ * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
+ */
+public class GetTagsRequest extends Packet {
+
+    public static final int TYPE = 0x1A;
+
+    @Override
+    public int packetType() {
+        return TYPE;
+    }
+
+    @Override
+    protected int packetLength() {
+        return 0;
+    }
+
+    @Override
+    protected void parsePacket(ByteBuffer bytes) {
+        // do nothing
+    }
+
+    @Override
+    protected ByteBuffer packetBytes() {
+        return ByteBuffer.allocate(0);
+    }
+
+    @Override
+    public int[] expectedResponses() {
+        return new int[] { TagsResponse.TYPE };
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetTileEffectRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetTileEffectRequest.java
new file mode 100644 (file)
index 0000000..fde9dcc
--- /dev/null
@@ -0,0 +1,56 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import java.nio.ByteBuffer;
+
+/**
+ * Implementation of GetTileEffect packet
+ *
+ * @author Pawel Pieczul - Initial contribution
+ */
+public class GetTileEffectRequest extends Packet {
+
+    public static final int TYPE = 0x2CE;
+
+    public GetTileEffectRequest() {
+        setTagged(false);
+        setAddressable(true);
+        setResponseRequired(true);
+    }
+
+    @Override
+    public int packetType() {
+        return TYPE;
+    }
+
+    @Override
+    protected int packetLength() {
+        return 0;
+    }
+
+    @Override
+    protected void parsePacket(ByteBuffer bytes) {
+        // do nothing
+    }
+
+    @Override
+    protected ByteBuffer packetBytes() {
+        return ByteBuffer.allocate(0);
+    }
+
+    @Override
+    public int[] expectedResponses() {
+        return new int[] { StateTileEffectResponse.TYPE };
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetVersionRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetVersionRequest.java
new file mode 100644 (file)
index 0000000..a278480
--- /dev/null
@@ -0,0 +1,55 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import java.nio.ByteBuffer;
+
+/**
+ * @author Tim Buckley - Initial contribution
+ * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
+ */
+public class GetVersionRequest extends Packet {
+
+    public static final int TYPE = 0x20;
+
+    public GetVersionRequest() {
+        setTagged(false);
+        setAddressable(true);
+        setResponseRequired(true);
+    }
+
+    @Override
+    public int packetType() {
+        return TYPE;
+    }
+
+    @Override
+    protected int packetLength() {
+        return 0;
+    }
+
+    @Override
+    protected void parsePacket(ByteBuffer bytes) {
+        // do nothing
+    }
+
+    @Override
+    protected ByteBuffer packetBytes() {
+        return ByteBuffer.allocate(0);
+    }
+
+    @Override
+    public int[] expectedResponses() {
+        return new int[] { StateVersionResponse.TYPE };
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetWifiFirmwareRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetWifiFirmwareRequest.java
new file mode 100644 (file)
index 0000000..e08771d
--- /dev/null
@@ -0,0 +1,55 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import java.nio.ByteBuffer;
+
+/**
+ * @author Tim Buckley - Initial contribution
+ * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
+ */
+public class GetWifiFirmwareRequest extends Packet {
+
+    public static final int TYPE = 0x12;
+
+    public GetWifiFirmwareRequest() {
+        setTagged(false);
+        setAddressable(true);
+        setResponseRequired(true);
+    }
+
+    @Override
+    public int packetType() {
+        return TYPE;
+    }
+
+    @Override
+    protected int packetLength() {
+        return 0;
+    }
+
+    @Override
+    protected void parsePacket(ByteBuffer bytes) {
+        // do nothing
+    }
+
+    @Override
+    protected ByteBuffer packetBytes() {
+        return ByteBuffer.allocate(0);
+    }
+
+    @Override
+    public int[] expectedResponses() {
+        return new int[] { StateWifiFirmwareResponse.TYPE };
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetWifiInfoRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/GetWifiInfoRequest.java
new file mode 100644 (file)
index 0000000..3b97981
--- /dev/null
@@ -0,0 +1,55 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import java.nio.ByteBuffer;
+
+/**
+ * @author Tim Buckley - Initial contribution
+ * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
+ */
+public class GetWifiInfoRequest extends Packet {
+
+    public static final int TYPE = 0x10;
+
+    public GetWifiInfoRequest() {
+        setTagged(false);
+        setAddressable(true);
+        setResponseRequired(true);
+    }
+
+    @Override
+    public int packetType() {
+        return TYPE;
+    }
+
+    @Override
+    protected int packetLength() {
+        return 0;
+    }
+
+    @Override
+    protected void parsePacket(ByteBuffer bytes) {
+        // do nothing
+    }
+
+    @Override
+    protected ByteBuffer packetBytes() {
+        return ByteBuffer.allocate(0);
+    }
+
+    @Override
+    public int[] expectedResponses() {
+        return new int[] { StateWifiInfoResponse.TYPE };
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/Packet.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/Packet.java
new file mode 100644 (file)
index 0000000..3b65afc
--- /dev/null
@@ -0,0 +1,397 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import java.nio.ByteBuffer;
+
+import org.openhab.binding.lifx.internal.fields.ByteField;
+import org.openhab.binding.lifx.internal.fields.Field;
+import org.openhab.binding.lifx.internal.fields.MACAddress;
+import org.openhab.binding.lifx.internal.fields.MACAddressField;
+import org.openhab.binding.lifx.internal.fields.UInt16Field;
+import org.openhab.binding.lifx.internal.fields.UInt32Field;
+import org.openhab.binding.lifx.internal.fields.UInt8Field;
+
+/**
+ * Represents an abstract packet, providing conversion functionality to and from
+ * {@link ByteBuffer}s for common packet (preamble) fields. Subtypes of this
+ * class can provide conversion functionality for specialized fields.
+ *
+ * <p>
+ * Defining new packet types essentially involves extending this class,
+ * defining the fields and implementing {@link #packetType()},
+ * {@link #packetLength()}, and {@link #packetBytes()}. By convention, packet
+ * type should be stored in a {@code public static final int PACKET_TYPE} field
+ * in each subtype, followed by a listing of fields contained in the packet.
+ * Field definitions should remain accessible to outside classes in the event
+ * they need to worked with directly elsewhere.
+ *
+ * @author Tim Buckley - Initial contribution
+ * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
+ */
+public abstract class Packet {
+
+    public static final Field<Integer> FIELD_SIZE = new UInt16Field().little();
+    public static final Field<Integer> FIELD_PROTOCOL = new UInt16Field().little();
+    public static final Field<Long> FIELD_SOURCE = new UInt32Field().little();
+    public static final Field<MACAddress> FIELD_TARGET = new MACAddressField();
+    public static final Field<ByteBuffer> FIELD_RESERVED_1 = new ByteField(6);
+    public static final Field<Integer> FIELD_ACK = new UInt8Field();
+    public static final Field<Integer> FIELD_SEQUENCE = new UInt8Field().little();
+    public static final Field<ByteBuffer> FIELD_RESERVED_2 = new ByteField(8);
+    public static final Field<Integer> FIELD_PACKET_TYPE = new UInt16Field().little();
+    public static final Field<ByteBuffer> FIELD_RESERVED_3 = new ByteField(2);
+
+    /**
+     * An ordered array of all fields contained in the common packet preamble.
+     */
+    public static final Field<?>[] PREAMBLE_FIELDS = new Field[] { FIELD_SIZE, FIELD_PROTOCOL, FIELD_SOURCE,
+            FIELD_TARGET, FIELD_RESERVED_1, FIELD_ACK, FIELD_SEQUENCE, FIELD_RESERVED_2, FIELD_PACKET_TYPE,
+            FIELD_RESERVED_3 };
+
+    protected int size;
+    protected int protocol;
+    protected long source;
+    protected MACAddress target;
+    protected ByteBuffer reserved1;
+    protected int ackbyte;
+    protected int sequence;
+    protected ByteBuffer reserved2;
+    protected int packetType;
+    protected ByteBuffer reserved3;
+
+    protected long timeStamp;
+
+    public int getSize() {
+        return size;
+    }
+
+    public void setSize(int size) {
+        this.size = size;
+    }
+
+    public int getOrigin() {
+        return (protocol & 0xC000) >> 14;
+    }
+
+    public void setOrigin(int origin) {
+        protocol = (protocol & ~(1 << 14)) | (origin << 14);
+    }
+
+    public boolean getTagged() {
+        return (protocol & 0x2000) >> 13 == 1 ? true : false;
+    }
+
+    public void setTagged(boolean flag) {
+        protocol = (protocol & ~(1 << 13)) | ((flag ? 1 : 0) << 13);
+    }
+
+    public boolean getAddressable() {
+        return (protocol & 0x1000) >> 12 == 1 ? true : false;
+    }
+
+    public void setAddressable(boolean flag) {
+        this.protocol = (protocol & ~(1 << 12)) | ((flag ? 1 : 0) << 12);
+    }
+
+    public int getProtocol() {
+        return protocol & 0x0FFF;
+    }
+
+    public void setProtocol(int protocol) {
+        this.protocol = this.protocol | protocol;
+    }
+
+    public long getSource() {
+        return source;
+    }
+
+    public void setSource(long source) {
+        this.source = source;
+    }
+
+    public MACAddress getTarget() {
+        return target;
+    }
+
+    public void setTarget(MACAddress lightAddress) {
+        this.target = lightAddress != null ? lightAddress : MACAddress.BROADCAST_ADDRESS;
+    }
+
+    public ByteBuffer getReserved1() {
+        return reserved1;
+    }
+
+    public void setReserved1(ByteBuffer reserved2) {
+        this.reserved1 = reserved2;
+    }
+
+    public boolean getAckRequired() {
+        return (ackbyte & 0x02) >> 1 == 1 ? true : false;
+    }
+
+    public void setAckRequired(boolean flag) {
+        this.ackbyte = (ackbyte & ~(1 << 1)) | ((flag ? 1 : 0) << 1);
+    }
+
+    public boolean getResponseRequired() {
+        return (ackbyte & 0x01) >> 0 == 1 ? true : false;
+    }
+
+    public void setResponseRequired(boolean flag) {
+        this.ackbyte = (ackbyte & ~(1 << 0)) | ((flag ? 1 : 0) << 0);
+    }
+
+    public int getSequence() {
+        return sequence;
+    }
+
+    public void setSequence(int sequence) {
+        if (0 <= sequence && sequence < 256) {
+            this.sequence = sequence;
+        } else {
+            throw new IllegalArgumentException("Sequence number '" + sequence + "' is not in range [0, 255]");
+        }
+    }
+
+    public ByteBuffer getReserved2() {
+        return reserved2;
+    }
+
+    public void setReserved2(ByteBuffer reserved3) {
+        this.reserved2 = reserved3;
+    }
+
+    public int getPacketType() {
+        return packetType;
+    }
+
+    public void setPacketType(int packetType) {
+        this.packetType = packetType;
+    }
+
+    public ByteBuffer getReserved3() {
+        return reserved3;
+    }
+
+    public void setReserved3(ByteBuffer reserved4) {
+        this.reserved3 = reserved4;
+    }
+
+    public long getTimeStamp() {
+        return timeStamp;
+    }
+
+    /**
+     * Creates an empty packet, setting some default values via
+     * {@link #preambleDefaults()}.
+     */
+    public Packet() {
+        preambleDefaults();
+        timeStamp = System.currentTimeMillis();
+    }
+
+    /**
+     * Parses, in order, the defined preamble fields, storing collected values.
+     * The buffer's position will be left at the end of the parsed fields and
+     * should be equal to the value returned by {@link #preambleLength()}.
+     *
+     * @param bytes the buffer to read from.
+     */
+    protected void parsePreamble(ByteBuffer bytes) {
+        size = FIELD_SIZE.value(bytes);
+        protocol = FIELD_PROTOCOL.value(bytes);
+        source = FIELD_SOURCE.value(bytes);
+        target = FIELD_TARGET.value(bytes);
+        reserved1 = FIELD_RESERVED_1.value(bytes);
+        ackbyte = FIELD_ACK.value(bytes);
+        sequence = FIELD_SEQUENCE.value(bytes);
+        reserved2 = FIELD_RESERVED_2.value(bytes);
+        packetType = FIELD_PACKET_TYPE.value(bytes);
+        reserved3 = FIELD_RESERVED_3.value(bytes);
+    }
+
+    /**
+     * Calculates the length of the packet header, defined as the sum of the
+     * lengths of all defined fields (see {@link #PREAMBLE_FIELDS}).
+     *
+     * @return the sum of the length of preamble fields
+     */
+    protected int preambleLength() {
+        int sum = 0;
+
+        for (Field<?> f : PREAMBLE_FIELDS) {
+            sum += f.getLength();
+        }
+
+        return sum;
+    }
+
+    /**
+     * Returns a new {@code ByteBuffer} containing the encoded preamble. Note
+     * that the returned buffer will have its position set at the end of the
+     * buffer and will need to have {@link ByteBuffer#rewind()} called before
+     * use.
+     *
+     * <p>
+     * The length of the buffer is the sum of the lengths of the defined
+     * preamble fields (see {@link #PREAMBLE_FIELDS} for an ordered list), which
+     * may also be accessed via {@link #preambleLength()}.
+     *
+     * <p>
+     * Certain fields are set to default values based on other class methods.
+     * For example, the size and packet type fields will be set to the values
+     * returned from {@link #length()} and {@link #packetType()}, respectively.
+     * Other defaults (such as the protocol, light address, site, and timestamp)
+     * may be specified either by directly setting the relevant protected
+     * variables or by overriding {@link #preambleDefaults()}.
+     *
+     * @return a new buffer containing the encoded preamble
+     */
+    protected ByteBuffer preambleBytes() {
+        return ByteBuffer.allocate(preambleLength()).put(FIELD_SIZE.bytes(length())).put(FIELD_PROTOCOL.bytes(protocol))
+                .put(FIELD_SOURCE.bytes(source)).put(FIELD_TARGET.bytes(target))
+                .put(ByteBuffer.allocate(FIELD_RESERVED_1.getLength())) // empty
+                .put(FIELD_ACK.bytes(ackbyte)).put(FIELD_SEQUENCE.bytes(sequence))
+                .put(ByteBuffer.allocate(FIELD_RESERVED_2.getLength())) // empty
+                .put(FIELD_PACKET_TYPE.bytes(packetType())).put(ByteBuffer.allocate(FIELD_RESERVED_3.getLength())); // empty
+    }
+
+    /**
+     * Sets default preamble values. If needed, subclasses may override these
+     * values by specifically overriding this method, or by setting individual
+     * values within the constructor, as this method is called automatically
+     * during initialization.
+     */
+    protected void preambleDefaults() {
+        size = 0;
+        protocol = 1024;
+        target = new MACAddress();
+        sequence = 0;
+        packetType = packetType();
+    }
+
+    /**
+     * Returns the packet type. Note that this value is technically distinct
+     * from {@code getPacketType()} in that it returns the packet type the
+     * current {@code Packet} subtype is designed to parse, while
+     * {@code getPacketType()} returns the actual {@code packetType} field of
+     * a parsed packet. However, these values should always match.
+     *
+     * @return the packet type intended to be handled by this Packet subtype
+     */
+    public abstract int packetType();
+
+    /**
+     * Returns the length of the payload specific to this packet subtype. The
+     * length of the preamble is specifically excluded.
+     *
+     * @return the length of this specialized packet payload
+     */
+    protected abstract int packetLength();
+
+    /**
+     * Parses the given {@link ByteBuffer} into class fields. Subtypes may
+     * implement {@link #parsePacket(ByteBuffer)} to parse additional fields;
+     * the preamble by default is always parsed.
+     *
+     * @param bytes the buffer to extract data from
+     */
+    public void parse(ByteBuffer bytes) {
+        bytes.rewind();
+        parsePreamble(bytes);
+        parsePacket(bytes);
+    }
+
+    /**
+     * Extracts data from the given {@link ByteBuffer} into fields specific to
+     * this packet subtype. The preamble will already have been parsed; as such,
+     * the buffer will be positioned at the end of the preamble. If needed,
+     * {@link #preambleLength()} may be used to restore the position of the
+     * buffer.
+     *
+     * @param bytes the raw bytes to parse
+     */
+    protected abstract void parsePacket(ByteBuffer bytes);
+
+    /**
+     * Returns a {@link ByteBuffer} containing the full payload for this packet,
+     * including the populated preamble and any specialized packet payload. The
+     * returned buffer will be at position zero.
+     *
+     * @return the full packet payload
+     */
+    public ByteBuffer bytes() {
+        ByteBuffer preamble = preambleBytes();
+        preamble.rewind();
+
+        ByteBuffer packet = packetBytes();
+        packet.rewind();
+
+        ByteBuffer ret = ByteBuffer.allocate(length()).put(preamble).put(packet);
+        ret.rewind();
+
+        return ret;
+    }
+
+    /**
+     * Returns a {@link ByteBuffer} containing the payload for this packet. Its
+     * length must match the value of {@link #packetLength()}. This specifically
+     * excludes preamble fields and should contain only data specific to the
+     * packet subtype.
+     * <p>
+     * Note that returned ByteBuffers will have {@link ByteBuffer#rewind()}
+     * called automatically before they are appended to the final packet
+     * buffer.
+     *
+     * @return the packet payload
+     */
+    protected abstract ByteBuffer packetBytes();
+
+    /**
+     * Gets the total length of this packet, in bytes. Specifically, this method
+     * is the sum of the preamble ({@link #preambleLength()}) and the payload
+     * length ({@link #packetLength()}); subtypes should override methods for
+     * those values if desired.
+     *
+     * @return the total length of this packet
+     */
+    public int length() {
+        return preambleLength() + packetLength();
+    }
+
+    /**
+     * Returns a list of expected response packet types. An empty array means
+     * no responses are expected (suitable for response packet definitions),
+     *
+     * @return a list of expected responses
+     */
+    public abstract int[] expectedResponses();
+
+    public boolean isExpectedResponse(int type) {
+        for (int a : expectedResponses()) {
+            if (a == type) {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+    public boolean isFulfilled(Packet somePacket) {
+        if (isExpectedResponse(somePacket.getPacketType())) {
+            return true;
+        }
+        return false;
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/PacketFactory.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/PacketFactory.java
new file mode 100644 (file)
index 0000000..ba9ea39
--- /dev/null
@@ -0,0 +1,157 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
+
+/**
+ * A static factory for registering packet types that may be received and
+ * dispatched to client cod * request types, like {@code PowerStateRequest}) or types received only via UDP
+ * e. Packet handlers (used to construct actual packet
+ * instances) may be retrieved via their packet type.
+ *
+ * @author Tim Buckley - Initial contribution
+ * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
+ * @author Wouter Born - Support LIFX 2016 product line-up and infrared functionality
+ */
+@NonNullByDefault
+public class PacketFactory {
+
+    private static @Nullable PacketFactory instance;
+
+    public static synchronized PacketFactory getInstance() {
+        PacketFactory result = instance;
+        if (result == null) {
+            result = new PacketFactory();
+            instance = result;
+        }
+        return result;
+    }
+
+    private final Map<Integer, PacketHandler<?>> handlers;
+
+    private PacketFactory() {
+        handlers = new HashMap<>();
+
+        register(AcknowledgementResponse.class);
+        register(EchoRequestResponse.class);
+        register(GetColorZonesRequest.class);
+        register(GetEchoRequest.class);
+        register(GetGroupRequest.class);
+        register(GetHostFirmwareRequest.class);
+        register(GetHostInfoRequest.class);
+        register(GetInfoRequest.class);
+        register(GetLabelRequest.class);
+        register(GetLightInfraredRequest.class);
+        register(GetLightPowerRequest.class);
+        register(GetLocationRequest.class);
+        register(GetPowerRequest.class);
+        register(GetRequest.class);
+        register(GetServiceRequest.class);
+        register(GetTagLabelsRequest.class);
+        register(GetTagsRequest.class);
+        register(GetTileEffectRequest.class);
+        register(GetVersionRequest.class);
+        register(GetWifiFirmwareRequest.class);
+        register(GetWifiInfoRequest.class);
+        register(SetColorRequest.class);
+        register(SetColorZonesRequest.class);
+        register(SetDimAbsoluteRequest.class);
+        register(SetLabelRequest.class);
+        register(SetLightInfraredRequest.class);
+        register(SetLightPowerRequest.class);
+        register(SetPowerRequest.class);
+        register(SetTagsRequest.class);
+        register(StateGroupResponse.class);
+        register(StateHostFirmwareResponse.class);
+        register(StateHostInfoResponse.class);
+        register(StateInfoResponse.class);
+        register(StateLabelResponse.class);
+        register(StateLightInfraredResponse.class);
+        register(StateLightPowerResponse.class);
+        register(StateLocationResponse.class);
+        register(StateMultiZoneResponse.class);
+        register(StatePowerResponse.class);
+        register(StateResponse.class);
+        register(StateServiceResponse.class);
+        register(StateTileEffectResponse.class);
+        register(StateVersionResponse.class);
+        register(StateWifiFirmwareResponse.class);
+        register(StateWifiInfoResponse.class);
+        register(StateZoneResponse.class);
+        register(TagLabelsResponse.class);
+        register(TagsResponse.class);
+    }
+
+    /**
+     * Registers a packet handler for the given packet type.
+     *
+     * @param type the type to register
+     * @param handler the packet handler to associate with the type
+     */
+    public final void register(int type, PacketHandler<?> handler) {
+        handlers.put(type, handler);
+    }
+
+    /**
+     * Registers a new generic packet handler for the given packet class. The
+     * packet class must meet the criteria for {@link GenericHandler};
+     * specifically, it must have an no-argument constructor and require no
+     * parsing logic outside of an invocation of
+     * {@link Packet#parse(java.nio.ByteBuffer)}.
+     *
+     * @param type the type of the packet to register
+     * @param clazz the class of the packet to register
+     */
+    public final void register(int type, Class<? extends Packet> clazz) {
+        handlers.put(type, new GenericHandler<>(clazz));
+    }
+
+    /**
+     * Registers a generic packet type. All requirements of
+     * {@link GenericHandler} must met; specifically, classes must have a
+     * no-args constructor and require no additional parsing logic.
+     * Additionally, a public static integer {@code TYPE} field must be defined.
+     *
+     * @param <T> the packet type to register
+     * @param clazz the packet class to register
+     */
+    public final <T extends Packet> void register(Class<T> clazz) {
+        GenericHandler<T> handler = new GenericHandler<>(clazz);
+
+        if (!handler.isTypeFound()) {
+            throw new IllegalArgumentException("Unable to register generic packet with no TYPE field.");
+        }
+
+        handlers.put(handler.getType(), handler);
+    }
+
+    /**
+     * Gets a registered handler for the given packet type, if any exists. If
+     * no matching handler can be found, {@code null} is returned.
+     *
+     * @param packetType the packet type of the handler to retrieve
+     * @return a packet handler, or null
+     */
+    public @Nullable PacketHandler<?> getHandler(int packetType) {
+        return handlers.get(packetType);
+    }
+
+    public static @Nullable PacketHandler<?> createHandler(int packetType) {
+        return getInstance().getHandler(packetType);
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/PacketHandler.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/PacketHandler.java
new file mode 100644 (file)
index 0000000..a93b475
--- /dev/null
@@ -0,0 +1,40 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import java.nio.ByteBuffer;
+
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
+/**
+ * A packet handler responsible for converting a ByteBuffer into a Packet
+ * instance.
+ *
+ * @param <T> the generic packet type
+ *
+ * @author Tim Buckley - Initial contribution
+ * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
+ */
+@NonNullByDefault
+public interface PacketHandler<T extends Packet> {
+
+    /**
+     * Creates a packet from the given buffer.
+     *
+     * @param buf the buffer used for creating the packet
+     * @return the packet created from the buffer
+     * @throws IllegalArgumentException when an empty packet could not be created or the data in the buffer
+     *             could not be parsed
+     */
+    public abstract T handle(ByteBuffer buf);
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/PowerState.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/PowerState.java
new file mode 100644 (file)
index 0000000..f12ba58
--- /dev/null
@@ -0,0 +1,57 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import org.openhab.core.library.types.OnOffType;
+
+/**
+ * Represents light power states (on or off).
+ *
+ * @author Tim Buckley - Initial contribution
+ * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
+ * @author Wouter Born - Added OnOffType conversion methods
+ */
+public enum PowerState {
+
+    ON(0xFFFF),
+    OFF(0x0000);
+
+    private final int value;
+
+    private PowerState(int value) {
+        this.value = value;
+    }
+
+    /**
+     * Gets the integer value of this power state.
+     *
+     * @return the integer value
+     */
+    public int getValue() {
+        return value;
+    }
+
+    public static PowerState fromValue(int value) {
+        // a response can have a power level between 0 and 65535 when the light
+        // has just been switched ON or OFF
+        return value == OFF.value ? OFF : ON;
+    }
+
+    public static PowerState fromOnOffType(OnOffType onOff) {
+        return onOff == OnOffType.ON ? ON : OFF;
+    }
+
+    public OnOffType toOnOffType() {
+        return this == ON ? OnOffType.ON : OnOffType.OFF;
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/SetColorRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/SetColorRequest.java
new file mode 100644 (file)
index 0000000..2ebe176
--- /dev/null
@@ -0,0 +1,92 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import java.nio.ByteBuffer;
+
+import org.openhab.binding.lifx.internal.fields.ByteField;
+import org.openhab.binding.lifx.internal.fields.Field;
+import org.openhab.binding.lifx.internal.fields.HSBK;
+import org.openhab.binding.lifx.internal.fields.HSBKField;
+import org.openhab.binding.lifx.internal.fields.UInt32Field;
+
+/**
+ * @author Tim Buckley - Initial contribution
+ * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
+ */
+public class SetColorRequest extends Packet {
+
+    public static final int TYPE = 0x66;
+
+    public static final Field<ByteBuffer> FIELD_STREAM = new ByteField(1);
+    public static final HSBKField FIELD_COLOR = new HSBKField();
+    public static final Field<Long> FIELD_FADE_TIME = new UInt32Field().little();
+
+    private ByteBuffer stream;
+
+    private HSBK color;
+    private long fadeTime;
+
+    public ByteBuffer getStream() {
+        return stream;
+    }
+
+    public HSBK getColor() {
+        return color;
+    }
+
+    public long getFadeTime() {
+        return fadeTime;
+    }
+
+    public SetColorRequest() {
+        stream = ByteBuffer.allocate(1);
+        setTagged(false);
+        setAddressable(true);
+        setResponseRequired(true);
+    }
+
+    public SetColorRequest(HSBK color, long fadeTime) {
+        this();
+        this.color = color;
+        this.fadeTime = fadeTime;
+    }
+
+    @Override
+    public int packetType() {
+        return TYPE;
+    }
+
+    @Override
+    protected int packetLength() {
+        return 13;
+    }
+
+    @Override
+    protected void parsePacket(ByteBuffer bytes) {
+        stream = FIELD_STREAM.value(bytes);
+        color = FIELD_COLOR.value(bytes);
+        fadeTime = FIELD_FADE_TIME.value(bytes);
+    }
+
+    @Override
+    protected ByteBuffer packetBytes() {
+        return ByteBuffer.allocate(packetLength()).put(FIELD_STREAM.bytes(stream)).put(FIELD_COLOR.bytes(color))
+                .put(FIELD_FADE_TIME.bytes(fadeTime));
+    }
+
+    @Override
+    public int[] expectedResponses() {
+        return new int[] { StateResponse.TYPE };
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/SetColorZonesRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/SetColorZonesRequest.java
new file mode 100644 (file)
index 0000000..5e40d1b
--- /dev/null
@@ -0,0 +1,125 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import static org.openhab.binding.lifx.internal.LifxBindingConstants.*;
+
+import java.nio.ByteBuffer;
+
+import org.openhab.binding.lifx.internal.fields.Field;
+import org.openhab.binding.lifx.internal.fields.HSBK;
+import org.openhab.binding.lifx.internal.fields.HSBKField;
+import org.openhab.binding.lifx.internal.fields.UInt32Field;
+import org.openhab.binding.lifx.internal.fields.UInt8Field;
+
+/**
+ * @author Wouter Born - Initial contribution
+ */
+public class SetColorZonesRequest extends Packet {
+
+    public static final int TYPE = 0x1F5;
+
+    public static final Field<Integer> FIELD_START_INDEX = new UInt8Field();
+    public static final Field<Integer> FIELD_END_INDEX = new UInt8Field();
+    public static final HSBKField FIELD_COLOR = new HSBKField();
+    public static final Field<Long> FIELD_FADE_TIME = new UInt32Field().little();
+    public static final Field<Integer> FIELD_APPLY = new UInt8Field();
+
+    private int startIndex = MIN_ZONE_INDEX;
+    private int endIndex = MAX_ZONE_INDEX;
+    private HSBK color;
+    private long fadeTime;
+    private ApplicationRequest apply;
+
+    public HSBK getColor() {
+        return color;
+    }
+
+    public int getHue() {
+        return color.getHue();
+    }
+
+    public int getSaturation() {
+        return color.getSaturation();
+    }
+
+    public int getBrightness() {
+        return color.getBrightness();
+    }
+
+    public int getKelvin() {
+        return color.getKelvin();
+    }
+
+    public long getFadeTime() {
+        return fadeTime;
+    }
+
+    public ApplicationRequest getApply() {
+        return apply;
+    }
+
+    public SetColorZonesRequest() {
+        setTagged(false);
+        setAddressable(true);
+        setResponseRequired(true);
+    }
+
+    public SetColorZonesRequest(HSBK color, long fadeTime, ApplicationRequest apply) {
+        this(MIN_ZONE_INDEX, MAX_ZONE_INDEX, color, fadeTime, apply);
+    }
+
+    public SetColorZonesRequest(int index, HSBK color, long fadeTime, ApplicationRequest apply) {
+        this(index, index, color, fadeTime, apply);
+    }
+
+    public SetColorZonesRequest(int startIndex, int endIndex, HSBK color, long fadeTime, ApplicationRequest apply) {
+        this();
+        this.startIndex = startIndex;
+        this.endIndex = endIndex;
+        this.color = color;
+        this.fadeTime = fadeTime;
+        this.apply = apply;
+    }
+
+    @Override
+    public int packetType() {
+        return TYPE;
+    }
+
+    @Override
+    protected int packetLength() {
+        return 15;
+    }
+
+    @Override
+    protected void parsePacket(ByteBuffer bytes) {
+        startIndex = FIELD_START_INDEX.value(bytes);
+        endIndex = FIELD_END_INDEX.value(bytes);
+        color = FIELD_COLOR.value(bytes);
+        fadeTime = FIELD_FADE_TIME.value(bytes);
+        apply = ApplicationRequest.fromValue(FIELD_APPLY.value(bytes));
+    }
+
+    @Override
+    protected ByteBuffer packetBytes() {
+        return ByteBuffer.allocate(packetLength()).put(FIELD_START_INDEX.bytes(startIndex))
+                .put(FIELD_END_INDEX.bytes(endIndex)).put(FIELD_COLOR.bytes(color)).put(FIELD_FADE_TIME.bytes(fadeTime))
+                .put(FIELD_APPLY.bytes(apply.getValue()));
+    }
+
+    @Override
+    public int[] expectedResponses() {
+        return new int[] {};
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/SetDimAbsoluteRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/SetDimAbsoluteRequest.java
new file mode 100644 (file)
index 0000000..ca92ded
--- /dev/null
@@ -0,0 +1,76 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import java.nio.ByteBuffer;
+
+import org.openhab.binding.lifx.internal.fields.Field;
+import org.openhab.binding.lifx.internal.fields.UInt16Field;
+import org.openhab.binding.lifx.internal.fields.UInt32Field;
+
+/**
+ * @author Tim Buckley - Initial contribution
+ * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
+ */
+public class SetDimAbsoluteRequest extends Packet {
+
+    public static final int TYPE = 0x68;
+
+    public static final Field<Integer> FIELD_DIM = new UInt16Field().little();
+    public static final Field<Long> FIELD_DURATION = new UInt32Field().little();
+
+    private int dim;
+    private long duration;
+
+    public int getDim() {
+        return dim;
+    }
+
+    public long getDuration() {
+        return duration;
+    }
+
+    public SetDimAbsoluteRequest() {
+    }
+
+    public SetDimAbsoluteRequest(int dim, long duration) {
+        this.dim = dim;
+        this.duration = duration;
+    }
+
+    @Override
+    public int packetType() {
+        return TYPE;
+    }
+
+    @Override
+    protected int packetLength() {
+        return 6;
+    }
+
+    @Override
+    protected void parsePacket(ByteBuffer bytes) {
+        dim = FIELD_DIM.value(bytes);
+        duration = FIELD_DURATION.value(bytes);
+    }
+
+    @Override
+    protected ByteBuffer packetBytes() {
+        return ByteBuffer.allocate(packetLength()).put(FIELD_DIM.bytes(dim)).put(FIELD_DURATION.bytes(duration));
+    }
+
+    @Override
+    public int[] expectedResponses() {
+        return new int[] {};
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/SetLabelRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/SetLabelRequest.java
new file mode 100644 (file)
index 0000000..ee11b74
--- /dev/null
@@ -0,0 +1,70 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import java.nio.ByteBuffer;
+
+import org.openhab.binding.lifx.internal.fields.Field;
+import org.openhab.binding.lifx.internal.fields.StringField;
+
+/**
+ * @author Tim Buckley - Initial contribution
+ * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
+ */
+public class SetLabelRequest extends Packet {
+
+    public static final int TYPE = 0x18;
+
+    public static final Field<String> FIELD_LABEL = new StringField(32).utf8();
+
+    private String label;
+
+    public SetLabelRequest() {
+        setTagged(false);
+        setAddressable(true);
+        setAckRequired(true);
+    }
+
+    public String getLabel() {
+        return label;
+    }
+
+    public void setLabel(String label) {
+        this.label = label;
+    }
+
+    @Override
+    public int packetType() {
+        return TYPE;
+    }
+
+    @Override
+    protected int packetLength() {
+        return 32;
+    }
+
+    @Override
+    protected void parsePacket(ByteBuffer bytes) {
+        label = FIELD_LABEL.value(bytes);
+    }
+
+    @Override
+    protected ByteBuffer packetBytes() {
+        return FIELD_LABEL.bytes(label);
+    }
+
+    @Override
+    public int[] expectedResponses() {
+        return new int[] {};
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/SetLightInfraredRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/SetLightInfraredRequest.java
new file mode 100644 (file)
index 0000000..1a0abda
--- /dev/null
@@ -0,0 +1,70 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import java.nio.ByteBuffer;
+
+import org.openhab.binding.lifx.internal.fields.Field;
+import org.openhab.binding.lifx.internal.fields.UInt16Field;
+
+/**
+ * @author Wouter Born - Initial contribution
+ */
+public class SetLightInfraredRequest extends Packet {
+
+    public static final int TYPE = 0x7A;
+
+    public static final Field<Integer> FIELD_STATE = new UInt16Field().little();
+
+    private int infrared;
+
+    public int getInfrared() {
+        return infrared;
+    }
+
+    public SetLightInfraredRequest() {
+        setTagged(false);
+        setAddressable(true);
+        setResponseRequired(true);
+    }
+
+    public SetLightInfraredRequest(int infrared) {
+        this();
+        this.infrared = infrared;
+    }
+
+    @Override
+    public int packetType() {
+        return TYPE;
+    }
+
+    @Override
+    protected int packetLength() {
+        return 2;
+    }
+
+    @Override
+    protected void parsePacket(ByteBuffer bytes) {
+        infrared = FIELD_STATE.value(bytes);
+    }
+
+    @Override
+    protected ByteBuffer packetBytes() {
+        return ByteBuffer.allocate(2).put(FIELD_STATE.bytes(infrared));
+    }
+
+    @Override
+    public int[] expectedResponses() {
+        return new int[] { StateLightInfraredResponse.TYPE };
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/SetLightPowerRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/SetLightPowerRequest.java
new file mode 100644 (file)
index 0000000..ecbfb7a
--- /dev/null
@@ -0,0 +1,89 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import java.nio.ByteBuffer;
+
+import org.openhab.binding.lifx.internal.fields.Field;
+import org.openhab.binding.lifx.internal.fields.UInt16Field;
+import org.openhab.binding.lifx.internal.fields.UInt32Field;
+
+/**
+ * @author Tim Buckley - Initial contribution
+ * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
+ */
+public class SetLightPowerRequest extends Packet {
+
+    public static final int TYPE = 0x75;
+
+    public static final Field<Integer> FIELD_STATE = new UInt16Field();
+    public static final Field<Long> FIELD_DURATION = new UInt32Field().little();
+
+    private PowerState state;
+    private long duration;
+
+    public PowerState getState() {
+        return state;
+    }
+
+    public long getDuration() {
+        return duration;
+    }
+
+    public void setDuration(long duration) {
+        this.duration = duration;
+    }
+
+    public SetLightPowerRequest() {
+        state = PowerState.OFF;
+        this.duration = 0;
+        setTagged(false);
+        setAddressable(true);
+        setResponseRequired(true);
+    }
+
+    public SetLightPowerRequest(PowerState state) {
+        this.state = state;
+        this.duration = 0;
+        setTagged(false);
+        setAddressable(true);
+        setResponseRequired(true);
+    }
+
+    @Override
+    public int packetType() {
+        return TYPE;
+    }
+
+    @Override
+    protected int packetLength() {
+        return 6;
+    }
+
+    @Override
+    protected void parsePacket(ByteBuffer bytes) {
+        state = PowerState.fromValue(FIELD_STATE.value(bytes));
+        duration = FIELD_DURATION.value(bytes);
+    }
+
+    @Override
+    protected ByteBuffer packetBytes() {
+        return ByteBuffer.allocate(packetLength()).put(FIELD_STATE.bytes(state.getValue()))
+                .put(FIELD_DURATION.bytes(duration));
+    }
+
+    @Override
+    public int[] expectedResponses() {
+        return new int[] { StateLightPowerResponse.TYPE };
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/SetPowerRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/SetPowerRequest.java
new file mode 100644 (file)
index 0000000..ff4988b
--- /dev/null
@@ -0,0 +1,74 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import java.nio.ByteBuffer;
+
+import org.openhab.binding.lifx.internal.fields.Field;
+import org.openhab.binding.lifx.internal.fields.UInt16Field;
+
+/**
+ * @author Tim Buckley - Initial contribution
+ * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
+ */
+public class SetPowerRequest extends Packet {
+
+    public static final int TYPE = 0x15;
+
+    public static final Field<Integer> FIELD_STATE = new UInt16Field();
+
+    private PowerState state;
+
+    public PowerState getState() {
+        return state;
+    }
+
+    public SetPowerRequest() {
+        state = PowerState.OFF;
+        setTagged(false);
+        setAddressable(true);
+        setResponseRequired(true);
+    }
+
+    public SetPowerRequest(PowerState state) {
+        this.state = state;
+        setTagged(false);
+        setAddressable(true);
+        setResponseRequired(true);
+    }
+
+    @Override
+    public int packetType() {
+        return TYPE;
+    }
+
+    @Override
+    protected int packetLength() {
+        return 2;
+    }
+
+    @Override
+    protected void parsePacket(ByteBuffer bytes) {
+        state = PowerState.fromValue(FIELD_STATE.value(bytes));
+    }
+
+    @Override
+    protected ByteBuffer packetBytes() {
+        return ByteBuffer.allocate(2).put(FIELD_STATE.bytes(state.getValue()));
+    }
+
+    @Override
+    public int[] expectedResponses() {
+        return new int[] { StatePowerResponse.TYPE };
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/SetTagsRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/SetTagsRequest.java
new file mode 100644 (file)
index 0000000..abbf5b5
--- /dev/null
@@ -0,0 +1,71 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import java.nio.ByteBuffer;
+
+import org.openhab.binding.lifx.internal.fields.Field;
+import org.openhab.binding.lifx.internal.fields.UInt64Field;
+
+/**
+ * @author Tim Buckley - Initial contribution
+ * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
+ */
+public class SetTagsRequest extends Packet {
+
+    public static final int TYPE = 0x1B;
+
+    public static final Field<Long> FIELD_TAGS = new UInt64Field();
+
+    private long tags;
+
+    public long getTags() {
+        return tags;
+    }
+
+    public void setTags(long tags) {
+        this.tags = tags;
+    }
+
+    public SetTagsRequest() {
+    }
+
+    public SetTagsRequest(long tags) {
+        this.tags = tags;
+    }
+
+    @Override
+    public int packetType() {
+        return TYPE;
+    }
+
+    @Override
+    protected int packetLength() {
+        return 8;
+    }
+
+    @Override
+    protected void parsePacket(ByteBuffer bytes) {
+        tags = FIELD_TAGS.value(bytes);
+    }
+
+    @Override
+    protected ByteBuffer packetBytes() {
+        return ByteBuffer.allocate(packetLength()).put(FIELD_TAGS.bytes(tags));
+    }
+
+    @Override
+    public int[] expectedResponses() {
+        return new int[] {};
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/SetTileEffectRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/SetTileEffectRequest.java
new file mode 100644 (file)
index 0000000..21d398e
--- /dev/null
@@ -0,0 +1,153 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import java.nio.ByteBuffer;
+
+import org.openhab.binding.lifx.internal.fields.Field;
+import org.openhab.binding.lifx.internal.fields.HSBK;
+import org.openhab.binding.lifx.internal.fields.HSBKField;
+import org.openhab.binding.lifx.internal.fields.UInt32Field;
+import org.openhab.binding.lifx.internal.fields.UInt64Field;
+import org.openhab.binding.lifx.internal.fields.UInt8Field;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Implementation of SetTileEffect packet
+ *
+ * @author Pawel Pieczul - Initial contribution
+ */
+public class SetTileEffectRequest extends Packet {
+
+    public static final int TYPE = 0x2CF;
+
+    // size.from.to....what
+    // ------------------------------
+    // 1....0....0.....reserved
+    // 1....1....1.....reserved
+    // 4....2....5.....instance ID
+    // 1....6....6.....effect type
+    // 4....7....10....speed
+    // 8....11...18....duration
+    // 4....19...22....reserved
+    // 4....23...26....reserved
+    // 32...27...58....parameters (8*32 bits)
+    // 1....59...59....palette count
+    // 128..60...187...palette (16*8 bits)
+
+    private static final Field<Integer> FIELD_RESERVED_0 = new UInt8Field();
+    private static final Field<Integer> FIELD_RESERVED_1 = new UInt8Field();
+    private static final Field<Long> FIELD_INSTANCE_ID = new UInt32Field().little();
+    private static final Field<Integer> FIELD_TYPE = new UInt8Field();
+    private static final Field<Long> FIELD_SPEED = new UInt32Field().little();
+    private static final Field<Long> FIELD_DURATION = new UInt64Field().little();
+    private static final Field<Long> FIELD_RESERVED_19_TO_26 = new UInt32Field().little();
+    private static final Field<Long> FIELD_PARAMETER_27_TO_58 = new UInt32Field().little();
+    private static final Field<Integer> FIELD_PALETTE_COUNT = new UInt8Field();
+    private static final Field<HSBK> FIELD_PALETTE_60_TO_187 = new HSBKField();
+
+    private final Logger logger = LoggerFactory.getLogger(SetTileEffectRequest.class);
+
+    private Integer reserved0 = 0;
+    private Integer reserved1 = 0;
+    private Long reserved19to22 = 0L;
+    private Long reserved23to26 = 0L;
+    private Effect effect;
+
+    public SetTileEffectRequest() {
+        setTagged(false);
+        setAddressable(true);
+        setAckRequired(true);
+    }
+
+    public SetTileEffectRequest(Effect effect) {
+        this();
+        this.effect = effect;
+    }
+
+    @Override
+    public int packetType() {
+        return TYPE;
+    }
+
+    @Override
+    protected int packetLength() {
+        return 188;
+    }
+
+    @Override
+    protected void parsePacket(ByteBuffer bytes) {
+        reserved0 = FIELD_RESERVED_0.value(bytes);
+        reserved1 = FIELD_RESERVED_1.value(bytes);
+        FIELD_INSTANCE_ID.value(bytes);
+        Integer effectType = FIELD_TYPE.value(bytes);
+        Long speed = FIELD_SPEED.value(bytes);
+        Long duration = FIELD_DURATION.value(bytes);
+        reserved19to22 = FIELD_RESERVED_19_TO_26.value(bytes);
+        reserved23to26 = FIELD_RESERVED_19_TO_26.value(bytes);
+        Long[] parameters = new Long[8];
+        for (int i = 0; i < parameters.length; i++) {
+            parameters[i] = FIELD_PARAMETER_27_TO_58.value(bytes);
+        }
+        Integer paletteCount = FIELD_PALETTE_COUNT.value(bytes);
+        HSBK[] palette = new HSBK[paletteCount];
+        for (int i = 0; i < palette.length; i++) {
+            palette[i] = FIELD_PALETTE_60_TO_187.value(bytes);
+        }
+        try {
+            effect = new Effect(effectType, speed, duration, palette);
+        } catch (IllegalArgumentException e) {
+            logger.debug("Wrong effect type received: {}", effectType);
+            effect = null;
+        }
+    }
+
+    @Override
+    protected ByteBuffer packetBytes() {
+        ByteBuffer buffer = ByteBuffer.allocate(packetLength());
+        buffer.put(FIELD_RESERVED_0.bytes(reserved0));
+        buffer.put(FIELD_RESERVED_1.bytes(reserved1));
+        buffer.put(FIELD_INSTANCE_ID.bytes(0L));
+        buffer.put(FIELD_TYPE.bytes(effect.getType().intValue()));
+        buffer.put(FIELD_SPEED.bytes(effect.getSpeed()));
+        buffer.put(FIELD_DURATION.bytes(effect.getDuration()));
+        buffer.put(FIELD_RESERVED_19_TO_26.bytes(reserved19to22));
+        buffer.put(FIELD_RESERVED_19_TO_26.bytes(reserved23to26));
+        for (int i = 0; i < 8; i++) {
+            buffer.put(FIELD_PARAMETER_27_TO_58.bytes(0L));
+        }
+        buffer.put(FIELD_PALETTE_COUNT.bytes(effect.getPalette().length));
+        HSBK[] palette = effect.getPalette();
+        for (int i = 0; i < palette.length; i++) {
+            buffer.put(FIELD_PALETTE_60_TO_187.bytes(palette[i]));
+        }
+        HSBK hsbkZero = new HSBK(0, 0, 0, 0);
+        for (int i = 0; i < 16 - palette.length; i++) {
+            buffer.put(FIELD_PALETTE_60_TO_187.bytes(hsbkZero));
+        }
+        if (logger.isDebugEnabled()) {
+            logger.debug("SetTileEffectRequest: type={}, speed={}, duration={}, palette_count={}", effect.getType(),
+                    effect.getSpeed(), effect.getDuration(), palette.length);
+            for (int i = 0; i < palette.length; i++) {
+                logger.debug("SetTileEffectRequest palette[{}] = {}", i, palette[i]);
+            }
+        }
+        return buffer;
+    }
+
+    @Override
+    public int[] expectedResponses() {
+        return new int[] {};
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/SignalStrength.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/SignalStrength.java
new file mode 100644 (file)
index 0000000..716a93f
--- /dev/null
@@ -0,0 +1,75 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+/**
+ * The signal strength of a light.
+ *
+ * @author Wouter Born - Initial contribution
+ */
+public class SignalStrength {
+
+    private double milliWatts;
+
+    public SignalStrength(double milliWatts) {
+        this.milliWatts = milliWatts;
+    }
+
+    /**
+     * Returns the signal strength.
+     *
+     * @return the signal strength in milliwatts (mW).
+     */
+    public double getMilliWatts() {
+        return milliWatts;
+    }
+
+    /**
+     * Returns the signal strength as a quality percentage:
+     * <ul>
+     * <li>RSSI <= -100: returns 0
+     * <li>-100 < RSSI < -50: returns a value between 0 and 1 (linearly distributed)
+     * <li>RSSI >= -50: returns 1
+     * <ul>
+     *
+     * @return a value between 0 and 1. 0 being worst strength and 1
+     *         being best strength.
+     */
+    public double toQualityPercentage() {
+        return Math.min(100, Math.max(0, 2 * (toRSSI() + 100))) / 100;
+    }
+
+    /**
+     * Returns the signal strength as a quality rating.
+     *
+     * @return one of the values: 0, 1, 2, 3 or 4. 0 being worst strength and 4
+     *         being best strength.
+     */
+    public byte toQualityRating() {
+        return (byte) Math.round(toQualityPercentage() * 4);
+    }
+
+    /**
+     * Returns the received signal strength indicator (RSSI).
+     *
+     * @return a value <= 0. 0 being best strength and more negative values indicate worser strength.
+     */
+    public double toRSSI() {
+        return 10 * Math.log10(milliWatts);
+    }
+
+    @Override
+    public String toString() {
+        return "SignalStrength [milliWatts=" + milliWatts + ", rssi=" + Math.round(toRSSI()) + "]";
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/StateGroupResponse.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/StateGroupResponse.java
new file mode 100644 (file)
index 0000000..2463eda
--- /dev/null
@@ -0,0 +1,93 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import java.nio.ByteBuffer;
+
+import org.openhab.binding.lifx.internal.fields.ByteField;
+import org.openhab.binding.lifx.internal.fields.Field;
+import org.openhab.binding.lifx.internal.fields.StringField;
+import org.openhab.binding.lifx.internal.fields.UInt64Field;
+
+/**
+ * @author Tim Buckley - Initial contribution
+ * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
+ */
+public class StateGroupResponse extends Packet {
+
+    public static final int TYPE = 0x35;
+
+    public static final Field<ByteBuffer> FIELD_GROUP = new ByteField(16);
+    public static final Field<String> FIELD_LABEL = new StringField(32).utf8();
+    public static final Field<Long> FIELD_UPDATED_AT = new UInt64Field().little();
+
+    private ByteBuffer group;
+    private String label;
+    private long updatedAt;
+
+    public static int getType() {
+        return TYPE;
+    }
+
+    public ByteBuffer getGroup() {
+        return group;
+    }
+
+    public void setGroup(ByteBuffer group) {
+        this.group = group;
+    }
+
+    public String getLabel() {
+        return label;
+    }
+
+    public void setLabel(String label) {
+        this.label = label;
+    }
+
+    public long getUpdatedAt() {
+        return updatedAt;
+    }
+
+    public void setUpdatedAt(long updatedAt) {
+        this.updatedAt = updatedAt;
+    }
+
+    @Override
+    public int packetType() {
+        return TYPE;
+    }
+
+    @Override
+    protected int packetLength() {
+        return 14;
+    }
+
+    @Override
+    protected void parsePacket(ByteBuffer bytes) {
+        group = FIELD_GROUP.value(bytes);
+        label = FIELD_LABEL.value(bytes);
+        updatedAt = FIELD_UPDATED_AT.value(bytes);
+    }
+
+    @Override
+    protected ByteBuffer packetBytes() {
+        return ByteBuffer.allocate(packetLength()).put(FIELD_GROUP.bytes(group)).put(FIELD_LABEL.bytes(label))
+                .put(FIELD_UPDATED_AT.bytes(updatedAt));
+    }
+
+    @Override
+    public int[] expectedResponses() {
+        return new int[] {};
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/StateHostFirmwareResponse.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/StateHostFirmwareResponse.java
new file mode 100644 (file)
index 0000000..065c065
--- /dev/null
@@ -0,0 +1,87 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import java.nio.ByteBuffer;
+
+import org.openhab.binding.lifx.internal.fields.Field;
+import org.openhab.binding.lifx.internal.fields.UInt64Field;
+import org.openhab.binding.lifx.internal.fields.Version;
+import org.openhab.binding.lifx.internal.fields.VersionField;
+
+/**
+ * @author Tim Buckley - Initial contribution
+ * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
+ */
+public class StateHostFirmwareResponse extends Packet {
+
+    public static final int TYPE = 0x0F;
+
+    public static final Field<Long> FIELD_BUILD = new UInt64Field().little();
+    public static final Field<Long> FIELD_RESERVED = new UInt64Field().little();
+    public static final Field<Version> FIELD_VERSION = new VersionField().little();
+
+    private long build;
+    private long reserved;
+    private Version version;
+
+    public long getBuild() {
+        return build;
+    }
+
+    public void setBuild(long build) {
+        this.build = build;
+    }
+
+    public Version getVersion() {
+        return version;
+    }
+
+    public void setVersion(Version version) {
+        this.version = version;
+    }
+
+    public StateHostFirmwareResponse() {
+        setTagged(false);
+        setAddressable(true);
+        setResponseRequired(true);
+    }
+
+    @Override
+    public int packetType() {
+        return TYPE;
+    }
+
+    @Override
+    protected int packetLength() {
+        return 20;
+    }
+
+    @Override
+    protected void parsePacket(ByteBuffer bytes) {
+        build = FIELD_BUILD.value(bytes);
+        reserved = FIELD_RESERVED.value(bytes);
+        version = FIELD_VERSION.value(bytes);
+    }
+
+    @Override
+    protected ByteBuffer packetBytes() {
+        return ByteBuffer.allocate(packetLength()).put(FIELD_BUILD.bytes(build)).put(FIELD_RESERVED.bytes(reserved))
+                .put(FIELD_VERSION.bytes(version));
+    }
+
+    @Override
+    public int[] expectedResponses() {
+        return new int[] {};
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/StateHostInfoResponse.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/StateHostInfoResponse.java
new file mode 100644 (file)
index 0000000..1690bd2
--- /dev/null
@@ -0,0 +1,84 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import java.nio.ByteBuffer;
+
+import org.openhab.binding.lifx.internal.fields.ByteField;
+import org.openhab.binding.lifx.internal.fields.Field;
+import org.openhab.binding.lifx.internal.fields.FloatField;
+import org.openhab.binding.lifx.internal.fields.UInt32Field;
+
+/**
+ * @author Tim Buckley - Initial contribution
+ * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
+ */
+public class StateHostInfoResponse extends Packet {
+
+    public static final int TYPE = 0x0D;
+
+    public static final Field<Float> FIELD_SIGNAL = new FloatField().little();
+    public static final Field<Long> FIELD_TX = new UInt32Field().little();
+    public static final Field<Long> FIELD_RX = new UInt32Field().little();
+    public static final Field<ByteBuffer> FIELD_RESERVED_5 = new ByteField(2);
+
+    private float signal;
+    private long tx;
+    private long rx;
+
+    public SignalStrength getSignalStrength() {
+        return new SignalStrength(signal);
+    }
+
+    public long getTx() {
+        return tx;
+    }
+
+    public long getRx() {
+        return rx;
+    }
+
+    public StateHostInfoResponse() {
+        setTagged(false);
+        setAddressable(true);
+        setResponseRequired(true);
+    }
+
+    @Override
+    public int packetType() {
+        return TYPE;
+    }
+
+    @Override
+    protected int packetLength() {
+        return 14;
+    }
+
+    @Override
+    protected void parsePacket(ByteBuffer bytes) {
+        signal = FIELD_SIGNAL.value(bytes);
+        tx = FIELD_TX.value(bytes);
+        rx = FIELD_RX.value(bytes);
+    }
+
+    @Override
+    protected ByteBuffer packetBytes() {
+        return ByteBuffer.allocate(packetLength()).put(FIELD_SIGNAL.bytes(signal)).put(FIELD_TX.bytes(tx))
+                .put(FIELD_RX.bytes(rx));
+    }
+
+    @Override
+    public int[] expectedResponses() {
+        return new int[] {};
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/StateInfoResponse.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/StateInfoResponse.java
new file mode 100644 (file)
index 0000000..ca3ccf2
--- /dev/null
@@ -0,0 +1,93 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import java.nio.ByteBuffer;
+
+import org.openhab.binding.lifx.internal.fields.Field;
+import org.openhab.binding.lifx.internal.fields.UInt64Field;
+
+/**
+ * @author Tim Buckley - Initial contribution
+ * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
+ */
+public class StateInfoResponse extends Packet {
+
+    public static final int TYPE = 0x23;
+
+    public static final Field<Long> FIELD_TIME = new UInt64Field().little();
+    public static final Field<Long> FIELD_UPTIME = new UInt64Field().little();
+    public static final Field<Long> FIELD_DOWNTIME = new UInt64Field().little();
+
+    private long time;
+    private long uptime;
+    private long downtime;
+
+    public long getTime() {
+        return time;
+    }
+
+    public void setTime(long time) {
+        this.time = time;
+    }
+
+    public long getUptime() {
+        return uptime;
+    }
+
+    public void setUptime(long uptime) {
+        this.uptime = uptime;
+    }
+
+    public long getDowntime() {
+        return downtime;
+    }
+
+    public void setDowntime(long downtime) {
+        this.downtime = downtime;
+    }
+
+    public StateInfoResponse() {
+        setTagged(false);
+        setAddressable(true);
+        setResponseRequired(true);
+    }
+
+    @Override
+    public int packetType() {
+        return TYPE;
+    }
+
+    @Override
+    protected int packetLength() {
+        return 24;
+    }
+
+    @Override
+    protected void parsePacket(ByteBuffer bytes) {
+        time = FIELD_TIME.value(bytes);
+        uptime = FIELD_UPTIME.value(bytes);
+        downtime = FIELD_DOWNTIME.value(bytes);
+    }
+
+    @Override
+    protected ByteBuffer packetBytes() {
+        return ByteBuffer.allocate(packetLength()).put(FIELD_TIME.bytes(time)).put(FIELD_UPTIME.bytes(uptime))
+                .put(FIELD_DOWNTIME.bytes(downtime));
+    }
+
+    @Override
+    public int[] expectedResponses() {
+        return new int[] {};
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/StateLabelResponse.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/StateLabelResponse.java
new file mode 100644 (file)
index 0000000..409d61f
--- /dev/null
@@ -0,0 +1,68 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import java.nio.ByteBuffer;
+
+import org.openhab.binding.lifx.internal.fields.Field;
+import org.openhab.binding.lifx.internal.fields.StringField;
+
+/**
+ * @author Tim Buckley - Initial contribution
+ * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
+ */
+public class StateLabelResponse extends Packet {
+
+    public static final int TYPE = 0x19;
+
+    public static final Field<String> FIELD_LABEL = new StringField(32).utf8();
+
+    private String label;
+
+    public static int getType() {
+        return TYPE;
+    }
+
+    public static Field<String> getFieldLabel() {
+        return FIELD_LABEL;
+    }
+
+    public String getLabel() {
+        return label;
+    }
+
+    @Override
+    public int packetType() {
+        return TYPE;
+    }
+
+    @Override
+    protected int packetLength() {
+        return 32;
+    }
+
+    @Override
+    protected void parsePacket(ByteBuffer bytes) {
+        label = FIELD_LABEL.value(bytes);
+    }
+
+    @Override
+    protected ByteBuffer packetBytes() {
+        return FIELD_LABEL.bytes(label);
+    }
+
+    @Override
+    public int[] expectedResponses() {
+        return new int[] {};
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/StateLightInfraredResponse.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/StateLightInfraredResponse.java
new file mode 100644 (file)
index 0000000..53d561b
--- /dev/null
@@ -0,0 +1,59 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import java.nio.ByteBuffer;
+
+import org.openhab.binding.lifx.internal.fields.Field;
+import org.openhab.binding.lifx.internal.fields.UInt16Field;
+
+/**
+ * @author Wouter Born - Initial contribution
+ */
+public class StateLightInfraredResponse extends Packet {
+
+    public static final int TYPE = 0x79;
+
+    public static final Field<Integer> FIELD_STATE = new UInt16Field().little();
+
+    private int infrared;
+
+    public int getInfrared() {
+        return infrared;
+    }
+
+    @Override
+    public int packetType() {
+        return TYPE;
+    }
+
+    @Override
+    protected int packetLength() {
+        return 2;
+    }
+
+    @Override
+    protected void parsePacket(ByteBuffer bytes) {
+        infrared = FIELD_STATE.value(bytes);
+    }
+
+    @Override
+    protected ByteBuffer packetBytes() {
+        return ByteBuffer.allocate(packetLength()).put(FIELD_STATE.bytes(infrared));
+    }
+
+    @Override
+    public int[] expectedResponses() {
+        return new int[] {};
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/StateLightPowerResponse.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/StateLightPowerResponse.java
new file mode 100644 (file)
index 0000000..9d248a1
--- /dev/null
@@ -0,0 +1,61 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import java.nio.ByteBuffer;
+
+import org.openhab.binding.lifx.internal.fields.Field;
+import org.openhab.binding.lifx.internal.fields.UInt16Field;
+
+/**
+ * @author Tim Buckley - Initial contribution
+ * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
+ */
+public class StateLightPowerResponse extends Packet {
+
+    public static final int TYPE = 0x76;
+
+    public static final Field<Integer> FIELD_STATE = new UInt16Field();
+
+    private PowerState state;
+
+    public PowerState getState() {
+        return state;
+    }
+
+    @Override
+    public int packetType() {
+        return TYPE;
+    }
+
+    @Override
+    protected int packetLength() {
+        return 2;
+    }
+
+    @Override
+    protected void parsePacket(ByteBuffer bytes) {
+        int stateValue = FIELD_STATE.value(bytes);
+        state = PowerState.fromValue(stateValue);
+    }
+
+    @Override
+    protected ByteBuffer packetBytes() {
+        return ByteBuffer.allocate(packetLength()).put(FIELD_STATE.bytes(state.getValue()));
+    }
+
+    @Override
+    public int[] expectedResponses() {
+        return new int[] {};
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/StateLocationResponse.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/StateLocationResponse.java
new file mode 100644 (file)
index 0000000..77c0146
--- /dev/null
@@ -0,0 +1,93 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import java.nio.ByteBuffer;
+
+import org.openhab.binding.lifx.internal.fields.ByteField;
+import org.openhab.binding.lifx.internal.fields.Field;
+import org.openhab.binding.lifx.internal.fields.StringField;
+import org.openhab.binding.lifx.internal.fields.UInt64Field;
+
+/**
+ * @author Tim Buckley - Initial contribution
+ * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
+ */
+public class StateLocationResponse extends Packet {
+
+    public static final int TYPE = 0x32;
+
+    public static final Field<ByteBuffer> FIELD_LOCATION = new ByteField(16);
+    public static final Field<String> FIELD_LABEL = new StringField(32).utf8();
+    public static final Field<Long> FIELD_UPDATED_AT = new UInt64Field().little();
+
+    private ByteBuffer location;
+    private String label;
+    private long updatedAt;
+
+    public static int getType() {
+        return TYPE;
+    }
+
+    public ByteBuffer getLocation() {
+        return location;
+    }
+
+    public void setLocation(ByteBuffer location) {
+        this.location = location;
+    }
+
+    public String getLabel() {
+        return label;
+    }
+
+    public void setLabel(String label) {
+        this.label = label;
+    }
+
+    public long getUpdatedAt() {
+        return updatedAt;
+    }
+
+    public void setUpdatedAt(long updatedAt) {
+        this.updatedAt = updatedAt;
+    }
+
+    @Override
+    public int packetType() {
+        return TYPE;
+    }
+
+    @Override
+    protected int packetLength() {
+        return 14;
+    }
+
+    @Override
+    protected void parsePacket(ByteBuffer bytes) {
+        location = FIELD_LOCATION.value(bytes);
+        label = FIELD_LABEL.value(bytes);
+        updatedAt = FIELD_UPDATED_AT.value(bytes);
+    }
+
+    @Override
+    protected ByteBuffer packetBytes() {
+        return ByteBuffer.allocate(packetLength()).put(FIELD_LOCATION.bytes(location)).put(FIELD_LABEL.bytes(label))
+                .put(FIELD_UPDATED_AT.bytes(updatedAt));
+    }
+
+    @Override
+    public int[] expectedResponses() {
+        return new int[] {};
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/StateMultiZoneResponse.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/StateMultiZoneResponse.java
new file mode 100644 (file)
index 0000000..4e2443b
--- /dev/null
@@ -0,0 +1,98 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import java.nio.ByteBuffer;
+
+import org.openhab.binding.lifx.internal.fields.Field;
+import org.openhab.binding.lifx.internal.fields.HSBK;
+import org.openhab.binding.lifx.internal.fields.HSBKField;
+import org.openhab.binding.lifx.internal.fields.UInt8Field;
+
+/**
+ * @author Wouter Born - Initial contribution
+ */
+public class StateMultiZoneResponse extends Packet {
+
+    public static final int TYPE = 0x1FA;
+    public static final int ZONES = 8;
+
+    public static final Field<Integer> FIELD_COUNT = new UInt8Field();
+    public static final Field<Integer> FIELD_INDEX = new UInt8Field();
+    public static final HSBKField FIELD_COLOR = new HSBKField();
+
+    private int count;
+    private int index;
+    private HSBK[] colors = new HSBK[ZONES];
+
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        sb.append("count=");
+        sb.append(count);
+        sb.append(", index=");
+        sb.append(index);
+
+        for (int i = 0; i < ZONES; i++) {
+            sb.append(", ");
+            sb.append(colors[i].toString("color[" + i + "]"));
+        }
+
+        return sb.toString();
+    }
+
+    public int getCount() {
+        return count;
+    }
+
+    public int getIndex() {
+        return index;
+    }
+
+    public HSBK[] getColors() {
+        return colors;
+    }
+
+    @Override
+    public int packetType() {
+        return TYPE;
+    }
+
+    @Override
+    protected int packetLength() {
+        return 66;
+    }
+
+    @Override
+    protected void parsePacket(ByteBuffer bytes) {
+        count = FIELD_COUNT.value(bytes);
+        index = FIELD_INDEX.value(bytes);
+        for (int i = 0; i < ZONES; i++) {
+            colors[i] = FIELD_COLOR.value(bytes);
+        }
+    }
+
+    @Override
+    protected ByteBuffer packetBytes() {
+        ByteBuffer bb = ByteBuffer.allocate(packetLength()).put(FIELD_COUNT.bytes(count)).put(FIELD_INDEX.bytes(index));
+        for (int i = 0; i < ZONES; i++) {
+            bb.put(FIELD_COLOR.bytes(colors[i]));
+        }
+        return bb;
+    }
+
+    @Override
+    public int[] expectedResponses() {
+        return new int[] {};
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/StatePowerResponse.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/StatePowerResponse.java
new file mode 100644 (file)
index 0000000..7d86030
--- /dev/null
@@ -0,0 +1,61 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import java.nio.ByteBuffer;
+
+import org.openhab.binding.lifx.internal.fields.Field;
+import org.openhab.binding.lifx.internal.fields.UInt16Field;
+
+/**
+ * @author Tim Buckley - Initial contribution
+ * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
+ */
+public class StatePowerResponse extends Packet {
+
+    public static final int TYPE = 0x16;
+
+    public static final Field<Integer> FIELD_STATE = new UInt16Field();
+
+    private PowerState state;
+
+    public PowerState getState() {
+        return state;
+    }
+
+    @Override
+    public int packetType() {
+        return TYPE;
+    }
+
+    @Override
+    protected int packetLength() {
+        return 2;
+    }
+
+    @Override
+    protected void parsePacket(ByteBuffer bytes) {
+        int stateValue = FIELD_STATE.value(bytes);
+        state = PowerState.fromValue(stateValue);
+    }
+
+    @Override
+    protected ByteBuffer packetBytes() {
+        return ByteBuffer.allocate(packetLength()).put(FIELD_STATE.bytes(state.getValue()));
+    }
+
+    @Override
+    public int[] expectedResponses() {
+        return new int[] {};
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/StateResponse.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/StateResponse.java
new file mode 100644 (file)
index 0000000..808577b
--- /dev/null
@@ -0,0 +1,98 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import java.nio.ByteBuffer;
+
+import org.openhab.binding.lifx.internal.fields.Field;
+import org.openhab.binding.lifx.internal.fields.HSBK;
+import org.openhab.binding.lifx.internal.fields.HSBKField;
+import org.openhab.binding.lifx.internal.fields.StringField;
+import org.openhab.binding.lifx.internal.fields.UInt16Field;
+import org.openhab.binding.lifx.internal.fields.UInt64Field;
+
+/**
+ * @author Tim Buckley - Initial contribution
+ * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
+ */
+public class StateResponse extends Packet {
+
+    public static final int TYPE = 0x6B;
+
+    public static final HSBKField FIELD_COLOR = new HSBKField();
+    public static final Field<Integer> FIELD_DIM = new UInt16Field().little();
+    public static final Field<Integer> FIELD_POWER = new UInt16Field();
+    public static final Field<String> FIELD_LABEL = new StringField(32);
+    public static final Field<Long> FIELD_TAGS = new UInt64Field();
+
+    private HSBK color;
+    private int dim;
+    private PowerState power;
+    private String label;
+    private long tags;
+
+    @Override
+    public String toString() {
+        return color.toString("color") + ", dim=" + dim + ", power=" + power + ", label=" + label;
+    }
+
+    public HSBK getColor() {
+        return color;
+    }
+
+    public int getDim() {
+        return dim;
+    }
+
+    public PowerState getPower() {
+        return power;
+    }
+
+    public String getLabel() {
+        return label;
+    }
+
+    public long getTags() {
+        return tags;
+    }
+
+    @Override
+    public int packetType() {
+        return TYPE;
+    }
+
+    @Override
+    protected int packetLength() {
+        return 52;
+    }
+
+    @Override
+    protected void parsePacket(ByteBuffer bytes) {
+        color = FIELD_COLOR.value(bytes);
+        dim = FIELD_DIM.value(bytes);
+        power = PowerState.fromValue(FIELD_POWER.value(bytes));
+        label = FIELD_LABEL.value(bytes);
+        tags = FIELD_TAGS.value(bytes);
+    }
+
+    @Override
+    protected ByteBuffer packetBytes() {
+        return ByteBuffer.allocate(packetLength()).put(FIELD_COLOR.bytes(color)).put(FIELD_DIM.bytes(dim))
+                .put(FIELD_POWER.bytes(power.getValue())).put(FIELD_LABEL.bytes(label)).put(FIELD_TAGS.bytes(tags));
+    }
+
+    @Override
+    public int[] expectedResponses() {
+        return new int[] {};
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/StateServiceResponse.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/StateServiceResponse.java
new file mode 100644 (file)
index 0000000..599da30
--- /dev/null
@@ -0,0 +1,72 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import java.nio.ByteBuffer;
+
+import org.openhab.binding.lifx.internal.fields.Field;
+import org.openhab.binding.lifx.internal.fields.LittleField;
+import org.openhab.binding.lifx.internal.fields.UInt32Field;
+import org.openhab.binding.lifx.internal.fields.UInt8Field;
+
+/**
+ * @author Tim Buckley - Initial contribution
+ * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
+ */
+public class StateServiceResponse extends Packet {
+
+    public static final int TYPE = 0x03;
+
+    public static final Field<Integer> FIELD_SERVICE = new UInt8Field();
+    public static final Field<Long> FIELD_PORT = new LittleField<>(new UInt32Field());
+
+    private int service;
+    private long port;
+
+    public int getService() {
+        return service;
+    }
+
+    public long getPort() {
+        return port;
+    }
+
+    public StateServiceResponse() {
+    }
+
+    @Override
+    protected void parsePacket(ByteBuffer bytes) {
+        service = FIELD_SERVICE.value(bytes);
+        port = FIELD_PORT.value(bytes);
+    }
+
+    @Override
+    public int packetType() {
+        return TYPE;
+    }
+
+    @Override
+    protected int packetLength() {
+        return 5;
+    }
+
+    @Override
+    protected ByteBuffer packetBytes() {
+        return ByteBuffer.allocate(packetLength()).put(FIELD_SERVICE.bytes(service)).put(FIELD_PORT.bytes(port));
+    }
+
+    @Override
+    public int[] expectedResponses() {
+        return new int[] {};
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/StateTileEffectResponse.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/StateTileEffectResponse.java
new file mode 100644 (file)
index 0000000..c9b6f40
--- /dev/null
@@ -0,0 +1,144 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import java.nio.ByteBuffer;
+
+import org.openhab.binding.lifx.internal.fields.Field;
+import org.openhab.binding.lifx.internal.fields.HSBK;
+import org.openhab.binding.lifx.internal.fields.HSBKField;
+import org.openhab.binding.lifx.internal.fields.UInt32Field;
+import org.openhab.binding.lifx.internal.fields.UInt64Field;
+import org.openhab.binding.lifx.internal.fields.UInt8Field;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Implementation of StateTileEffect packet
+ *
+ * @author Pawel Pieczul - Initial contribution
+ */
+public class StateTileEffectResponse extends Packet {
+
+    public static final int TYPE = 0x2D0;
+
+    // size.from.to....what
+    // ------------------------------
+    // 1....0....0.....reserved
+    // 4....1....4.....instance ID
+    // 1....5....5.....effect type
+    // 4....6....9.....speed
+    // 8....10...17....duration
+    // 4....18...21....reserved
+    // 4....22...25....reserved
+    // 32...26...57....parameters (8*32 bits)
+    // 1....58...58....palette count
+    // 128..59...186...palette (16*8 bits)
+
+    private static final Field<Integer> FIELD_RESERVED_0 = new UInt8Field();
+    private static final Field<Long> FIELD_INSTANCE_ID = new UInt32Field().little();
+    private static final Field<Integer> FIELD_TYPE = new UInt8Field();
+    private static final Field<Long> FIELD_SPEED = new UInt32Field().little();
+    private static final Field<Long> FIELD_DURATION = new UInt64Field().little();
+    private static final Field<Long> FIELD_RESERVED_18_TO_25 = new UInt32Field().little();
+    private static final Field<Long> FIELD_PARAMETER_26_TO_57 = new UInt32Field().little();
+    private static final Field<Integer> FIELD_PALETTE_COUNT = new UInt8Field();
+    private static final Field<HSBK> FIELD_PALETTE_59_TO_186 = new HSBKField();
+
+    private Integer reserved0 = 0;
+    private Long reserved18to21 = 0L;
+    private Long reserved22to25 = 0L;
+    private Effect effect;
+
+    private final Logger logger = LoggerFactory.getLogger(StateTileEffectResponse.class);
+
+    public Effect getEffect() {
+        return effect;
+    }
+
+    @Override
+    public int packetType() {
+        return TYPE;
+    }
+
+    @Override
+    protected int packetLength() {
+        return 187;
+    }
+
+    @Override
+    protected void parsePacket(ByteBuffer bytes) {
+        reserved0 = FIELD_RESERVED_0.value(bytes);
+        Long instanceId = FIELD_INSTANCE_ID.value(bytes);
+        Integer effectType = FIELD_TYPE.value(bytes);
+        Long speed = FIELD_SPEED.value(bytes);
+        Long duration = FIELD_DURATION.value(bytes);
+        reserved18to21 = FIELD_RESERVED_18_TO_25.value(bytes);
+        reserved22to25 = FIELD_RESERVED_18_TO_25.value(bytes);
+        Long[] parameters = new Long[8];
+        for (int i = 0; i < 8; i++) {
+            parameters[i] = FIELD_PARAMETER_26_TO_57.value(bytes);
+        }
+        Integer paletteCount = FIELD_PALETTE_COUNT.value(bytes);
+        HSBK[] palette = new HSBK[paletteCount];
+        for (int i = 0; i < palette.length; i++) {
+            palette[i] = FIELD_PALETTE_59_TO_186.value(bytes);
+        }
+        try {
+            effect = new Effect(effectType, speed, duration, palette);
+        } catch (IllegalArgumentException e) {
+            logger.debug("Wrong effect type received: {}", effectType);
+            effect = null;
+        }
+        if (logger.isDebugEnabled()) {
+            logger.debug("StateTileEffectResponse: instanceId={}, type={}, speed={}, duration={}, palette_count={}",
+                    instanceId, effectType, speed, duration, paletteCount);
+            logger.debug("StateTileEffectResponse parameters=[{}, {}, {}, {}, {}, {}, {}, {}]", parameters[0],
+                    parameters[1], parameters[2], parameters[3], parameters[4], parameters[5], parameters[6],
+                    parameters[7]);
+            for (int i = 0; i < palette.length; i++) {
+                logger.debug("StateTileEffectResponse palette[{}] = {}", i, palette[i]);
+            }
+        }
+    }
+
+    @Override
+    protected ByteBuffer packetBytes() {
+        ByteBuffer buffer = ByteBuffer.allocate(packetLength());
+        buffer.put(FIELD_RESERVED_0.bytes(reserved0));
+        buffer.put(FIELD_INSTANCE_ID.bytes(0L));
+        buffer.put(FIELD_TYPE.bytes(effect.getType().intValue()));
+        buffer.put(FIELD_SPEED.bytes(effect.getSpeed()));
+        buffer.put(FIELD_DURATION.bytes(effect.getDuration()));
+        buffer.put(FIELD_RESERVED_18_TO_25.bytes(reserved18to21));
+        buffer.put(FIELD_RESERVED_18_TO_25.bytes(reserved22to25));
+        for (int i = 0; i < 8; i++) {
+            buffer.put(FIELD_PARAMETER_26_TO_57.bytes(0L));
+        }
+        HSBK[] palette = effect.getPalette();
+        buffer.put(FIELD_PALETTE_COUNT.bytes(palette.length));
+        for (int i = 0; i < palette.length; i++) {
+            buffer.put(FIELD_PALETTE_59_TO_186.bytes(palette[i]));
+        }
+        HSBK hsbkZero = new HSBK(0, 0, 0, 0);
+        for (int i = 0; i < 16 - palette.length; i++) {
+            buffer.put(FIELD_PALETTE_59_TO_186.bytes(hsbkZero));
+        }
+        return buffer;
+    }
+
+    @Override
+    public int[] expectedResponses() {
+        return new int[] {};
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/StateVersionResponse.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/StateVersionResponse.java
new file mode 100644 (file)
index 0000000..db0b14e
--- /dev/null
@@ -0,0 +1,93 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import java.nio.ByteBuffer;
+
+import org.openhab.binding.lifx.internal.fields.Field;
+import org.openhab.binding.lifx.internal.fields.UInt32Field;
+
+/**
+ * @author Tim Buckley - Initial contribution
+ * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
+ */
+public class StateVersionResponse extends Packet {
+
+    public static final int TYPE = 0x21;
+
+    public static final Field<Long> FIELD_VENDOR = new UInt32Field().little();
+    public static final Field<Long> FIELD_PRODUCT = new UInt32Field().little();
+    public static final Field<Long> FIELD_VERSION = new UInt32Field().little();
+
+    private long vendor;
+    private long product;
+    private long version;
+
+    public long getVendor() {
+        return vendor;
+    }
+
+    public void setVendor(long build) {
+        this.vendor = build;
+    }
+
+    public long getProduct() {
+        return product;
+    }
+
+    public void setProduct(long product) {
+        this.product = product;
+    }
+
+    public long getVersion() {
+        return version;
+    }
+
+    public void setVersion(long version) {
+        this.version = version;
+    }
+
+    public StateVersionResponse() {
+        setTagged(false);
+        setAddressable(true);
+        setResponseRequired(true);
+    }
+
+    @Override
+    public int packetType() {
+        return TYPE;
+    }
+
+    @Override
+    protected int packetLength() {
+        return 12;
+    }
+
+    @Override
+    protected void parsePacket(ByteBuffer bytes) {
+        vendor = FIELD_VENDOR.value(bytes);
+        product = FIELD_PRODUCT.value(bytes);
+        version = FIELD_VERSION.value(bytes);
+    }
+
+    @Override
+    protected ByteBuffer packetBytes() {
+        return ByteBuffer.allocate(packetLength()).put(FIELD_VENDOR.bytes(vendor)).put(FIELD_PRODUCT.bytes(product))
+                .put(FIELD_VERSION.bytes(version));
+    }
+
+    @Override
+    public int[] expectedResponses() {
+        return new int[] {};
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/StateWifiFirmwareResponse.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/StateWifiFirmwareResponse.java
new file mode 100644 (file)
index 0000000..6cf177f
--- /dev/null
@@ -0,0 +1,87 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import java.nio.ByteBuffer;
+
+import org.openhab.binding.lifx.internal.fields.Field;
+import org.openhab.binding.lifx.internal.fields.UInt64Field;
+import org.openhab.binding.lifx.internal.fields.Version;
+import org.openhab.binding.lifx.internal.fields.VersionField;
+
+/**
+ * @author Tim Buckley - Initial contribution
+ * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
+ */
+public class StateWifiFirmwareResponse extends Packet {
+
+    public static final int TYPE = 0x13;
+
+    public static final Field<Long> FIELD_BUILD = new UInt64Field().little();
+    public static final Field<Long> FIELD_RESERVED = new UInt64Field().little();
+    public static final Field<Version> FIELD_VERSION = new VersionField().little();
+
+    private long build;
+    private long reserved;
+    private Version version;
+
+    public long getBuild() {
+        return build;
+    }
+
+    public void setBuild(long build) {
+        this.build = build;
+    }
+
+    public Version getVersion() {
+        return version;
+    }
+
+    public void setVersion(Version version) {
+        this.version = version;
+    }
+
+    public StateWifiFirmwareResponse() {
+        setTagged(false);
+        setAddressable(true);
+        setResponseRequired(true);
+    }
+
+    @Override
+    public int packetType() {
+        return TYPE;
+    }
+
+    @Override
+    protected int packetLength() {
+        return 20;
+    }
+
+    @Override
+    protected void parsePacket(ByteBuffer bytes) {
+        build = FIELD_BUILD.value(bytes);
+        reserved = FIELD_RESERVED.value(bytes);
+        version = FIELD_VERSION.value(bytes);
+    }
+
+    @Override
+    protected ByteBuffer packetBytes() {
+        return ByteBuffer.allocate(packetLength()).put(FIELD_BUILD.bytes(build)).put(FIELD_RESERVED.bytes(reserved))
+                .put(FIELD_VERSION.bytes(version));
+    }
+
+    @Override
+    public int[] expectedResponses() {
+        return new int[] {};
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/StateWifiInfoResponse.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/StateWifiInfoResponse.java
new file mode 100644 (file)
index 0000000..516562d
--- /dev/null
@@ -0,0 +1,84 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import java.nio.ByteBuffer;
+
+import org.openhab.binding.lifx.internal.fields.Field;
+import org.openhab.binding.lifx.internal.fields.FloatField;
+import org.openhab.binding.lifx.internal.fields.UInt16Field;
+import org.openhab.binding.lifx.internal.fields.UInt32Field;
+
+/**
+ * @author Tim Buckley - Initial contribution
+ * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
+ */
+public class StateWifiInfoResponse extends Packet {
+
+    public static final int TYPE = 0x11;
+
+    public static final Field<Float> FIELD_SIGNAL = new FloatField().little();
+    public static final Field<Long> FIELD_RX = new UInt32Field().little();
+    public static final Field<Long> FIELD_TX = new UInt32Field().little();
+    public static final Field<Integer> FIELD_TEMP = new UInt16Field();
+
+    private float signal;
+    private long rx;
+    private long tx;
+    private int mcuTemperature;
+
+    public SignalStrength getSignalStrength() {
+        return new SignalStrength(signal);
+    }
+
+    public long getRx() {
+        return rx;
+    }
+
+    public long getTx() {
+        return tx;
+    }
+
+    public int getMcuTemperature() {
+        return mcuTemperature;
+    }
+
+    @Override
+    public int packetType() {
+        return TYPE;
+    }
+
+    @Override
+    protected int packetLength() {
+        return 14;
+    }
+
+    @Override
+    protected void parsePacket(ByteBuffer bytes) {
+        signal = FIELD_SIGNAL.value(bytes);
+        rx = FIELD_RX.value(bytes);
+        tx = FIELD_TX.value(bytes);
+        mcuTemperature = FIELD_TEMP.value(bytes);
+    }
+
+    @Override
+    protected ByteBuffer packetBytes() {
+        return ByteBuffer.allocate(packetLength()).put(FIELD_SIGNAL.bytes(signal)).put(FIELD_RX.bytes(rx))
+                .put(FIELD_TX.bytes(tx)).put(FIELD_TEMP.bytes(mcuTemperature));
+    }
+
+    @Override
+    public int[] expectedResponses() {
+        return new int[] {};
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/StateZoneResponse.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/StateZoneResponse.java
new file mode 100644 (file)
index 0000000..26eaf28
--- /dev/null
@@ -0,0 +1,81 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import java.nio.ByteBuffer;
+
+import org.openhab.binding.lifx.internal.fields.Field;
+import org.openhab.binding.lifx.internal.fields.HSBK;
+import org.openhab.binding.lifx.internal.fields.HSBKField;
+import org.openhab.binding.lifx.internal.fields.UInt8Field;
+
+/**
+ * @author Wouter Born - Initial contribution
+ */
+public class StateZoneResponse extends Packet {
+
+    public static final int TYPE = 0x1F7;
+
+    public static final Field<Integer> FIELD_COUNT = new UInt8Field();
+    public static final Field<Integer> FIELD_INDEX = new UInt8Field();
+    public static final HSBKField FIELD_COLOR = new HSBKField();
+
+    private int count;
+    private int index;
+    private HSBK color;
+
+    @Override
+    public String toString() {
+        return "count=" + count + ", index=" + index + ", " + color.toString("color");
+    }
+
+    public int getCount() {
+        return count;
+    }
+
+    public int getIndex() {
+        return index;
+    }
+
+    public HSBK getColor() {
+        return color;
+    }
+
+    @Override
+    public int packetType() {
+        return TYPE;
+    }
+
+    @Override
+    protected int packetLength() {
+        return 10;
+    }
+
+    @Override
+    protected void parsePacket(ByteBuffer bytes) {
+        count = FIELD_COUNT.value(bytes);
+        index = FIELD_INDEX.value(bytes);
+        color = FIELD_COLOR.value(bytes);
+    }
+
+    @Override
+    protected ByteBuffer packetBytes() {
+        return ByteBuffer.allocate(packetLength()).put(FIELD_COUNT.bytes(count)).put(FIELD_INDEX.bytes(index))
+                .put(FIELD_COLOR.bytes(color));
+    }
+
+    @Override
+    public int[] expectedResponses() {
+        return new int[] {};
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/TagLabelsResponse.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/TagLabelsResponse.java
new file mode 100644 (file)
index 0000000..5ecd16b
--- /dev/null
@@ -0,0 +1,68 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import java.nio.ByteBuffer;
+
+import org.openhab.binding.lifx.internal.fields.Field;
+import org.openhab.binding.lifx.internal.fields.StringField;
+import org.openhab.binding.lifx.internal.fields.UInt64Field;
+
+/**
+ * @author Tim Buckley - Initial contribution
+ * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
+ */
+public class TagLabelsResponse extends Packet {
+
+    public static final int TYPE = 0x1F;
+
+    public static final Field<Long> FIELD_TAGS = new UInt64Field();
+    public static final Field<String> FIELD_LABEL = new StringField(32).utf8();
+
+    private long tags;
+    private String label;
+
+    public long getTags() {
+        return tags;
+    }
+
+    public String getLabel() {
+        return label;
+    }
+
+    @Override
+    public int packetType() {
+        return TYPE;
+    }
+
+    @Override
+    protected int packetLength() {
+        return 40;
+    }
+
+    @Override
+    protected void parsePacket(ByteBuffer bytes) {
+        tags = FIELD_TAGS.value(bytes);
+        label = FIELD_LABEL.value(bytes);
+    }
+
+    @Override
+    protected ByteBuffer packetBytes() {
+        return ByteBuffer.allocate(packetLength()).put(FIELD_TAGS.bytes(tags)).put(FIELD_LABEL.bytes(label));
+    }
+
+    @Override
+    public int[] expectedResponses() {
+        return new int[] {};
+    }
+}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/TagsResponse.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/dto/TagsResponse.java
new file mode 100644 (file)
index 0000000..104ad08
--- /dev/null
@@ -0,0 +1,60 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.dto;
+
+import java.nio.ByteBuffer;
+
+import org.openhab.binding.lifx.internal.fields.Field;
+import org.openhab.binding.lifx.internal.fields.UInt64Field;
+
+/**
+ * @author Tim Buckley - Initial contribution
+ * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
+ */
+public class TagsResponse extends Packet {
+
+    public static final int TYPE = 0x1C;
+
+    public static final Field<Long> FIELD_TAGS = new UInt64Field();
+
+    private long tags;
+
+    public long getTags() {
+        return tags;
+    }
+
+    @Override
+    public int packetType() {
+        return TYPE;
+    }
+
+    @Override
+    protected int packetLength() {
+        return 8;
+    }
+
+    @Override
+    protected void parsePacket(ByteBuffer bytes) {
+        tags = FIELD_TAGS.value(bytes);
+    }
+
+    @Override
+    protected ByteBuffer packetBytes() {
+        return ByteBuffer.allocate(packetLength()).put(FIELD_TAGS.bytes(tags));
+    }
+
+    @Override
+    public int[] expectedResponses() {
+        return new int[] {};
+    }
+}
index 29418f3263a4e10be0ed71e04a72e787388259e7..5649a32d81e6f90af090e52fb0a2d08f3b6dc3e7 100644 (file)
@@ -17,7 +17,7 @@ import java.nio.ByteBuffer;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 
 /**
- * @author Tim Buckley
+ * @author Tim Buckley - Initial contribution
  */
 @NonNullByDefault
 public class ByteField extends Field<ByteBuffer> {
index e2bcc7d9e6407cd8bbd8cc0456330889ee1320f2..1a1ae2c92c49a6e42bbb92c947ba7f023cd6a335 100644 (file)
@@ -22,7 +22,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
  *
  * @param <T> the field datatype
  *
- * @author Tim Buckley
+ * @author Tim Buckley - Initial contribution
  */
 @NonNullByDefault
 public abstract class Field<T> {
index 7e29fd58190257e6d6f32e7e383cbd6794c08d6f..ffb7bd40f09d8d9de283a5d5c2a1dc0e0c0f952c 100644 (file)
@@ -17,7 +17,7 @@ import java.nio.ByteBuffer;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 
 /**
- * @author Tim Buckley
+ * @author Tim Buckley - Initial contribution
  */
 @NonNullByDefault
 public class FloatField extends Field<Float> {
index e31629cbfa158783f31942dfd3e0990970cd4054..23885500c6d438a8d71e535c4d71f72fabaf137f 100644 (file)
@@ -21,7 +21,7 @@ import org.openhab.core.library.types.HSBType;
 import org.openhab.core.library.types.PercentType;
 
 /**
- * @author Wouter Born - Add support for MultiZone light control
+ * @author Wouter Born - Initial contribution
  */
 @NonNullByDefault
 public class HSBK {
index c254f4bdb7919d13886e30420f8e91176040bca9..75d1e167019ef9c51cdd0887ded474a63146529a 100644 (file)
@@ -17,7 +17,7 @@ import java.nio.ByteBuffer;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 
 /**
- * @author Wouter Born - Add support for MultiZone light control
+ * @author Wouter Born - Initial contribution
  */
 @NonNullByDefault
 public class HSBKField extends Field<HSBK> {
index 8dfcb257f42ecd5a40f8455b1c4744c82c0b3011..5352491dfec37a4821c5a2db2b140ca08813f94b 100644 (file)
@@ -19,7 +19,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
 /**
  * Reads a wrapped field in reversed byte order.
  *
- * @author Tim Buckley
+ * @author Tim Buckley - Initial contribution
  */
 @NonNullByDefault
 public class LittleField<T> extends Field<T> {
index bfce15f8014186481d5428a497830f55fed0147e..91190f4242b4283e53fd98ff7ad6a5717169db30 100644 (file)
  */
 package org.openhab.binding.lifx.internal.fields;
 
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
 import java.nio.ByteBuffer;
-import java.util.Arrays;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Objects;
 
-import org.apache.commons.lang.StringUtils;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.openhab.core.util.HexUtils;
 
 /**
- * @author Tim Buckley
- * @author Karel Goderis
+ * @author Tim Buckley - Initial contribution
+ * @author Karel Goderis - Initial contribution
  */
 @NonNullByDefault
 public class MACAddress {
 
-    public static final MACAddress BROADCAST_ADDRESS = new MACAddress("000000000000", true);
-
-    private final Logger logger = LoggerFactory.getLogger(MACAddress.class);
+    public static final MACAddress BROADCAST_ADDRESS = new MACAddress("000000000000");
 
     private ByteBuffer bytes;
     private String hex = "";
@@ -54,28 +47,10 @@ public class MACAddress {
         createHex();
     }
 
-    public MACAddress(String string, boolean isHex) {
-        if (!isHex) {
-            this.bytes = ByteBuffer.wrap(string.getBytes());
-            createHex();
-        } else {
-            this.bytes = ByteBuffer.wrap(parseHexBinary(string));
-
-            try {
-                formatHex(string, 2, ":");
-            } catch (IOException e) {
-                logger.error("An exception occurred while formatting an HEX string : '{}'", e.getMessage());
-            }
-        }
-    }
-
-    private byte[] parseHexBinary(String s) {
-        int len = s.length();
-        byte[] data = new byte[len / 2];
-        for (int i = 0; i < len; i += 2) {
-            data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s.charAt(i + 1), 16));
-        }
-        return data;
+    public MACAddress(String string) {
+        byte[] byteArray = HexUtils.hexToBytes(string);
+        this.bytes = ByteBuffer.wrap(byteArray);
+        this.hex = HexUtils.bytesToHex(byteArray, ":");
     }
 
     public MACAddress() {
@@ -90,7 +65,7 @@ public class MACAddress {
             byteStrings.add(String.format("%02X", bytes.get()));
         }
 
-        hex = StringUtils.join(byteStrings, ':');
+        hex = String.join(":", byteStrings);
 
         bytes.rewind();
     }
@@ -108,21 +83,6 @@ public class MACAddress {
         return hex.toString();
     }
 
-    private void formatHex(String original, int length, String separator) throws IOException {
-        ByteArrayInputStream bis = new ByteArrayInputStream(original.getBytes());
-        byte[] buffer = new byte[length];
-        String result = "";
-        while (bis.read(buffer) > 0) {
-            for (byte b : buffer) {
-                result += (char) b;
-            }
-            Arrays.fill(buffer, (byte) 0);
-            result += separator;
-        }
-
-        hex = StringUtils.left(result, result.length() - 1);
-    }
-
     @Override
     public int hashCode() {
         int hash = 7;
index 417348cb71e05b705f7d717d2696bc226c336436..57471120c027948005b1a3b62c2c8eed4612c740 100644 (file)
@@ -17,8 +17,8 @@ import java.nio.ByteBuffer;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 
 /**
- * @author Tim Buckley
- * @author Karel Goderis
+ * @author Tim Buckley - Initial contribution
+ * @author Karel Goderis - Initial contribution
  */
 @NonNullByDefault
 public class MACAddressField extends Field<MACAddress> {
index 360ceb28161264362d69a64f453db96c5dbcab45..0184d65c09ee009e65d263b219b431cf50be017f 100644 (file)
@@ -19,7 +19,7 @@ import java.nio.charset.StandardCharsets;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 
 /**
- * @author Tim Buckley
+ * @author Tim Buckley - Initial contribution
  */
 @NonNullByDefault
 public class StringField extends Field<String> {
index 3cdcb44c28bbeeb8546f9085c91b93318d8acae1..a9c65d2e53008fae59cfc8f970aeb39128e8a6f2 100644 (file)
@@ -17,7 +17,7 @@ import java.nio.ByteBuffer;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 
 /**
- * @author Tim Buckley
+ * @author Tim Buckley - Initial contribution
  */
 @NonNullByDefault
 public class UInt16Field extends Field<Integer> {
index 04b9d7acbee7bc5e1fabb9a31f295e7539f74a25..89ce6fb8828e715fea3e2a96e4dc3c7ca463d0ac 100644 (file)
@@ -17,7 +17,7 @@ import java.nio.ByteBuffer;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 
 /**
- * @author Tim Buckley
+ * @author Tim Buckley - Initial contribution
  */
 @NonNullByDefault
 public class UInt32Field extends Field<Long> {
index bfc229a4dd3549d5b923b18424bdbc65821154af..b72ef6b2db74818293388f1eaf3b8a0cb954f5b5 100644 (file)
@@ -21,7 +21,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
  * unexpected values will likely be shown if exposed to users. Most bit-level
  * operations should still work (addition, multiplication, shifting, etc).
  *
- * @author Tim Buckley
+ * @author Tim Buckley - Initial contribution
  */
 @NonNullByDefault
 public class UInt64Field extends Field<Long> {
index 23ba2353bde727b3f3dd4187ad59ff8a3e269a9f..969c468061fe6683bab51c8294dd2623a57e2835 100644 (file)
@@ -17,7 +17,7 @@ import java.nio.ByteBuffer;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 
 /**
- * @author Tim Buckley
+ * @author Tim Buckley - Initial contribution
  */
 @NonNullByDefault
 public class UInt8Field extends Field<Integer> {
index 559bae30ecac8c6d3d2b3cd2a93678e8b994382d..3d53df7703c92d87a9552d28e22821b58b052868 100644 (file)
@@ -15,7 +15,7 @@ package org.openhab.binding.lifx.internal.fields;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 
 /**
- * @author Wouter Born - Add Thing properties
+ * @author Wouter Born - Initial contribution
  */
 @NonNullByDefault
 public class Version {
index 7cec7a8e96adde3b50db55c13bd609a63ceb1211..26af5382c6a6157928275eb67c721d390c972e88 100644 (file)
@@ -17,7 +17,7 @@ import java.nio.ByteBuffer;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 
 /**
- * @author Wouter Born - Add Thing properties
+ * @author Wouter Born - Initial contribution
  */
 @NonNullByDefault
 public class VersionField extends Field<Version> {
index af941d2f9669214988bf6f377d239ef5443420b4..812371394eaf77d5f54d278f2f1d05cc97fa7ab4 100644 (file)
@@ -13,7 +13,7 @@
 package org.openhab.binding.lifx.internal.handler;
 
 import static org.openhab.binding.lifx.internal.LifxBindingConstants.*;
-import static org.openhab.binding.lifx.internal.protocol.Product.Feature.*;
+import static org.openhab.binding.lifx.internal.LifxProduct.Feature.*;
 import static org.openhab.binding.lifx.internal.util.LifxMessageUtil.*;
 
 import java.net.InetSocketAddress;
@@ -38,18 +38,18 @@ import org.openhab.binding.lifx.internal.LifxLightOnlineStateUpdater;
 import org.openhab.binding.lifx.internal.LifxLightPropertiesUpdater;
 import org.openhab.binding.lifx.internal.LifxLightState;
 import org.openhab.binding.lifx.internal.LifxLightStateChanger;
+import org.openhab.binding.lifx.internal.LifxProduct;
+import org.openhab.binding.lifx.internal.dto.Effect;
+import org.openhab.binding.lifx.internal.dto.GetLightInfraredRequest;
+import org.openhab.binding.lifx.internal.dto.GetLightPowerRequest;
+import org.openhab.binding.lifx.internal.dto.GetRequest;
+import org.openhab.binding.lifx.internal.dto.GetTileEffectRequest;
+import org.openhab.binding.lifx.internal.dto.GetWifiInfoRequest;
+import org.openhab.binding.lifx.internal.dto.Packet;
+import org.openhab.binding.lifx.internal.dto.PowerState;
+import org.openhab.binding.lifx.internal.dto.SignalStrength;
 import org.openhab.binding.lifx.internal.fields.HSBK;
 import org.openhab.binding.lifx.internal.fields.MACAddress;
-import org.openhab.binding.lifx.internal.protocol.Effect;
-import org.openhab.binding.lifx.internal.protocol.GetLightInfraredRequest;
-import org.openhab.binding.lifx.internal.protocol.GetLightPowerRequest;
-import org.openhab.binding.lifx.internal.protocol.GetRequest;
-import org.openhab.binding.lifx.internal.protocol.GetTileEffectRequest;
-import org.openhab.binding.lifx.internal.protocol.GetWifiInfoRequest;
-import org.openhab.binding.lifx.internal.protocol.Packet;
-import org.openhab.binding.lifx.internal.protocol.PowerState;
-import org.openhab.binding.lifx.internal.protocol.Product;
-import org.openhab.binding.lifx.internal.protocol.SignalStrength;
 import org.openhab.core.config.core.Configuration;
 import org.openhab.core.library.types.DecimalType;
 import org.openhab.core.library.types.HSBType;
@@ -90,7 +90,7 @@ public class LifxLightHandler extends BaseThingHandler {
     private static final Duration MAX_STATE_CHANGE_DURATION = Duration.ofSeconds(4);
 
     private final LifxChannelFactory channelFactory;
-    private @NonNullByDefault({}) Product product;
+    private @NonNullByDefault({}) LifxProduct product;
 
     private @Nullable PercentType powerOnBrightness;
     private @Nullable HSBType powerOnColor;
@@ -405,10 +405,10 @@ public class LifxLightHandler extends BaseThingHandler {
         return speed == null ? null : new Double(speed.toString());
     }
 
-    private Product getProduct() {
+    private LifxProduct getProduct() {
         Object propertyValue = getThing().getProperties().get(LifxBindingConstants.PROPERTY_PRODUCT_ID);
         if (propertyValue == null) {
-            return Product.getLikelyProduct(getThing().getThingTypeUID());
+            return LifxProduct.getLikelyProduct(getThing().getThingTypeUID());
         }
         try {
             // Without first conversion to double, on a very first thing creation from discovery inbox,
@@ -416,9 +416,9 @@ public class LifxLightHandler extends BaseThingHandler {
             // (e.g. 50.0 instead of 50)
             Double d = Double.parseDouble((String) propertyValue);
             long productID = d.longValue();
-            return Product.getProductFromProductID(productID);
+            return LifxProduct.getProductFromProductID(productID);
         } catch (IllegalArgumentException e) {
-            return Product.getLikelyProduct(getThing().getThingTypeUID());
+            return LifxProduct.getLikelyProduct(getThing().getThingTypeUID());
         }
     }
 
index 68b7c460aaf7c8516cecd15ba1f2d41cb6287e0e..fab89fa7f1984f881271dfc71f8c33a01ccb5c3d 100644 (file)
@@ -15,10 +15,10 @@ package org.openhab.binding.lifx.internal.listener;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.openhab.binding.lifx.internal.LifxLightState;
+import org.openhab.binding.lifx.internal.dto.Effect;
+import org.openhab.binding.lifx.internal.dto.PowerState;
+import org.openhab.binding.lifx.internal.dto.SignalStrength;
 import org.openhab.binding.lifx.internal.fields.HSBK;
-import org.openhab.binding.lifx.internal.protocol.Effect;
-import org.openhab.binding.lifx.internal.protocol.PowerState;
-import org.openhab.binding.lifx.internal.protocol.SignalStrength;
 import org.openhab.core.library.types.PercentType;
 
 /**
index 8909ee73bf35652ae712914f5163694b9fe42ec7..c4dedcdea3e0a5592527314d04ddb781baee4b96 100644 (file)
@@ -21,7 +21,7 @@ import org.openhab.binding.lifx.internal.LifxLightPropertiesUpdater;
  * The {@link LifxPropertiesUpdateListener} is notified when the {@link LifxLightPropertiesUpdater} has
  * updated light properties.
  *
- * @author Wouter Born - Update light properties when online
+ * @author Wouter Born - Initial contribution
  */
 @NonNullByDefault
 public interface LifxPropertiesUpdateListener {
index fa622f6e64b22170c5ea3cb500e8cd22ddefa647..10396ac5e8964baeddb579209b208691f8cb14dd 100644 (file)
@@ -14,7 +14,7 @@ package org.openhab.binding.lifx.internal.listener;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.openhab.binding.lifx.internal.LifxLightCommunicationHandler;
-import org.openhab.binding.lifx.internal.protocol.Packet;
+import org.openhab.binding.lifx.internal.dto.Packet;
 
 /**
  * The {@link LifxResponsePacketListener} is notified when the {@link LifxLightCommunicationHandler} receives a response
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/AcknowledgementResponse.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/AcknowledgementResponse.java
deleted file mode 100644 (file)
index 79eb578..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import java.nio.ByteBuffer;
-
-/**
- * @author Tim Buckley - Initial Contribution
- * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
- */
-public class AcknowledgementResponse extends Packet {
-
-    public static final int TYPE = 0x2D;
-
-    public AcknowledgementResponse() {
-    }
-
-    @Override
-    public int packetType() {
-        return TYPE;
-    }
-
-    @Override
-    protected int packetLength() {
-        return 0;
-    }
-
-    @Override
-    protected void parsePacket(ByteBuffer bytes) {
-        // do nothing
-    }
-
-    @Override
-    protected ByteBuffer packetBytes() {
-        return ByteBuffer.allocate(0);
-    }
-
-    @Override
-    public int[] expectedResponses() {
-        return new int[] {};
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/ApplicationRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/ApplicationRequest.java
deleted file mode 100644 (file)
index 233cfde..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-/**
- * @author Wouter Born - Add support for MultiZone light control
- */
-public enum ApplicationRequest {
-
-    /**
-     * Don't apply the requested changes until a message with APPLY or APPLY_ONLY is sent.
-     */
-    NO_APPLY(0x00),
-
-    /**
-     * Apply the changes immediately and apply any pending changes.
-     */
-    APPLY(0x01),
-
-    /**
-     * Ignore the requested changes in this message and only apply pending changes.
-     */
-    APPLY_ONLY(0x02);
-
-    private final int value;
-
-    private ApplicationRequest(int value) {
-        this.value = value;
-    }
-
-    /**
-     * Gets the integer value of this application request.
-     *
-     * @return the integer value
-     */
-    public int getValue() {
-        return value;
-    }
-
-    /**
-     * Returns the {@link ApplicationRequest} for the given integer value.
-     *
-     * @param value the integer value
-     * @return the {@link ApplicationRequest} or <code>null</code>, if no {@link ApplicationRequest} exists for the
-     *         given value
-     */
-    public static ApplicationRequest fromValue(int value) {
-        for (ApplicationRequest ar : values()) {
-            if (ar.getValue() == value) {
-                return ar;
-            }
-        }
-
-        return null;
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/EchoRequestResponse.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/EchoRequestResponse.java
deleted file mode 100644 (file)
index 8ea7522..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import java.nio.ByteBuffer;
-
-import org.openhab.binding.lifx.internal.fields.ByteField;
-import org.openhab.binding.lifx.internal.fields.Field;
-
-/**
- * @author Tim Buckley - Initial Contribution
- * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
- */
-public class EchoRequestResponse extends Packet {
-
-    public static final int TYPE = 0x3B;
-
-    public static final Field<ByteBuffer> FIELD_PAYLOAD = new ByteField(64);
-
-    private ByteBuffer payload;
-
-    public EchoRequestResponse() {
-    }
-
-    public ByteBuffer getPayload() {
-        return payload;
-    }
-
-    public void setPayload(ByteBuffer location) {
-        this.payload = location;
-    }
-
-    @Override
-    public int packetType() {
-        return TYPE;
-    }
-
-    @Override
-    protected int packetLength() {
-        return 64;
-    }
-
-    @Override
-    protected void parsePacket(ByteBuffer bytes) {
-        payload = FIELD_PAYLOAD.value(bytes);
-    }
-
-    @Override
-    protected ByteBuffer packetBytes() {
-        return ByteBuffer.allocate(packetLength()).put(FIELD_PAYLOAD.bytes(payload));
-    }
-
-    @Override
-    public int[] expectedResponses() {
-        return new int[] {};
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/Effect.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/Effect.java
deleted file mode 100644 (file)
index 73f9d64..0000000
+++ /dev/null
@@ -1,169 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import org.eclipse.jdt.annotation.NonNullByDefault;
-import org.eclipse.jdt.annotation.Nullable;
-import org.openhab.binding.lifx.internal.LifxBindingConstants;
-import org.openhab.binding.lifx.internal.fields.HSBK;
-
-/**
- * This class represents LIFX Tile effect
- *
- * @author Pawel Pieczul - initial contribution
- */
-@NonNullByDefault
-public class Effect {
-    public enum EffectType {
-        OFF(0),
-        MORPH(2),
-        FLAME(3);
-
-        Integer type;
-
-        EffectType(Integer type) {
-            this.type = type;
-        }
-
-        public static EffectType fromValue(Integer value) {
-            switch (value) {
-                case 0:
-                    return OFF;
-                case 2:
-                    return MORPH;
-                case 3:
-                    return FLAME;
-                default:
-                    throw new IllegalArgumentException("Unknown effect type");
-            }
-        }
-
-        public static EffectType fromValue(String value) {
-            if (LifxBindingConstants.CHANNEL_TYPE_EFFECT_OPTION_OFF.equals(value)) {
-                return OFF;
-            } else if (LifxBindingConstants.CHANNEL_TYPE_EFFECT_OPTION_MORPH.equals(value)) {
-                return MORPH;
-            } else if (LifxBindingConstants.CHANNEL_TYPE_EFFECT_OPTION_FLAME.equals(value)) {
-                return FLAME;
-            }
-            throw new IllegalArgumentException("Unknown effect type");
-        }
-
-        public Integer intValue() {
-            return type;
-        }
-
-        public String stringValue() {
-            switch (type) {
-                case 2:
-                    return LifxBindingConstants.CHANNEL_TYPE_EFFECT_OPTION_MORPH;
-                case 3:
-                    return LifxBindingConstants.CHANNEL_TYPE_EFFECT_OPTION_FLAME;
-                default:
-                    return LifxBindingConstants.CHANNEL_TYPE_EFFECT_OPTION_OFF;
-            }
-        }
-    }
-
-    final EffectType type;
-    final Long speed;
-    final Long duration;
-    final HSBK[] palette;
-
-    public EffectType getType() {
-        return type;
-    }
-
-    public Long getSpeed() {
-        return speed;
-    }
-
-    public Long getDuration() {
-        return duration;
-    }
-
-    HSBK[] getPalette() {
-        return palette;
-    }
-
-    public Effect(EffectType type, Long speed, Long duration, HSBK[] palette) {
-        this.type = type;
-        this.palette = palette;
-        this.duration = duration;
-        this.speed = speed;
-    }
-
-    public Effect(Integer type, Long speed, Long duration, HSBK[] palette) {
-        this(EffectType.fromValue(type), speed, duration, palette);
-    }
-
-    public Effect() {
-        this(EffectType.OFF, 3000L, 0L, new HSBK[0]);
-    }
-
-    public static Effect createDefault(String type, @Nullable Long morphSpeed, @Nullable Long flameSpeed) {
-        Long speed;
-        EffectType effectType = EffectType.fromValue(type);
-        switch (effectType) {
-            case OFF:
-                return new Effect(effectType, 0L, 0L, new HSBK[0]);
-            case MORPH:
-                if (morphSpeed == null) {
-                    speed = 3000L;
-                } else {
-                    speed = morphSpeed;
-                }
-                HSBK[] p = { new HSBK(0, 65535, 65535, 3500), new HSBK(7281, 65535, 65535, 3500),
-                        new HSBK(10922, 65535, 65535, 3500), new HSBK(22209, 65535, 65535, 3500),
-                        new HSBK(43507, 65535, 65535, 3500), new HSBK(49333, 65535, 65535, 3500),
-                        new HSBK(53520, 65535, 65535, 3500) };
-                return new Effect(effectType, speed, 0L, p);
-            case FLAME:
-                if (flameSpeed == null) {
-                    speed = 4000L;
-                } else {
-                    speed = flameSpeed;
-                }
-                return new Effect(effectType, speed, 0L, new HSBK[0]);
-            default:
-                throw new IllegalArgumentException("Unknown effect type");
-        }
-    }
-
-    @Override
-    public boolean equals(@Nullable Object o) {
-        if (this == o) {
-            return true;
-        }
-        if (o == null) {
-            return false;
-        }
-        if (o.getClass() != getClass()) {
-            return false;
-        }
-        Effect n = (Effect) o;
-        return n.getType().equals(this.getType()) && n.duration.equals(this.duration) && n.speed.equals(this.speed)
-                && n.palette == this.palette;
-    }
-
-    @Override
-    public int hashCode() {
-        Long hash = 1L;
-        int prime = 31;
-        hash = prime * hash + type.hashCode();
-        hash = prime * hash + duration;
-        hash = prime * hash + speed;
-        hash = prime * hash + palette.hashCode();
-        return hash.intValue();
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GenericHandler.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GenericHandler.java
deleted file mode 100644 (file)
index 13127f9..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
-import java.nio.ByteBuffer;
-
-import org.eclipse.jdt.annotation.NonNullByDefault;
-
-/**
- * A generic handler that dynamically creates "standard" packet instances.
- *
- * <p>
- * Packet types must have an empty constructor and cannot require any
- * additional logic (other than parsing).
- *
- * @param <T> the packet subtype this handler constructs
- *
- * @author Tim Buckley - Initial Contribution
- * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
- */
-@NonNullByDefault
-public class GenericHandler<T extends Packet> implements PacketHandler<T> {
-
-    private Constructor<T> constructor;
-
-    private boolean typeFound;
-    private int type;
-
-    public boolean isTypeFound() {
-        return typeFound;
-    }
-
-    public int getType() {
-        return type;
-    }
-
-    public GenericHandler(Class<T> clazz) {
-        try {
-            constructor = clazz.getConstructor();
-        } catch (NoSuchMethodException ex) {
-            throw new IllegalArgumentException("Packet class cannot be handled by GenericHandler", ex);
-        }
-
-        try {
-            Field typeField = clazz.getField("TYPE");
-            type = (int) typeField.get(null);
-            typeFound = true;
-        } catch (NoSuchFieldException | IllegalAccessException ex) {
-            // silently ignore
-            typeFound = false;
-        }
-    }
-
-    @Override
-    public T handle(ByteBuffer buf) {
-        try {
-            T ret = constructor.newInstance();
-            ret.parse(buf);
-            return ret;
-        } catch (ReflectiveOperationException ex) {
-            throw new IllegalArgumentException("Unable to instantiate empty packet", ex);
-        }
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GenericPacket.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GenericPacket.java
deleted file mode 100644 (file)
index 4966796..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import java.nio.ByteBuffer;
-
-/**
- * @author Tim Buckley - Initial Contribution
- * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
- */
-public class GenericPacket extends Packet {
-
-    @Override
-    public int packetType() {
-        return 0;
-    }
-
-    @Override
-    protected int packetLength() {
-        return 0;
-    }
-
-    @Override
-    protected void parsePacket(ByteBuffer bytes) {
-    }
-
-    @Override
-    protected ByteBuffer packetBytes() {
-        return ByteBuffer.allocate(0);
-    }
-
-    @Override
-    public int[] expectedResponses() {
-        return new int[] {};
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetColorZonesRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetColorZonesRequest.java
deleted file mode 100644 (file)
index c535154..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import static org.openhab.binding.lifx.internal.LifxBindingConstants.*;
-
-import java.nio.ByteBuffer;
-
-import org.openhab.binding.lifx.internal.fields.Field;
-import org.openhab.binding.lifx.internal.fields.UInt8Field;
-
-/**
- * @author Wouter Born - Add support for MultiZone light control
- */
-public class GetColorZonesRequest extends Packet {
-
-    public static final int TYPE = 0x1F6;
-
-    public static final Field<Integer> FIELD_START_INDEX = new UInt8Field();
-    public static final Field<Integer> FIELD_END_INDEX = new UInt8Field();
-
-    private int startIndex = MIN_ZONE_INDEX;
-    private int endIndex = MAX_ZONE_INDEX;
-
-    public GetColorZonesRequest() {
-        setTagged(false);
-        setAddressable(true);
-        setResponseRequired(true);
-    }
-
-    public GetColorZonesRequest(int index) {
-        this(index, index);
-    }
-
-    public GetColorZonesRequest(int startIndex, int endIndex) {
-        this();
-        this.startIndex = startIndex;
-        this.endIndex = endIndex;
-    }
-
-    public int getStartIndex() {
-        return startIndex;
-    }
-
-    public int getEndIndex() {
-        return endIndex;
-    }
-
-    @Override
-    public int packetType() {
-        return TYPE;
-    }
-
-    @Override
-    protected int packetLength() {
-        return 2;
-    }
-
-    @Override
-    protected void parsePacket(ByteBuffer bytes) {
-        startIndex = FIELD_START_INDEX.value(bytes);
-        endIndex = FIELD_END_INDEX.value(bytes);
-    }
-
-    @Override
-    protected ByteBuffer packetBytes() {
-        return ByteBuffer.allocate(packetLength()).put(FIELD_START_INDEX.bytes(startIndex))
-                .put(FIELD_END_INDEX.bytes(endIndex));
-    }
-
-    @Override
-    public int[] expectedResponses() {
-        return new int[] { StateMultiZoneResponse.TYPE, StateZoneResponse.TYPE };
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetEchoRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetEchoRequest.java
deleted file mode 100644 (file)
index 43b0fc2..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import java.nio.ByteBuffer;
-
-import org.openhab.binding.lifx.internal.fields.ByteField;
-import org.openhab.binding.lifx.internal.fields.Field;
-
-/**
- * @author Tim Buckley - Initial Contribution
- * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
- */
-public class GetEchoRequest extends Packet {
-
-    public static final int TYPE = 0x3A;
-
-    public static final Field<ByteBuffer> FIELD_PAYLOAD = new ByteField(64);
-
-    private ByteBuffer payload;
-
-    public GetEchoRequest() {
-        setTagged(false);
-        setAddressable(true);
-        setResponseRequired(true);
-    }
-
-    public ByteBuffer getPayload() {
-        return payload;
-    }
-
-    public void setPayload(ByteBuffer payload) {
-        this.payload = payload;
-    }
-
-    @Override
-    public int packetType() {
-        return TYPE;
-    }
-
-    @Override
-    protected int packetLength() {
-        return 64;
-    }
-
-    @Override
-    protected void parsePacket(ByteBuffer bytes) {
-        // do nothing
-    }
-
-    @Override
-    protected ByteBuffer packetBytes() {
-        return ByteBuffer.allocate(packetLength()).put(FIELD_PAYLOAD.bytes(payload));
-    }
-
-    @Override
-    public int[] expectedResponses() {
-        return new int[] { EchoRequestResponse.TYPE };
-    }
-
-    public static GetEchoRequest currentTimeEchoRequest() {
-        ByteBuffer payload = ByteBuffer.allocate(Long.SIZE / 8);
-        payload.putLong(System.currentTimeMillis());
-
-        GetEchoRequest request = new GetEchoRequest();
-        request.setResponseRequired(true);
-        request.setPayload(payload);
-        return request;
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetGroupRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetGroupRequest.java
deleted file mode 100644 (file)
index 8bb6cf2..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import java.nio.ByteBuffer;
-
-/**
- * @author Tim Buckley - Initial Contribution
- * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
- */
-public class GetGroupRequest extends Packet {
-
-    public static final int TYPE = 0x33;
-
-    public GetGroupRequest() {
-        setTagged(false);
-        setAddressable(true);
-        setResponseRequired(true);
-    }
-
-    @Override
-    public int packetType() {
-        return TYPE;
-    }
-
-    @Override
-    protected int packetLength() {
-        return 0;
-    }
-
-    @Override
-    protected void parsePacket(ByteBuffer bytes) {
-        // do nothing
-    }
-
-    @Override
-    protected ByteBuffer packetBytes() {
-        return ByteBuffer.allocate(0);
-    }
-
-    @Override
-    public int[] expectedResponses() {
-        return new int[] { StateGroupResponse.TYPE };
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetHostFirmwareRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetHostFirmwareRequest.java
deleted file mode 100644 (file)
index 9905cec..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import java.nio.ByteBuffer;
-
-/**
- * @author Tim Buckley - Initial Contribution
- * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
- */
-public class GetHostFirmwareRequest extends Packet {
-
-    public static final int TYPE = 0x0E;
-
-    public GetHostFirmwareRequest() {
-        setTagged(false);
-        setAddressable(true);
-        setResponseRequired(true);
-    }
-
-    @Override
-    public int packetType() {
-        return TYPE;
-    }
-
-    @Override
-    protected int packetLength() {
-        return 0;
-    }
-
-    @Override
-    protected void parsePacket(ByteBuffer bytes) {
-        // do nothing
-    }
-
-    @Override
-    protected ByteBuffer packetBytes() {
-        return ByteBuffer.allocate(0);
-    }
-
-    @Override
-    public int[] expectedResponses() {
-        return new int[] { StateHostFirmwareResponse.TYPE };
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetHostInfoRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetHostInfoRequest.java
deleted file mode 100644 (file)
index 290c934..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import java.nio.ByteBuffer;
-
-/**
- * @author Tim Buckley - Initial Contribution
- * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
- */
-public class GetHostInfoRequest extends Packet {
-
-    public static final int TYPE = 0x0C;
-
-    public GetHostInfoRequest() {
-        setTagged(false);
-        setAddressable(true);
-        setResponseRequired(true);
-    }
-
-    @Override
-    public int packetType() {
-        return TYPE;
-    }
-
-    @Override
-    protected int packetLength() {
-        return 0;
-    }
-
-    @Override
-    protected void parsePacket(ByteBuffer bytes) {
-        // do nothing
-    }
-
-    @Override
-    protected ByteBuffer packetBytes() {
-        return ByteBuffer.allocate(0);
-    }
-
-    @Override
-    public int[] expectedResponses() {
-        return new int[] { StateHostInfoResponse.TYPE };
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetInfoRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetInfoRequest.java
deleted file mode 100644 (file)
index 33e830f..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import java.nio.ByteBuffer;
-
-/**
- * @author Tim Buckley - Initial Contribution
- * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
- */
-public class GetInfoRequest extends Packet {
-
-    public static final int TYPE = 0x22;
-
-    public GetInfoRequest() {
-        setTagged(false);
-        setAddressable(true);
-        setResponseRequired(true);
-    }
-
-    @Override
-    public int packetType() {
-        return TYPE;
-    }
-
-    @Override
-    protected int packetLength() {
-        return 0;
-    }
-
-    @Override
-    protected void parsePacket(ByteBuffer bytes) {
-        // do nothing
-    }
-
-    @Override
-    protected ByteBuffer packetBytes() {
-        return ByteBuffer.allocate(0);
-    }
-
-    @Override
-    public int[] expectedResponses() {
-        return new int[] { StateInfoResponse.TYPE };
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetLabelRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetLabelRequest.java
deleted file mode 100644 (file)
index 20d6b5a..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import java.nio.ByteBuffer;
-
-/**
- * @author Tim Buckley - Initial Contribution
- * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
- */
-public class GetLabelRequest extends Packet {
-
-    public static final int TYPE = 0x17;
-
-    public GetLabelRequest() {
-        setTagged(false);
-        setAddressable(true);
-        setResponseRequired(true);
-    }
-
-    @Override
-    public int packetType() {
-        return TYPE;
-    }
-
-    @Override
-    protected int packetLength() {
-        return 0;
-    }
-
-    @Override
-    protected void parsePacket(ByteBuffer bytes) {
-        // do nothing
-    }
-
-    @Override
-    protected ByteBuffer packetBytes() {
-        return ByteBuffer.allocate(0);
-    }
-
-    @Override
-    public int[] expectedResponses() {
-        return new int[] { StateLabelResponse.TYPE };
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetLightInfraredRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetLightInfraredRequest.java
deleted file mode 100644 (file)
index 1297026..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import java.nio.ByteBuffer;
-
-/**
- * @author Wouter Born - Support LIFX 2016 product line-up and infrared functionality
- */
-public class GetLightInfraredRequest extends Packet {
-
-    public static final int TYPE = 0x78;
-
-    public GetLightInfraredRequest() {
-        setTagged(false);
-        setAddressable(true);
-        setResponseRequired(true);
-    }
-
-    @Override
-    public int packetType() {
-        return TYPE;
-    }
-
-    @Override
-    protected int packetLength() {
-        return 0;
-    }
-
-    @Override
-    protected void parsePacket(ByteBuffer bytes) {
-        // do nothing
-    }
-
-    @Override
-    protected ByteBuffer packetBytes() {
-        return ByteBuffer.allocate(0);
-    }
-
-    @Override
-    public int[] expectedResponses() {
-        return new int[] { StateLightInfraredResponse.TYPE };
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetLightPowerRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetLightPowerRequest.java
deleted file mode 100644 (file)
index d8853b7..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import java.nio.ByteBuffer;
-
-/**
- * @author Tim Buckley - Initial Contribution
- * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
- */
-public class GetLightPowerRequest extends Packet {
-
-    public static final int TYPE = 0x74;
-
-    public GetLightPowerRequest() {
-        setTagged(false);
-        setAddressable(true);
-        setResponseRequired(true);
-    }
-
-    @Override
-    public int packetType() {
-        return TYPE;
-    }
-
-    @Override
-    protected int packetLength() {
-        return 0;
-    }
-
-    @Override
-    protected void parsePacket(ByteBuffer bytes) {
-        // do nothing
-    }
-
-    @Override
-    protected ByteBuffer packetBytes() {
-        return ByteBuffer.allocate(0);
-    }
-
-    @Override
-    public int[] expectedResponses() {
-        return new int[] { StateLightPowerResponse.TYPE };
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetLocationRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetLocationRequest.java
deleted file mode 100644 (file)
index abf7b83..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import java.nio.ByteBuffer;
-
-/**
- * @author Tim Buckley - Initial Contribution
- * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
- */
-public class GetLocationRequest extends Packet {
-
-    public static final int TYPE = 0x30;
-
-    public GetLocationRequest() {
-        setTagged(false);
-        setAddressable(true);
-        setResponseRequired(true);
-    }
-
-    @Override
-    public int packetType() {
-        return TYPE;
-    }
-
-    @Override
-    protected int packetLength() {
-        return 0;
-    }
-
-    @Override
-    protected void parsePacket(ByteBuffer bytes) {
-        // do nothing
-    }
-
-    @Override
-    protected ByteBuffer packetBytes() {
-        return ByteBuffer.allocate(0);
-    }
-
-    @Override
-    public int[] expectedResponses() {
-        return new int[] { StateLocationResponse.TYPE };
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetPowerRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetPowerRequest.java
deleted file mode 100644 (file)
index 6e09a2d..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import java.nio.ByteBuffer;
-
-/**
- * @author Tim Buckley - Initial Contribution
- * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
- */
-public class GetPowerRequest extends Packet {
-
-    public static final int TYPE = 0x14;
-
-    public GetPowerRequest() {
-        setTagged(false);
-        setAddressable(true);
-        setResponseRequired(true);
-    }
-
-    @Override
-    public int packetType() {
-        return TYPE;
-    }
-
-    @Override
-    protected int packetLength() {
-        return 0;
-    }
-
-    @Override
-    protected void parsePacket(ByteBuffer bytes) {
-        // do nothing
-    }
-
-    @Override
-    protected ByteBuffer packetBytes() {
-        return ByteBuffer.allocate(0);
-    }
-
-    @Override
-    public int[] expectedResponses() {
-        return new int[] { StatePowerResponse.TYPE };
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetRequest.java
deleted file mode 100644 (file)
index 3f11ae4..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import java.nio.ByteBuffer;
-
-/**
- * @author Tim Buckley - Initial Contribution
- * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
- */
-public class GetRequest extends Packet {
-
-    public static final int TYPE = 0x65;
-
-    public GetRequest() {
-        setTagged(false);
-        setAddressable(true);
-        setResponseRequired(true);
-    }
-
-    @Override
-    public int packetType() {
-        return TYPE;
-    }
-
-    @Override
-    protected int packetLength() {
-        return 0;
-    }
-
-    @Override
-    protected void parsePacket(ByteBuffer bytes) {
-        // do nothing
-    }
-
-    @Override
-    protected ByteBuffer packetBytes() {
-        return ByteBuffer.allocate(0);
-    }
-
-    @Override
-    public int[] expectedResponses() {
-        return new int[] { StateResponse.TYPE };
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetServiceRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetServiceRequest.java
deleted file mode 100644 (file)
index 400a19b..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import java.nio.ByteBuffer;
-
-/**
- * @author Tim Buckley - Initial Contribution
- * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
- */
-public class GetServiceRequest extends Packet {
-
-    public static final int TYPE = 0x02;
-
-    public GetServiceRequest() {
-        setTagged(true);
-        setAddressable(true);
-    }
-
-    @Override
-    public int packetLength() {
-        return 0;
-    }
-
-    @Override
-    public int packetType() {
-        return TYPE;
-    }
-
-    @Override
-    protected void parsePacket(ByteBuffer bytes) {
-        // empty
-    }
-
-    @Override
-    protected ByteBuffer packetBytes() {
-        return ByteBuffer.allocate(0);
-    }
-
-    @Override
-    public int[] expectedResponses() {
-        return new int[] { StateServiceResponse.TYPE };
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetTagLabelsRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetTagLabelsRequest.java
deleted file mode 100644 (file)
index 39aeb59..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import java.nio.ByteBuffer;
-
-import org.openhab.binding.lifx.internal.fields.Field;
-import org.openhab.binding.lifx.internal.fields.UInt64Field;
-
-/**
- * @author Tim Buckley - Initial Contribution
- * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
- */
-public class GetTagLabelsRequest extends Packet {
-
-    public static final int TYPE = 0x1D;
-
-    public static final Field<Long> FIELD_TAGS = new UInt64Field();
-
-    private long tags;
-
-    public long getTags() {
-        return tags;
-    }
-
-    public GetTagLabelsRequest() {
-    }
-
-    public GetTagLabelsRequest(long tags) {
-        this.tags = tags;
-    }
-
-    @Override
-    public int packetType() {
-        return TYPE;
-    }
-
-    @Override
-    protected int packetLength() {
-        return 8;
-    }
-
-    @Override
-    protected void parsePacket(ByteBuffer bytes) {
-        tags = FIELD_TAGS.value(bytes);
-    }
-
-    @Override
-    protected ByteBuffer packetBytes() {
-        return ByteBuffer.allocate(packetLength()).put(FIELD_TAGS.bytes(tags));
-    }
-
-    @Override
-    public int[] expectedResponses() {
-        return new int[] { TagLabelsResponse.TYPE };
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetTagsRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetTagsRequest.java
deleted file mode 100644 (file)
index 1b76a2d..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import java.nio.ByteBuffer;
-
-/**
- * @author Tim Buckley - Initial Contribution
- * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
- */
-public class GetTagsRequest extends Packet {
-
-    public static final int TYPE = 0x1A;
-
-    @Override
-    public int packetType() {
-        return TYPE;
-    }
-
-    @Override
-    protected int packetLength() {
-        return 0;
-    }
-
-    @Override
-    protected void parsePacket(ByteBuffer bytes) {
-        // do nothing
-    }
-
-    @Override
-    protected ByteBuffer packetBytes() {
-        return ByteBuffer.allocate(0);
-    }
-
-    @Override
-    public int[] expectedResponses() {
-        return new int[] { TagsResponse.TYPE };
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetTileEffectRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetTileEffectRequest.java
deleted file mode 100644 (file)
index afb4fa6..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import java.nio.ByteBuffer;
-
-/**
- * Implementation of GetTileEffect packet
- * 
- * @author Pawel Pieczul - Add support for Tile Effects
- */
-public class GetTileEffectRequest extends Packet {
-
-    public static final int TYPE = 0x2CE;
-
-    public GetTileEffectRequest() {
-        setTagged(false);
-        setAddressable(true);
-        setResponseRequired(true);
-    }
-
-    @Override
-    public int packetType() {
-        return TYPE;
-    }
-
-    @Override
-    protected int packetLength() {
-        return 0;
-    }
-
-    @Override
-    protected void parsePacket(ByteBuffer bytes) {
-        // do nothing
-    }
-
-    @Override
-    protected ByteBuffer packetBytes() {
-        return ByteBuffer.allocate(0);
-    }
-
-    @Override
-    public int[] expectedResponses() {
-        return new int[] { StateTileEffectResponse.TYPE };
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetVersionRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetVersionRequest.java
deleted file mode 100644 (file)
index 9e789f8..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import java.nio.ByteBuffer;
-
-/**
- * @author Tim Buckley - Initial Contribution
- * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
- */
-public class GetVersionRequest extends Packet {
-
-    public static final int TYPE = 0x20;
-
-    public GetVersionRequest() {
-        setTagged(false);
-        setAddressable(true);
-        setResponseRequired(true);
-    }
-
-    @Override
-    public int packetType() {
-        return TYPE;
-    }
-
-    @Override
-    protected int packetLength() {
-        return 0;
-    }
-
-    @Override
-    protected void parsePacket(ByteBuffer bytes) {
-        // do nothing
-    }
-
-    @Override
-    protected ByteBuffer packetBytes() {
-        return ByteBuffer.allocate(0);
-    }
-
-    @Override
-    public int[] expectedResponses() {
-        return new int[] { StateVersionResponse.TYPE };
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetWifiFirmwareRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetWifiFirmwareRequest.java
deleted file mode 100644 (file)
index ca18a4a..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import java.nio.ByteBuffer;
-
-/**
- * @author Tim Buckley - Initial Contribution
- * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
- */
-public class GetWifiFirmwareRequest extends Packet {
-
-    public static final int TYPE = 0x12;
-
-    public GetWifiFirmwareRequest() {
-        setTagged(false);
-        setAddressable(true);
-        setResponseRequired(true);
-    }
-
-    @Override
-    public int packetType() {
-        return TYPE;
-    }
-
-    @Override
-    protected int packetLength() {
-        return 0;
-    }
-
-    @Override
-    protected void parsePacket(ByteBuffer bytes) {
-        // do nothing
-    }
-
-    @Override
-    protected ByteBuffer packetBytes() {
-        return ByteBuffer.allocate(0);
-    }
-
-    @Override
-    public int[] expectedResponses() {
-        return new int[] { StateWifiFirmwareResponse.TYPE };
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetWifiInfoRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/GetWifiInfoRequest.java
deleted file mode 100644 (file)
index 5740cce..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import java.nio.ByteBuffer;
-
-/**
- * @author Tim Buckley - Initial Contribution
- * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
- */
-public class GetWifiInfoRequest extends Packet {
-
-    public static final int TYPE = 0x10;
-
-    public GetWifiInfoRequest() {
-        setTagged(false);
-        setAddressable(true);
-        setResponseRequired(true);
-    }
-
-    @Override
-    public int packetType() {
-        return TYPE;
-    }
-
-    @Override
-    protected int packetLength() {
-        return 0;
-    }
-
-    @Override
-    protected void parsePacket(ByteBuffer bytes) {
-        // do nothing
-    }
-
-    @Override
-    protected ByteBuffer packetBytes() {
-        return ByteBuffer.allocate(0);
-    }
-
-    @Override
-    public int[] expectedResponses() {
-        return new int[] { StateWifiInfoResponse.TYPE };
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/Packet.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/Packet.java
deleted file mode 100644 (file)
index d9084ab..0000000
+++ /dev/null
@@ -1,397 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import java.nio.ByteBuffer;
-
-import org.openhab.binding.lifx.internal.fields.ByteField;
-import org.openhab.binding.lifx.internal.fields.Field;
-import org.openhab.binding.lifx.internal.fields.MACAddress;
-import org.openhab.binding.lifx.internal.fields.MACAddressField;
-import org.openhab.binding.lifx.internal.fields.UInt16Field;
-import org.openhab.binding.lifx.internal.fields.UInt32Field;
-import org.openhab.binding.lifx.internal.fields.UInt8Field;
-
-/**
- * Represents an abstract packet, providing conversion functionality to and from
- * {@link ByteBuffer}s for common packet (preamble) fields. Subtypes of this
- * class can provide conversion functionality for specialized fields.
- *
- * <p>
- * Defining new packet types essentially involves extending this class,
- * defining the fields and implementing {@link #packetType()},
- * {@link #packetLength()}, and {@link #packetBytes()}. By convention, packet
- * type should be stored in a {@code public static final int PACKET_TYPE} field
- * in each subtype, followed by a listing of fields contained in the packet.
- * Field definitions should remain accessible to outside classes in the event
- * they need to worked with directly elsewhere.
- *
- * @author Tim Buckley - Initial Contribution
- * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
- */
-public abstract class Packet {
-
-    public static final Field<Integer> FIELD_SIZE = new UInt16Field().little();
-    public static final Field<Integer> FIELD_PROTOCOL = new UInt16Field().little();
-    public static final Field<Long> FIELD_SOURCE = new UInt32Field().little();
-    public static final Field<MACAddress> FIELD_TARGET = new MACAddressField();
-    public static final Field<ByteBuffer> FIELD_RESERVED_1 = new ByteField(6);
-    public static final Field<Integer> FIELD_ACK = new UInt8Field();
-    public static final Field<Integer> FIELD_SEQUENCE = new UInt8Field().little();
-    public static final Field<ByteBuffer> FIELD_RESERVED_2 = new ByteField(8);
-    public static final Field<Integer> FIELD_PACKET_TYPE = new UInt16Field().little();
-    public static final Field<ByteBuffer> FIELD_RESERVED_3 = new ByteField(2);
-
-    /**
-     * An ordered array of all fields contained in the common packet preamble.
-     */
-    public static final Field<?>[] PREAMBLE_FIELDS = new Field[] { FIELD_SIZE, FIELD_PROTOCOL, FIELD_SOURCE,
-            FIELD_TARGET, FIELD_RESERVED_1, FIELD_ACK, FIELD_SEQUENCE, FIELD_RESERVED_2, FIELD_PACKET_TYPE,
-            FIELD_RESERVED_3 };
-
-    protected int size;
-    protected int protocol;
-    protected long source;
-    protected MACAddress target;
-    protected ByteBuffer reserved1;
-    protected int ackbyte;
-    protected int sequence;
-    protected ByteBuffer reserved2;
-    protected int packetType;
-    protected ByteBuffer reserved3;
-
-    protected long timeStamp;
-
-    public int getSize() {
-        return size;
-    }
-
-    public void setSize(int size) {
-        this.size = size;
-    }
-
-    public int getOrigin() {
-        return (protocol & 0xC000) >> 14;
-    }
-
-    public void setOrigin(int origin) {
-        protocol = (protocol & ~(1 << 14)) | (origin << 14);
-    }
-
-    public boolean getTagged() {
-        return (protocol & 0x2000) >> 13 == 1 ? true : false;
-    }
-
-    public void setTagged(boolean flag) {
-        protocol = (protocol & ~(1 << 13)) | ((flag ? 1 : 0) << 13);
-    }
-
-    public boolean getAddressable() {
-        return (protocol & 0x1000) >> 12 == 1 ? true : false;
-    }
-
-    public void setAddressable(boolean flag) {
-        this.protocol = (protocol & ~(1 << 12)) | ((flag ? 1 : 0) << 12);
-    }
-
-    public int getProtocol() {
-        return protocol & 0x0FFF;
-    }
-
-    public void setProtocol(int protocol) {
-        this.protocol = this.protocol | protocol;
-    }
-
-    public long getSource() {
-        return source;
-    }
-
-    public void setSource(long source) {
-        this.source = source;
-    }
-
-    public MACAddress getTarget() {
-        return target;
-    }
-
-    public void setTarget(MACAddress lightAddress) {
-        this.target = lightAddress != null ? lightAddress : MACAddress.BROADCAST_ADDRESS;
-    }
-
-    public ByteBuffer getReserved1() {
-        return reserved1;
-    }
-
-    public void setReserved1(ByteBuffer reserved2) {
-        this.reserved1 = reserved2;
-    }
-
-    public boolean getAckRequired() {
-        return (ackbyte & 0x02) >> 1 == 1 ? true : false;
-    }
-
-    public void setAckRequired(boolean flag) {
-        this.ackbyte = (ackbyte & ~(1 << 1)) | ((flag ? 1 : 0) << 1);
-    }
-
-    public boolean getResponseRequired() {
-        return (ackbyte & 0x01) >> 0 == 1 ? true : false;
-    }
-
-    public void setResponseRequired(boolean flag) {
-        this.ackbyte = (ackbyte & ~(1 << 0)) | ((flag ? 1 : 0) << 0);
-    }
-
-    public int getSequence() {
-        return sequence;
-    }
-
-    public void setSequence(int sequence) {
-        if (0 <= sequence && sequence < 256) {
-            this.sequence = sequence;
-        } else {
-            throw new IllegalArgumentException("Sequence number '" + sequence + "' is not in range [0, 255]");
-        }
-    }
-
-    public ByteBuffer getReserved2() {
-        return reserved2;
-    }
-
-    public void setReserved2(ByteBuffer reserved3) {
-        this.reserved2 = reserved3;
-    }
-
-    public int getPacketType() {
-        return packetType;
-    }
-
-    public void setPacketType(int packetType) {
-        this.packetType = packetType;
-    }
-
-    public ByteBuffer getReserved3() {
-        return reserved3;
-    }
-
-    public void setReserved3(ByteBuffer reserved4) {
-        this.reserved3 = reserved4;
-    }
-
-    public long getTimeStamp() {
-        return timeStamp;
-    }
-
-    /**
-     * Creates an empty packet, setting some default values via
-     * {@link #preambleDefaults()}.
-     */
-    public Packet() {
-        preambleDefaults();
-        timeStamp = System.currentTimeMillis();
-    }
-
-    /**
-     * Parses, in order, the defined preamble fields, storing collected values.
-     * The buffer's position will be left at the end of the parsed fields and
-     * should be equal to the value returned by {@link #preambleLength()}.
-     *
-     * @param bytes the buffer to read from.
-     */
-    protected void parsePreamble(ByteBuffer bytes) {
-        size = FIELD_SIZE.value(bytes);
-        protocol = FIELD_PROTOCOL.value(bytes);
-        source = FIELD_SOURCE.value(bytes);
-        target = FIELD_TARGET.value(bytes);
-        reserved1 = FIELD_RESERVED_1.value(bytes);
-        ackbyte = FIELD_ACK.value(bytes);
-        sequence = FIELD_SEQUENCE.value(bytes);
-        reserved2 = FIELD_RESERVED_2.value(bytes);
-        packetType = FIELD_PACKET_TYPE.value(bytes);
-        reserved3 = FIELD_RESERVED_3.value(bytes);
-    }
-
-    /**
-     * Calculates the length of the packet header, defined as the sum of the
-     * lengths of all defined fields (see {@link #PREAMBLE_FIELDS}).
-     *
-     * @return the sum of the length of preamble fields
-     */
-    protected int preambleLength() {
-        int sum = 0;
-
-        for (Field<?> f : PREAMBLE_FIELDS) {
-            sum += f.getLength();
-        }
-
-        return sum;
-    }
-
-    /**
-     * Returns a new {@code ByteBuffer} containing the encoded preamble. Note
-     * that the returned buffer will have its position set at the end of the
-     * buffer and will need to have {@link ByteBuffer#rewind()} called before
-     * use.
-     *
-     * <p>
-     * The length of the buffer is the sum of the lengths of the defined
-     * preamble fields (see {@link #PREAMBLE_FIELDS} for an ordered list), which
-     * may also be accessed via {@link #preambleLength()}.
-     *
-     * <p>
-     * Certain fields are set to default values based on other class methods.
-     * For example, the size and packet type fields will be set to the values
-     * returned from {@link #length()} and {@link #packetType()}, respectively.
-     * Other defaults (such as the protocol, light address, site, and timestamp)
-     * may be specified either by directly setting the relevant protected
-     * variables or by overriding {@link #preambleDefaults()}.
-     *
-     * @return a new buffer containing the encoded preamble
-     */
-    protected ByteBuffer preambleBytes() {
-        return ByteBuffer.allocate(preambleLength()).put(FIELD_SIZE.bytes(length())).put(FIELD_PROTOCOL.bytes(protocol))
-                .put(FIELD_SOURCE.bytes(source)).put(FIELD_TARGET.bytes(target))
-                .put(ByteBuffer.allocate(FIELD_RESERVED_1.getLength())) // empty
-                .put(FIELD_ACK.bytes(ackbyte)).put(FIELD_SEQUENCE.bytes(sequence))
-                .put(ByteBuffer.allocate(FIELD_RESERVED_2.getLength())) // empty
-                .put(FIELD_PACKET_TYPE.bytes(packetType())).put(ByteBuffer.allocate(FIELD_RESERVED_3.getLength())); // empty
-    }
-
-    /**
-     * Sets default preamble values. If needed, subclasses may override these
-     * values by specifically overriding this method, or by setting individual
-     * values within the constructor, as this method is called automatically
-     * during initialization.
-     */
-    protected void preambleDefaults() {
-        size = 0;
-        protocol = 1024;
-        target = new MACAddress();
-        sequence = 0;
-        packetType = packetType();
-    }
-
-    /**
-     * Returns the packet type. Note that this value is technically distinct
-     * from {@code getPacketType()} in that it returns the packet type the
-     * current {@code Packet} subtype is designed to parse, while
-     * {@code getPacketType()} returns the actual {@code packetType} field of
-     * a parsed packet. However, these values should always match.
-     *
-     * @return the packet type intended to be handled by this Packet subtype
-     */
-    public abstract int packetType();
-
-    /**
-     * Returns the length of the payload specific to this packet subtype. The
-     * length of the preamble is specifically excluded.
-     *
-     * @return the length of this specialized packet payload
-     */
-    protected abstract int packetLength();
-
-    /**
-     * Parses the given {@link ByteBuffer} into class fields. Subtypes may
-     * implement {@link #parsePacket(ByteBuffer)} to parse additional fields;
-     * the preamble by default is always parsed.
-     *
-     * @param bytes the buffer to extract data from
-     */
-    public void parse(ByteBuffer bytes) {
-        bytes.rewind();
-        parsePreamble(bytes);
-        parsePacket(bytes);
-    }
-
-    /**
-     * Extracts data from the given {@link ByteBuffer} into fields specific to
-     * this packet subtype. The preamble will already have been parsed; as such,
-     * the buffer will be positioned at the end of the preamble. If needed,
-     * {@link #preambleLength()} may be used to restore the position of the
-     * buffer.
-     *
-     * @param bytes the raw bytes to parse
-     */
-    protected abstract void parsePacket(ByteBuffer bytes);
-
-    /**
-     * Returns a {@link ByteBuffer} containing the full payload for this packet,
-     * including the populated preamble and any specialized packet payload. The
-     * returned buffer will be at position zero.
-     *
-     * @return the full packet payload
-     */
-    public ByteBuffer bytes() {
-        ByteBuffer preamble = preambleBytes();
-        preamble.rewind();
-
-        ByteBuffer packet = packetBytes();
-        packet.rewind();
-
-        ByteBuffer ret = ByteBuffer.allocate(length()).put(preamble).put(packet);
-        ret.rewind();
-
-        return ret;
-    }
-
-    /**
-     * Returns a {@link ByteBuffer} containing the payload for this packet. Its
-     * length must match the value of {@link #packetLength()}. This specifically
-     * excludes preamble fields and should contain only data specific to the
-     * packet subtype.
-     * <p>
-     * Note that returned ByteBuffers will have {@link ByteBuffer#rewind()}
-     * called automatically before they are appended to the final packet
-     * buffer.
-     *
-     * @return the packet payload
-     */
-    protected abstract ByteBuffer packetBytes();
-
-    /**
-     * Gets the total length of this packet, in bytes. Specifically, this method
-     * is the sum of the preamble ({@link #preambleLength()}) and the payload
-     * length ({@link #packetLength()}); subtypes should override methods for
-     * those values if desired.
-     *
-     * @return the total length of this packet
-     */
-    public int length() {
-        return preambleLength() + packetLength();
-    }
-
-    /**
-     * Returns a list of expected response packet types. An empty array means
-     * no responses are expected (suitable for response packet definitions),
-     *
-     * @return a list of expected responses
-     */
-    public abstract int[] expectedResponses();
-
-    public boolean isExpectedResponse(int type) {
-        for (int a : expectedResponses()) {
-            if (a == type) {
-                return true;
-            }
-        }
-
-        return false;
-    }
-
-    public boolean isFulfilled(Packet somePacket) {
-        if (isExpectedResponse(somePacket.getPacketType())) {
-            return true;
-        }
-        return false;
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/PacketFactory.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/PacketFactory.java
deleted file mode 100644 (file)
index 6718d31..0000000
+++ /dev/null
@@ -1,157 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.eclipse.jdt.annotation.NonNullByDefault;
-import org.eclipse.jdt.annotation.Nullable;
-
-/**
- * A static factory for registering packet types that may be received and
- * dispatched to client cod * request types, like {@code PowerStateRequest}) or types received only via UDP
- * e. Packet handlers (used to construct actual packet
- * instances) may be retrieved via their packet type.
- *
- * @author Tim Buckley - Initial Contribution
- * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
- * @author Wouter Born - Support LIFX 2016 product line-up and infrared functionality
- */
-@NonNullByDefault
-public class PacketFactory {
-
-    private static @Nullable PacketFactory instance;
-
-    public static synchronized PacketFactory getInstance() {
-        PacketFactory result = instance;
-        if (result == null) {
-            result = new PacketFactory();
-            instance = result;
-        }
-        return result;
-    }
-
-    private final Map<Integer, PacketHandler<?>> handlers;
-
-    private PacketFactory() {
-        handlers = new HashMap<>();
-
-        register(AcknowledgementResponse.class);
-        register(EchoRequestResponse.class);
-        register(GetColorZonesRequest.class);
-        register(GetEchoRequest.class);
-        register(GetGroupRequest.class);
-        register(GetHostFirmwareRequest.class);
-        register(GetHostInfoRequest.class);
-        register(GetInfoRequest.class);
-        register(GetLabelRequest.class);
-        register(GetLightInfraredRequest.class);
-        register(GetLightPowerRequest.class);
-        register(GetLocationRequest.class);
-        register(GetPowerRequest.class);
-        register(GetRequest.class);
-        register(GetServiceRequest.class);
-        register(GetTagLabelsRequest.class);
-        register(GetTagsRequest.class);
-        register(GetTileEffectRequest.class);
-        register(GetVersionRequest.class);
-        register(GetWifiFirmwareRequest.class);
-        register(GetWifiInfoRequest.class);
-        register(SetColorRequest.class);
-        register(SetColorZonesRequest.class);
-        register(SetDimAbsoluteRequest.class);
-        register(SetLabelRequest.class);
-        register(SetLightInfraredRequest.class);
-        register(SetLightPowerRequest.class);
-        register(SetPowerRequest.class);
-        register(SetTagsRequest.class);
-        register(StateGroupResponse.class);
-        register(StateHostFirmwareResponse.class);
-        register(StateHostInfoResponse.class);
-        register(StateInfoResponse.class);
-        register(StateLabelResponse.class);
-        register(StateLightInfraredResponse.class);
-        register(StateLightPowerResponse.class);
-        register(StateLocationResponse.class);
-        register(StateMultiZoneResponse.class);
-        register(StatePowerResponse.class);
-        register(StateResponse.class);
-        register(StateServiceResponse.class);
-        register(StateTileEffectResponse.class);
-        register(StateVersionResponse.class);
-        register(StateWifiFirmwareResponse.class);
-        register(StateWifiInfoResponse.class);
-        register(StateZoneResponse.class);
-        register(TagLabelsResponse.class);
-        register(TagsResponse.class);
-    }
-
-    /**
-     * Registers a packet handler for the given packet type.
-     *
-     * @param type the type to register
-     * @param handler the packet handler to associate with the type
-     */
-    public final void register(int type, PacketHandler<?> handler) {
-        handlers.put(type, handler);
-    }
-
-    /**
-     * Registers a new generic packet handler for the given packet class. The
-     * packet class must meet the criteria for {@link GenericHandler};
-     * specifically, it must have an no-argument constructor and require no
-     * parsing logic outside of an invocation of
-     * {@link Packet#parse(java.nio.ByteBuffer)}.
-     *
-     * @param type the type of the packet to register
-     * @param clazz the class of the packet to register
-     */
-    public final void register(int type, Class<? extends Packet> clazz) {
-        handlers.put(type, new GenericHandler<>(clazz));
-    }
-
-    /**
-     * Registers a generic packet type. All requirements of
-     * {@link GenericHandler} must met; specifically, classes must have a
-     * no-args constructor and require no additional parsing logic.
-     * Additionally, a public static integer {@code TYPE} field must be defined.
-     *
-     * @param <T> the packet type to register
-     * @param clazz the packet class to register
-     */
-    public final <T extends Packet> void register(Class<T> clazz) {
-        GenericHandler<T> handler = new GenericHandler<>(clazz);
-
-        if (!handler.isTypeFound()) {
-            throw new IllegalArgumentException("Unable to register generic packet with no TYPE field.");
-        }
-
-        handlers.put(handler.getType(), handler);
-    }
-
-    /**
-     * Gets a registered handler for the given packet type, if any exists. If
-     * no matching handler can be found, {@code null} is returned.
-     *
-     * @param packetType the packet type of the handler to retrieve
-     * @return a packet handler, or null
-     */
-    public @Nullable PacketHandler<?> getHandler(int packetType) {
-        return handlers.get(packetType);
-    }
-
-    public static @Nullable PacketHandler<?> createHandler(int packetType) {
-        return getInstance().getHandler(packetType);
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/PacketHandler.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/PacketHandler.java
deleted file mode 100644 (file)
index fe8944e..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import java.nio.ByteBuffer;
-
-import org.eclipse.jdt.annotation.NonNullByDefault;
-
-/**
- * A packet handler responsible for converting a ByteBuffer into a Packet
- * instance.
- *
- * @param <T> the generic packet type
- *
- * @author Tim Buckley - Initial Contribution
- * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
- */
-@NonNullByDefault
-public interface PacketHandler<T extends Packet> {
-
-    /**
-     * Creates a packet from the given buffer.
-     *
-     * @param buf the buffer used for creating the packet
-     * @return the packet created from the buffer
-     * @throws IllegalArgumentException when an empty packet could not be created or the data in the buffer
-     *             could not be parsed
-     */
-    public abstract T handle(ByteBuffer buf);
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/PowerState.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/PowerState.java
deleted file mode 100644 (file)
index 69d6ad1..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import org.openhab.core.library.types.OnOffType;
-
-/**
- * Represents light power states (on or off).
- *
- * @author Tim Buckley - Initial Contribution
- * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
- * @author Wouter Born - Added OnOffType conversion methods
- */
-public enum PowerState {
-
-    ON(0xFFFF),
-    OFF(0x0000);
-
-    private final int value;
-
-    private PowerState(int value) {
-        this.value = value;
-    }
-
-    /**
-     * Gets the integer value of this power state.
-     *
-     * @return the integer value
-     */
-    public int getValue() {
-        return value;
-    }
-
-    public static PowerState fromValue(int value) {
-        // a response can have a power level between 0 and 65535 when the light
-        // has just been switched ON or OFF
-        return value == OFF.value ? OFF : ON;
-    }
-
-    public static PowerState fromOnOffType(OnOffType onOff) {
-        return onOff == OnOffType.ON ? ON : OFF;
-    }
-
-    public OnOffType toOnOffType() {
-        return this == ON ? OnOffType.ON : OnOffType.OFF;
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/Product.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/Product.java
deleted file mode 100644 (file)
index cee8e8d..0000000
+++ /dev/null
@@ -1,312 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import static org.openhab.binding.lifx.internal.protocol.Product.Feature.*;
-import static org.openhab.binding.lifx.internal.protocol.Product.TemperatureRange.*;
-import static org.openhab.binding.lifx.internal.protocol.Product.Vendor.LIFX;
-
-import java.util.Arrays;
-import java.util.EnumSet;
-
-import org.eclipse.jdt.annotation.NonNullByDefault;
-import org.openhab.binding.lifx.internal.LifxBindingConstants;
-import org.openhab.core.thing.ThingTypeUID;
-
-/**
- * Enumerates the LIFX products, their IDs and feature set.
- *
- * @see https://lan.developer.lifx.com/docs/lifx-products
- *
- * @author Wouter Born - Support LIFX 2016 product line-up and infrared functionality
- * @author Wouter Born - Add temperature ranges and simplify feature definitions
- */
-@NonNullByDefault
-public enum Product {
-
-    PRODUCT_1(1, "LIFX Original 1000", TR_2500_9000, COLOR),
-    PRODUCT_3(3, "LIFX Color 650", TR_2500_9000, COLOR),
-    PRODUCT_10(10, "LIFX White 800 (Low Voltage)", TR_2700_6500),
-    PRODUCT_11(11, "LIFX White 800 (High Voltage)", TR_2700_6500),
-    PRODUCT_15(15, "LIFX Color 1000", TR_2500_9000, COLOR),
-    PRODUCT_18(18, "LIFX White 900 BR30 (Low Voltage)", TR_2700_6500),
-    PRODUCT_19(19, "LIFX White 900 BR30 (High Voltage)", TR_2700_6500),
-    PRODUCT_20(20, "LIFX Color 1000 BR30", TR_2500_9000, COLOR),
-    PRODUCT_22(22, "LIFX Color 1000", TR_2500_9000, COLOR),
-    PRODUCT_27(27, "LIFX A19", TR_2500_9000, COLOR),
-    PRODUCT_28(28, "LIFX BR30", TR_2500_9000, COLOR),
-    PRODUCT_29(29, "LIFX A19 Night Vision", TR_2500_9000, COLOR, INFRARED),
-    PRODUCT_30(30, "LIFX BR30 Night Vision", TR_2500_9000, COLOR, INFRARED),
-    PRODUCT_31(31, "LIFX Z", TR_2500_9000, COLOR, MULTIZONE),
-    PRODUCT_32(32, "LIFX Z", TR_2500_9000, COLOR, MULTIZONE),
-    PRODUCT_36(36, "LIFX Downlight", TR_2500_9000, COLOR),
-    PRODUCT_37(37, "LIFX Downlight", TR_2500_9000, COLOR),
-    PRODUCT_38(38, "LIFX Beam", TR_2500_9000, COLOR, MULTIZONE),
-    PRODUCT_39(39, "LIFX Downlight White to Warm", TR_1500_9000),
-    PRODUCT_40(40, "LIFX Downlight", TR_2500_9000, COLOR),
-    PRODUCT_43(43, "LIFX A19", TR_2500_9000, COLOR),
-    PRODUCT_44(44, "LIFX BR30", TR_2500_9000, COLOR),
-    PRODUCT_45(45, "LIFX A19 Night Vision", TR_2500_9000, COLOR, INFRARED),
-    PRODUCT_46(46, "LIFX BR30 Night Vision", TR_2500_9000, COLOR, INFRARED),
-    PRODUCT_49(49, "LIFX Mini Color", TR_2500_9000, COLOR),
-    PRODUCT_50(50, "LIFX Mini White to Warm", TR_1500_4000),
-    PRODUCT_51(51, "LIFX Mini White", TR_2700_2700),
-    PRODUCT_52(52, "LIFX GU10", TR_2500_9000, COLOR),
-    PRODUCT_53(53, "LIFX GU10", TR_2500_9000, COLOR),
-    PRODUCT_55(55, "LIFX Tile", TR_2500_9000, CHAIN, COLOR, MATRIX, TILE_EFFECT),
-    PRODUCT_57(57, "LIFX Candle", TR_1500_9000, COLOR, MATRIX),
-    PRODUCT_59(59, "LIFX Mini Color", TR_2500_9000, COLOR),
-    PRODUCT_60(60, "LIFX Mini White to Warm", TR_1500_4000),
-    PRODUCT_61(61, "LIFX Mini White", TR_2700_2700),
-    PRODUCT_62(62, "LIFX A19", TR_2500_9000, COLOR),
-    PRODUCT_63(63, "LIFX BR30", TR_2500_9000, COLOR),
-    PRODUCT_64(64, "LIFX A19 Night Vision", TR_2500_9000, COLOR, INFRARED),
-    PRODUCT_65(65, "LIFX BR30 Night Vision", TR_2500_9000, COLOR, INFRARED),
-    PRODUCT_66(66, "LIFX Mini White", TR_2700_2700),
-    PRODUCT_68(68, "LIFX Candle", TR_1500_9000, MATRIX),
-    PRODUCT_81(81, "LIFX Candle White to Warm", TR_2200_6500),
-    PRODUCT_82(82, "LIFX Filament Clear", TR_2100_2100),
-    PRODUCT_85(85, "LIFX Filament Amber", TR_2000_2000),
-    PRODUCT_87(87, "LIFX Mini White", TR_2700_2700),
-    PRODUCT_88(88, "LIFX Mini White", TR_2700_2700),
-    PRODUCT_90(90, "LIFX Clean", TR_2500_9000, HEV),
-    PRODUCT_91(91, "LIFX Color", TR_2500_9000, COLOR),
-    PRODUCT_92(92, "LIFX Color", TR_2500_9000, COLOR),
-    PRODUCT_94(94, "LIFX BR30", TR_2500_9000, COLOR),
-    PRODUCT_96(96, "LIFX Candle White to Warm", TR_2200_6500),
-    PRODUCT_97(97, "LIFX A19", TR_2500_9000, COLOR),
-    PRODUCT_98(98, "LIFX BR30", TR_2500_9000, COLOR),
-    PRODUCT_99(99, "LIFX Clean", TR_2500_9000, HEV),
-    PRODUCT_100(100, "LIFX Filament Clear", TR_2100_2100),
-    PRODUCT_101(101, "LIFX Filament Amber", TR_2000_2000),
-    PRODUCT_109(109, "LIFX A19 Night Vision", TR_2500_9000, COLOR, INFRARED),
-    PRODUCT_110(110, "LIFX BR30 Night Vision", TR_2500_9000, COLOR, INFRARED),
-    PRODUCT_111(111, "LIFX A19 Night Vision", TR_2500_9000, COLOR, INFRARED);
-
-    /**
-     * Enumerates the product features.
-     */
-    public enum Feature {
-        CHAIN,
-        COLOR,
-        HEV,
-        INFRARED,
-        MATRIX,
-        MULTIZONE,
-        TILE_EFFECT
-    }
-
-    /**
-     * Enumerates the product vendors.
-     */
-    public enum Vendor {
-        LIFX(1, "LIFX");
-
-        private final int id;
-        private final String name;
-
-        Vendor(int id, String name) {
-            this.id = id;
-            this.name = name;
-        }
-
-        public int getID() {
-            return id;
-        }
-
-        public String getName() {
-            return name;
-        }
-    }
-
-    /**
-     * Enumerates the color temperature ranges of lights.
-     */
-    public enum TemperatureRange {
-        /**
-         * 1500-4000K
-         */
-        TR_1500_4000(1500, 4000),
-
-        /**
-         * 1500-9000K
-         */
-        TR_1500_9000(1500, 9000),
-
-        /**
-         * 2000-2000K
-         */
-        TR_2000_2000(2000, 2000),
-
-        /**
-         * 2100-2100K
-         */
-        TR_2100_2100(2100, 2100),
-
-        /**
-         * 2200-6500K
-         */
-        TR_2200_6500(2200, 6500),
-
-        /**
-         * 2500-9000K
-         */
-        TR_2500_9000(2500, 9000),
-
-        /**
-         * 2700-2700K
-         */
-        TR_2700_2700(2700, 2700),
-
-        /**
-         * 2700-6500K
-         */
-        TR_2700_6500(2700, 6500);
-
-        private final int minimum;
-        private final int maximum;
-
-        TemperatureRange(int minimum, int maximum) {
-            this.minimum = minimum;
-            this.maximum = maximum;
-        }
-
-        /**
-         * The minimum color temperature in degrees Kelvin.
-         *
-         * @return minimum color temperature (K)
-         */
-        public int getMinimum() {
-            return minimum;
-        }
-
-        /**
-         * The maxiumum color temperature in degrees Kelvin.
-         *
-         * @return maximum color temperature (K)
-         */
-        public int getMaximum() {
-            return maximum;
-        }
-
-        /**
-         * The color temperature range in degrees Kelvin.
-         *
-         * @return difference between maximum and minimum color temperature values
-         */
-        public int getRange() {
-            return maximum - minimum;
-        }
-    }
-
-    private final Vendor vendor;
-    private final long id;
-    private final String name;
-    private final TemperatureRange temperatureRange;
-    private final EnumSet<Feature> features = EnumSet.noneOf(Feature.class);
-
-    private Product(long id, String name, TemperatureRange temperatureRange) {
-        this(LIFX, id, name, temperatureRange);
-    }
-
-    private Product(long id, String name, TemperatureRange temperatureRange, Feature... features) {
-        this(LIFX, id, name, temperatureRange, features);
-    }
-
-    private Product(Vendor vendor, long id, String name, TemperatureRange temperatureRange) {
-        this(vendor, id, name, temperatureRange, new Feature[0]);
-    }
-
-    private Product(Vendor vendor, long id, String name, TemperatureRange temperatureRange, Feature... features) {
-        this.vendor = vendor;
-        this.id = id;
-        this.name = name;
-        this.temperatureRange = temperatureRange;
-        this.features.addAll(Arrays.asList(features));
-    }
-
-    @Override
-    public String toString() {
-        return name;
-    }
-
-    public Vendor getVendor() {
-        return vendor;
-    }
-
-    public long getID() {
-        return id;
-    }
-
-    public String getName() {
-        return name;
-    }
-
-    public TemperatureRange getTemperatureRange() {
-        return temperatureRange;
-    }
-
-    public ThingTypeUID getThingTypeUID() {
-        if (hasFeature(COLOR)) {
-            if (hasFeature(TILE_EFFECT)) {
-                return LifxBindingConstants.THING_TYPE_TILELIGHT;
-            } else if (hasFeature(INFRARED)) {
-                return LifxBindingConstants.THING_TYPE_COLORIRLIGHT;
-            } else if (hasFeature(MULTIZONE)) {
-                return LifxBindingConstants.THING_TYPE_COLORMZLIGHT;
-            } else {
-                return LifxBindingConstants.THING_TYPE_COLORLIGHT;
-            }
-        } else {
-            return LifxBindingConstants.THING_TYPE_WHITELIGHT;
-        }
-    }
-
-    public boolean hasFeature(Feature feature) {
-        return features.contains(feature);
-    }
-
-    /**
-     * Returns a product that has the given thing type UID.
-     *
-     * @param uid a thing type UID
-     * @return a product that has the given thing type UID
-     * @throws IllegalArgumentException when <code>uid</code> is not a valid LIFX thing type UID
-     */
-    public static Product getLikelyProduct(ThingTypeUID uid) throws IllegalArgumentException {
-        for (Product product : Product.values()) {
-            if (product.getThingTypeUID().equals(uid)) {
-                return product;
-            }
-        }
-
-        throw new IllegalArgumentException(uid + " is not a valid product thing type UID");
-    }
-
-    /**
-     * Returns the product that has the given product ID.
-     *
-     * @param id the product ID
-     * @return the product that has the given product ID
-     * @throws IllegalArgumentException when <code>id</code> is not a valid LIFX product ID
-     */
-    public static Product getProductFromProductID(long id) throws IllegalArgumentException {
-        for (Product product : Product.values()) {
-            if (product.id == id) {
-                return product;
-            }
-        }
-
-        throw new IllegalArgumentException(id + " is not a valid product ID");
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/SetColorRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/SetColorRequest.java
deleted file mode 100644 (file)
index 3a24126..0000000
+++ /dev/null
@@ -1,92 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import java.nio.ByteBuffer;
-
-import org.openhab.binding.lifx.internal.fields.ByteField;
-import org.openhab.binding.lifx.internal.fields.Field;
-import org.openhab.binding.lifx.internal.fields.HSBK;
-import org.openhab.binding.lifx.internal.fields.HSBKField;
-import org.openhab.binding.lifx.internal.fields.UInt32Field;
-
-/**
- * @author Tim Buckley - Initial Contribution
- * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
- */
-public class SetColorRequest extends Packet {
-
-    public static final int TYPE = 0x66;
-
-    public static final Field<ByteBuffer> FIELD_STREAM = new ByteField(1);
-    public static final HSBKField FIELD_COLOR = new HSBKField();
-    public static final Field<Long> FIELD_FADE_TIME = new UInt32Field().little();
-
-    private ByteBuffer stream;
-
-    private HSBK color;
-    private long fadeTime;
-
-    public ByteBuffer getStream() {
-        return stream;
-    }
-
-    public HSBK getColor() {
-        return color;
-    }
-
-    public long getFadeTime() {
-        return fadeTime;
-    }
-
-    public SetColorRequest() {
-        stream = ByteBuffer.allocate(1);
-        setTagged(false);
-        setAddressable(true);
-        setResponseRequired(true);
-    }
-
-    public SetColorRequest(HSBK color, long fadeTime) {
-        this();
-        this.color = color;
-        this.fadeTime = fadeTime;
-    }
-
-    @Override
-    public int packetType() {
-        return TYPE;
-    }
-
-    @Override
-    protected int packetLength() {
-        return 13;
-    }
-
-    @Override
-    protected void parsePacket(ByteBuffer bytes) {
-        stream = FIELD_STREAM.value(bytes);
-        color = FIELD_COLOR.value(bytes);
-        fadeTime = FIELD_FADE_TIME.value(bytes);
-    }
-
-    @Override
-    protected ByteBuffer packetBytes() {
-        return ByteBuffer.allocate(packetLength()).put(FIELD_STREAM.bytes(stream)).put(FIELD_COLOR.bytes(color))
-                .put(FIELD_FADE_TIME.bytes(fadeTime));
-    }
-
-    @Override
-    public int[] expectedResponses() {
-        return new int[] { StateResponse.TYPE };
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/SetColorZonesRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/SetColorZonesRequest.java
deleted file mode 100644 (file)
index 5553877..0000000
+++ /dev/null
@@ -1,125 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import static org.openhab.binding.lifx.internal.LifxBindingConstants.*;
-
-import java.nio.ByteBuffer;
-
-import org.openhab.binding.lifx.internal.fields.Field;
-import org.openhab.binding.lifx.internal.fields.HSBK;
-import org.openhab.binding.lifx.internal.fields.HSBKField;
-import org.openhab.binding.lifx.internal.fields.UInt32Field;
-import org.openhab.binding.lifx.internal.fields.UInt8Field;
-
-/**
- * @author Wouter Born - Add support for MultiZone light control
- */
-public class SetColorZonesRequest extends Packet {
-
-    public static final int TYPE = 0x1F5;
-
-    public static final Field<Integer> FIELD_START_INDEX = new UInt8Field();
-    public static final Field<Integer> FIELD_END_INDEX = new UInt8Field();
-    public static final HSBKField FIELD_COLOR = new HSBKField();
-    public static final Field<Long> FIELD_FADE_TIME = new UInt32Field().little();
-    public static final Field<Integer> FIELD_APPLY = new UInt8Field();
-
-    private int startIndex = MIN_ZONE_INDEX;
-    private int endIndex = MAX_ZONE_INDEX;
-    private HSBK color;
-    private long fadeTime;
-    private ApplicationRequest apply;
-
-    public HSBK getColor() {
-        return color;
-    }
-
-    public int getHue() {
-        return color.getHue();
-    }
-
-    public int getSaturation() {
-        return color.getSaturation();
-    }
-
-    public int getBrightness() {
-        return color.getBrightness();
-    }
-
-    public int getKelvin() {
-        return color.getKelvin();
-    }
-
-    public long getFadeTime() {
-        return fadeTime;
-    }
-
-    public ApplicationRequest getApply() {
-        return apply;
-    }
-
-    public SetColorZonesRequest() {
-        setTagged(false);
-        setAddressable(true);
-        setResponseRequired(true);
-    }
-
-    public SetColorZonesRequest(HSBK color, long fadeTime, ApplicationRequest apply) {
-        this(MIN_ZONE_INDEX, MAX_ZONE_INDEX, color, fadeTime, apply);
-    }
-
-    public SetColorZonesRequest(int index, HSBK color, long fadeTime, ApplicationRequest apply) {
-        this(index, index, color, fadeTime, apply);
-    }
-
-    public SetColorZonesRequest(int startIndex, int endIndex, HSBK color, long fadeTime, ApplicationRequest apply) {
-        this();
-        this.startIndex = startIndex;
-        this.endIndex = endIndex;
-        this.color = color;
-        this.fadeTime = fadeTime;
-        this.apply = apply;
-    }
-
-    @Override
-    public int packetType() {
-        return TYPE;
-    }
-
-    @Override
-    protected int packetLength() {
-        return 15;
-    }
-
-    @Override
-    protected void parsePacket(ByteBuffer bytes) {
-        startIndex = FIELD_START_INDEX.value(bytes);
-        endIndex = FIELD_END_INDEX.value(bytes);
-        color = FIELD_COLOR.value(bytes);
-        fadeTime = FIELD_FADE_TIME.value(bytes);
-        apply = ApplicationRequest.fromValue(FIELD_APPLY.value(bytes));
-    }
-
-    @Override
-    protected ByteBuffer packetBytes() {
-        return ByteBuffer.allocate(packetLength()).put(FIELD_START_INDEX.bytes(startIndex))
-                .put(FIELD_END_INDEX.bytes(endIndex)).put(FIELD_COLOR.bytes(color)).put(FIELD_FADE_TIME.bytes(fadeTime))
-                .put(FIELD_APPLY.bytes(apply.getValue()));
-    }
-
-    @Override
-    public int[] expectedResponses() {
-        return new int[] {};
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/SetDimAbsoluteRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/SetDimAbsoluteRequest.java
deleted file mode 100644 (file)
index 648db58..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import java.nio.ByteBuffer;
-
-import org.openhab.binding.lifx.internal.fields.Field;
-import org.openhab.binding.lifx.internal.fields.UInt16Field;
-import org.openhab.binding.lifx.internal.fields.UInt32Field;
-
-/**
- * @author Tim Buckley - Initial Contribution
- * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
- */
-public class SetDimAbsoluteRequest extends Packet {
-
-    public static final int TYPE = 0x68;
-
-    public static final Field<Integer> FIELD_DIM = new UInt16Field().little();
-    public static final Field<Long> FIELD_DURATION = new UInt32Field().little();
-
-    private int dim;
-    private long duration;
-
-    public int getDim() {
-        return dim;
-    }
-
-    public long getDuration() {
-        return duration;
-    }
-
-    public SetDimAbsoluteRequest() {
-    }
-
-    public SetDimAbsoluteRequest(int dim, long duration) {
-        this.dim = dim;
-        this.duration = duration;
-    }
-
-    @Override
-    public int packetType() {
-        return TYPE;
-    }
-
-    @Override
-    protected int packetLength() {
-        return 6;
-    }
-
-    @Override
-    protected void parsePacket(ByteBuffer bytes) {
-        dim = FIELD_DIM.value(bytes);
-        duration = FIELD_DURATION.value(bytes);
-    }
-
-    @Override
-    protected ByteBuffer packetBytes() {
-        return ByteBuffer.allocate(packetLength()).put(FIELD_DIM.bytes(dim)).put(FIELD_DURATION.bytes(duration));
-    }
-
-    @Override
-    public int[] expectedResponses() {
-        return new int[] {};
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/SetLabelRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/SetLabelRequest.java
deleted file mode 100644 (file)
index e55dbe5..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import java.nio.ByteBuffer;
-
-import org.openhab.binding.lifx.internal.fields.Field;
-import org.openhab.binding.lifx.internal.fields.StringField;
-
-/**
- * @author Tim Buckley - Initial Contribution
- * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
- */
-public class SetLabelRequest extends Packet {
-
-    public static final int TYPE = 0x18;
-
-    public static final Field<String> FIELD_LABEL = new StringField(32).utf8();
-
-    private String label;
-
-    public SetLabelRequest() {
-        setTagged(false);
-        setAddressable(true);
-        setAckRequired(true);
-    }
-
-    public String getLabel() {
-        return label;
-    }
-
-    public void setLabel(String label) {
-        this.label = label;
-    }
-
-    @Override
-    public int packetType() {
-        return TYPE;
-    }
-
-    @Override
-    protected int packetLength() {
-        return 32;
-    }
-
-    @Override
-    protected void parsePacket(ByteBuffer bytes) {
-        label = FIELD_LABEL.value(bytes);
-    }
-
-    @Override
-    protected ByteBuffer packetBytes() {
-        return FIELD_LABEL.bytes(label);
-    }
-
-    @Override
-    public int[] expectedResponses() {
-        return new int[] {};
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/SetLightInfraredRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/SetLightInfraredRequest.java
deleted file mode 100644 (file)
index e9d601c..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import java.nio.ByteBuffer;
-
-import org.openhab.binding.lifx.internal.fields.Field;
-import org.openhab.binding.lifx.internal.fields.UInt16Field;
-
-/**
- * @author Wouter Born - Support LIFX 2016 product line-up and infrared functionality
- */
-public class SetLightInfraredRequest extends Packet {
-
-    public static final int TYPE = 0x7A;
-
-    public static final Field<Integer> FIELD_STATE = new UInt16Field().little();
-
-    private int infrared;
-
-    public int getInfrared() {
-        return infrared;
-    }
-
-    public SetLightInfraredRequest() {
-        setTagged(false);
-        setAddressable(true);
-        setResponseRequired(true);
-    }
-
-    public SetLightInfraredRequest(int infrared) {
-        this();
-        this.infrared = infrared;
-    }
-
-    @Override
-    public int packetType() {
-        return TYPE;
-    }
-
-    @Override
-    protected int packetLength() {
-        return 2;
-    }
-
-    @Override
-    protected void parsePacket(ByteBuffer bytes) {
-        infrared = FIELD_STATE.value(bytes);
-    }
-
-    @Override
-    protected ByteBuffer packetBytes() {
-        return ByteBuffer.allocate(2).put(FIELD_STATE.bytes(infrared));
-    }
-
-    @Override
-    public int[] expectedResponses() {
-        return new int[] { StateLightInfraredResponse.TYPE };
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/SetLightPowerRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/SetLightPowerRequest.java
deleted file mode 100644 (file)
index ed186fd..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import java.nio.ByteBuffer;
-
-import org.openhab.binding.lifx.internal.fields.Field;
-import org.openhab.binding.lifx.internal.fields.UInt16Field;
-import org.openhab.binding.lifx.internal.fields.UInt32Field;
-
-/**
- * @author Tim Buckley - Initial Contribution
- * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
- */
-public class SetLightPowerRequest extends Packet {
-
-    public static final int TYPE = 0x75;
-
-    public static final Field<Integer> FIELD_STATE = new UInt16Field();
-    public static final Field<Long> FIELD_DURATION = new UInt32Field().little();
-
-    private PowerState state;
-    private long duration;
-
-    public PowerState getState() {
-        return state;
-    }
-
-    public long getDuration() {
-        return duration;
-    }
-
-    public void setDuration(long duration) {
-        this.duration = duration;
-    }
-
-    public SetLightPowerRequest() {
-        state = PowerState.OFF;
-        this.duration = 0;
-        setTagged(false);
-        setAddressable(true);
-        setResponseRequired(true);
-    }
-
-    public SetLightPowerRequest(PowerState state) {
-        this.state = state;
-        this.duration = 0;
-        setTagged(false);
-        setAddressable(true);
-        setResponseRequired(true);
-    }
-
-    @Override
-    public int packetType() {
-        return TYPE;
-    }
-
-    @Override
-    protected int packetLength() {
-        return 6;
-    }
-
-    @Override
-    protected void parsePacket(ByteBuffer bytes) {
-        state = PowerState.fromValue(FIELD_STATE.value(bytes));
-        duration = FIELD_DURATION.value(bytes);
-    }
-
-    @Override
-    protected ByteBuffer packetBytes() {
-        return ByteBuffer.allocate(packetLength()).put(FIELD_STATE.bytes(state.getValue()))
-                .put(FIELD_DURATION.bytes(duration));
-    }
-
-    @Override
-    public int[] expectedResponses() {
-        return new int[] { StateLightPowerResponse.TYPE };
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/SetPowerRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/SetPowerRequest.java
deleted file mode 100644 (file)
index 8b0d61a..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import java.nio.ByteBuffer;
-
-import org.openhab.binding.lifx.internal.fields.Field;
-import org.openhab.binding.lifx.internal.fields.UInt16Field;
-
-/**
- * @author Tim Buckley - Initial Contribution
- * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
- */
-public class SetPowerRequest extends Packet {
-
-    public static final int TYPE = 0x15;
-
-    public static final Field<Integer> FIELD_STATE = new UInt16Field();
-
-    private PowerState state;
-
-    public PowerState getState() {
-        return state;
-    }
-
-    public SetPowerRequest() {
-        state = PowerState.OFF;
-        setTagged(false);
-        setAddressable(true);
-        setResponseRequired(true);
-    }
-
-    public SetPowerRequest(PowerState state) {
-        this.state = state;
-        setTagged(false);
-        setAddressable(true);
-        setResponseRequired(true);
-    }
-
-    @Override
-    public int packetType() {
-        return TYPE;
-    }
-
-    @Override
-    protected int packetLength() {
-        return 2;
-    }
-
-    @Override
-    protected void parsePacket(ByteBuffer bytes) {
-        state = PowerState.fromValue(FIELD_STATE.value(bytes));
-    }
-
-    @Override
-    protected ByteBuffer packetBytes() {
-        return ByteBuffer.allocate(2).put(FIELD_STATE.bytes(state.getValue()));
-    }
-
-    @Override
-    public int[] expectedResponses() {
-        return new int[] { StatePowerResponse.TYPE };
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/SetTagsRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/SetTagsRequest.java
deleted file mode 100644 (file)
index 384ae11..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import java.nio.ByteBuffer;
-
-import org.openhab.binding.lifx.internal.fields.Field;
-import org.openhab.binding.lifx.internal.fields.UInt64Field;
-
-/**
- * @author Tim Buckley - Initial Contribution
- * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
- */
-public class SetTagsRequest extends Packet {
-
-    public static final int TYPE = 0x1B;
-
-    public static final Field<Long> FIELD_TAGS = new UInt64Field();
-
-    private long tags;
-
-    public long getTags() {
-        return tags;
-    }
-
-    public void setTags(long tags) {
-        this.tags = tags;
-    }
-
-    public SetTagsRequest() {
-    }
-
-    public SetTagsRequest(long tags) {
-        this.tags = tags;
-    }
-
-    @Override
-    public int packetType() {
-        return TYPE;
-    }
-
-    @Override
-    protected int packetLength() {
-        return 8;
-    }
-
-    @Override
-    protected void parsePacket(ByteBuffer bytes) {
-        tags = FIELD_TAGS.value(bytes);
-    }
-
-    @Override
-    protected ByteBuffer packetBytes() {
-        return ByteBuffer.allocate(packetLength()).put(FIELD_TAGS.bytes(tags));
-    }
-
-    @Override
-    public int[] expectedResponses() {
-        return new int[] {};
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/SetTileEffectRequest.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/SetTileEffectRequest.java
deleted file mode 100644 (file)
index f4cef59..0000000
+++ /dev/null
@@ -1,153 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import java.nio.ByteBuffer;
-
-import org.openhab.binding.lifx.internal.fields.Field;
-import org.openhab.binding.lifx.internal.fields.HSBK;
-import org.openhab.binding.lifx.internal.fields.HSBKField;
-import org.openhab.binding.lifx.internal.fields.UInt32Field;
-import org.openhab.binding.lifx.internal.fields.UInt64Field;
-import org.openhab.binding.lifx.internal.fields.UInt8Field;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Implementation of SetTileEffect packet
- *
- * @author Pawel Pieczul - Initial contribution
- */
-public class SetTileEffectRequest extends Packet {
-
-    public static final int TYPE = 0x2CF;
-
-    // size.from.to....what
-    // ------------------------------
-    // 1....0....0.....reserved
-    // 1....1....1.....reserved
-    // 4....2....5.....instance ID
-    // 1....6....6.....effect type
-    // 4....7....10....speed
-    // 8....11...18....duration
-    // 4....19...22....reserved
-    // 4....23...26....reserved
-    // 32...27...58....parameters (8*32 bits)
-    // 1....59...59....palette count
-    // 128..60...187...palette (16*8 bits)
-
-    private static final Field<Integer> FIELD_RESERVED_0 = new UInt8Field();
-    private static final Field<Integer> FIELD_RESERVED_1 = new UInt8Field();
-    private static final Field<Long> FIELD_INSTANCE_ID = new UInt32Field().little();
-    private static final Field<Integer> FIELD_TYPE = new UInt8Field();
-    private static final Field<Long> FIELD_SPEED = new UInt32Field().little();
-    private static final Field<Long> FIELD_DURATION = new UInt64Field().little();
-    private static final Field<Long> FIELD_RESERVED_19_TO_26 = new UInt32Field().little();
-    private static final Field<Long> FIELD_PARAMETER_27_TO_58 = new UInt32Field().little();
-    private static final Field<Integer> FIELD_PALETTE_COUNT = new UInt8Field();
-    private static final Field<HSBK> FIELD_PALETTE_60_TO_187 = new HSBKField();
-
-    private final Logger logger = LoggerFactory.getLogger(SetTileEffectRequest.class);
-
-    private Integer reserved0 = 0;
-    private Integer reserved1 = 0;
-    private Long reserved19to22 = 0L;
-    private Long reserved23to26 = 0L;
-    private Effect effect;
-
-    public SetTileEffectRequest() {
-        setTagged(false);
-        setAddressable(true);
-        setAckRequired(true);
-    }
-
-    public SetTileEffectRequest(Effect effect) {
-        this();
-        this.effect = effect;
-    }
-
-    @Override
-    public int packetType() {
-        return TYPE;
-    }
-
-    @Override
-    protected int packetLength() {
-        return 188;
-    }
-
-    @Override
-    protected void parsePacket(ByteBuffer bytes) {
-        reserved0 = FIELD_RESERVED_0.value(bytes);
-        reserved1 = FIELD_RESERVED_1.value(bytes);
-        FIELD_INSTANCE_ID.value(bytes);
-        Integer effectType = FIELD_TYPE.value(bytes);
-        Long speed = FIELD_SPEED.value(bytes);
-        Long duration = FIELD_DURATION.value(bytes);
-        reserved19to22 = FIELD_RESERVED_19_TO_26.value(bytes);
-        reserved23to26 = FIELD_RESERVED_19_TO_26.value(bytes);
-        Long[] parameters = new Long[8];
-        for (int i = 0; i < parameters.length; i++) {
-            parameters[i] = FIELD_PARAMETER_27_TO_58.value(bytes);
-        }
-        Integer paletteCount = FIELD_PALETTE_COUNT.value(bytes);
-        HSBK[] palette = new HSBK[paletteCount];
-        for (int i = 0; i < palette.length; i++) {
-            palette[i] = FIELD_PALETTE_60_TO_187.value(bytes);
-        }
-        try {
-            effect = new Effect(effectType, speed, duration, palette);
-        } catch (IllegalArgumentException e) {
-            logger.debug("Wrong effect type received: {}", effectType);
-            effect = null;
-        }
-    }
-
-    @Override
-    protected ByteBuffer packetBytes() {
-        ByteBuffer buffer = ByteBuffer.allocate(packetLength());
-        buffer.put(FIELD_RESERVED_0.bytes(reserved0));
-        buffer.put(FIELD_RESERVED_1.bytes(reserved1));
-        buffer.put(FIELD_INSTANCE_ID.bytes(0L));
-        buffer.put(FIELD_TYPE.bytes(effect.getType().intValue()));
-        buffer.put(FIELD_SPEED.bytes(effect.getSpeed()));
-        buffer.put(FIELD_DURATION.bytes(effect.getDuration()));
-        buffer.put(FIELD_RESERVED_19_TO_26.bytes(reserved19to22));
-        buffer.put(FIELD_RESERVED_19_TO_26.bytes(reserved23to26));
-        for (int i = 0; i < 8; i++) {
-            buffer.put(FIELD_PARAMETER_27_TO_58.bytes(0L));
-        }
-        buffer.put(FIELD_PALETTE_COUNT.bytes(effect.getPalette().length));
-        HSBK[] palette = effect.getPalette();
-        for (int i = 0; i < palette.length; i++) {
-            buffer.put(FIELD_PALETTE_60_TO_187.bytes(palette[i]));
-        }
-        HSBK hsbkZero = new HSBK(0, 0, 0, 0);
-        for (int i = 0; i < 16 - palette.length; i++) {
-            buffer.put(FIELD_PALETTE_60_TO_187.bytes(hsbkZero));
-        }
-        if (logger.isDebugEnabled()) {
-            logger.debug("SetTileEffectRequest: type={}, speed={}, duration={}, palette_count={}", effect.getType(),
-                    effect.getSpeed(), effect.getDuration(), palette.length);
-            for (int i = 0; i < palette.length; i++) {
-                logger.debug("SetTileEffectRequest palette[{}] = {}", i, palette[i]);
-            }
-        }
-        return buffer;
-    }
-
-    @Override
-    public int[] expectedResponses() {
-        return new int[] {};
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/SignalStrength.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/SignalStrength.java
deleted file mode 100644 (file)
index 5a10b8a..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-/**
- * The signal strength of a light.
- *
- * @author Wouter Born - Add signal strength channel
- */
-public class SignalStrength {
-
-    private double milliWatts;
-
-    public SignalStrength(double milliWatts) {
-        this.milliWatts = milliWatts;
-    }
-
-    /**
-     * Returns the signal strength.
-     *
-     * @return the signal strength in milliwatts (mW).
-     */
-    public double getMilliWatts() {
-        return milliWatts;
-    }
-
-    /**
-     * Returns the signal strength as a quality percentage:
-     * <ul>
-     * <li>RSSI <= -100: returns 0
-     * <li>-100 < RSSI < -50: returns a value between 0 and 1 (linearly distributed)
-     * <li>RSSI >= -50: returns 1
-     * <ul>
-     *
-     * @return a value between 0 and 1. 0 being worst strength and 1
-     *         being best strength.
-     */
-    public double toQualityPercentage() {
-        return Math.min(100, Math.max(0, 2 * (toRSSI() + 100))) / 100;
-    }
-
-    /**
-     * Returns the signal strength as a quality rating.
-     *
-     * @return one of the values: 0, 1, 2, 3 or 4. 0 being worst strength and 4
-     *         being best strength.
-     */
-    public byte toQualityRating() {
-        return (byte) Math.round(toQualityPercentage() * 4);
-    }
-
-    /**
-     * Returns the received signal strength indicator (RSSI).
-     *
-     * @return a value <= 0. 0 being best strength and more negative values indicate worser strength.
-     */
-    public double toRSSI() {
-        return 10 * Math.log10(milliWatts);
-    }
-
-    @Override
-    public String toString() {
-        return "SignalStrength [milliWatts=" + milliWatts + ", rssi=" + Math.round(toRSSI()) + "]";
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/StateGroupResponse.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/StateGroupResponse.java
deleted file mode 100644 (file)
index 274a9c5..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import java.nio.ByteBuffer;
-
-import org.openhab.binding.lifx.internal.fields.ByteField;
-import org.openhab.binding.lifx.internal.fields.Field;
-import org.openhab.binding.lifx.internal.fields.StringField;
-import org.openhab.binding.lifx.internal.fields.UInt64Field;
-
-/**
- * @author Tim Buckley - Initial Contribution
- * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
- */
-public class StateGroupResponse extends Packet {
-
-    public static final int TYPE = 0x35;
-
-    public static final Field<ByteBuffer> FIELD_GROUP = new ByteField(16);
-    public static final Field<String> FIELD_LABEL = new StringField(32).utf8();
-    public static final Field<Long> FIELD_UPDATED_AT = new UInt64Field().little();
-
-    private ByteBuffer group;
-    private String label;
-    private long updatedAt;
-
-    public static int getType() {
-        return TYPE;
-    }
-
-    public ByteBuffer getGroup() {
-        return group;
-    }
-
-    public void setGroup(ByteBuffer group) {
-        this.group = group;
-    }
-
-    public String getLabel() {
-        return label;
-    }
-
-    public void setLabel(String label) {
-        this.label = label;
-    }
-
-    public long getUpdatedAt() {
-        return updatedAt;
-    }
-
-    public void setUpdatedAt(long updatedAt) {
-        this.updatedAt = updatedAt;
-    }
-
-    @Override
-    public int packetType() {
-        return TYPE;
-    }
-
-    @Override
-    protected int packetLength() {
-        return 14;
-    }
-
-    @Override
-    protected void parsePacket(ByteBuffer bytes) {
-        group = FIELD_GROUP.value(bytes);
-        label = FIELD_LABEL.value(bytes);
-        updatedAt = FIELD_UPDATED_AT.value(bytes);
-    }
-
-    @Override
-    protected ByteBuffer packetBytes() {
-        return ByteBuffer.allocate(packetLength()).put(FIELD_GROUP.bytes(group)).put(FIELD_LABEL.bytes(label))
-                .put(FIELD_UPDATED_AT.bytes(updatedAt));
-    }
-
-    @Override
-    public int[] expectedResponses() {
-        return new int[] {};
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/StateHostFirmwareResponse.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/StateHostFirmwareResponse.java
deleted file mode 100644 (file)
index 4eb1730..0000000
+++ /dev/null
@@ -1,87 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import java.nio.ByteBuffer;
-
-import org.openhab.binding.lifx.internal.fields.Field;
-import org.openhab.binding.lifx.internal.fields.UInt64Field;
-import org.openhab.binding.lifx.internal.fields.Version;
-import org.openhab.binding.lifx.internal.fields.VersionField;
-
-/**
- * @author Tim Buckley - Initial Contribution
- * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
- */
-public class StateHostFirmwareResponse extends Packet {
-
-    public static final int TYPE = 0x0F;
-
-    public static final Field<Long> FIELD_BUILD = new UInt64Field().little();
-    public static final Field<Long> FIELD_RESERVED = new UInt64Field().little();
-    public static final Field<Version> FIELD_VERSION = new VersionField().little();
-
-    private long build;
-    private long reserved;
-    private Version version;
-
-    public long getBuild() {
-        return build;
-    }
-
-    public void setBuild(long build) {
-        this.build = build;
-    }
-
-    public Version getVersion() {
-        return version;
-    }
-
-    public void setVersion(Version version) {
-        this.version = version;
-    }
-
-    public StateHostFirmwareResponse() {
-        setTagged(false);
-        setAddressable(true);
-        setResponseRequired(true);
-    }
-
-    @Override
-    public int packetType() {
-        return TYPE;
-    }
-
-    @Override
-    protected int packetLength() {
-        return 20;
-    }
-
-    @Override
-    protected void parsePacket(ByteBuffer bytes) {
-        build = FIELD_BUILD.value(bytes);
-        reserved = FIELD_RESERVED.value(bytes);
-        version = FIELD_VERSION.value(bytes);
-    }
-
-    @Override
-    protected ByteBuffer packetBytes() {
-        return ByteBuffer.allocate(packetLength()).put(FIELD_BUILD.bytes(build)).put(FIELD_RESERVED.bytes(reserved))
-                .put(FIELD_VERSION.bytes(version));
-    }
-
-    @Override
-    public int[] expectedResponses() {
-        return new int[] {};
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/StateHostInfoResponse.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/StateHostInfoResponse.java
deleted file mode 100644 (file)
index 5b4b712..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import java.nio.ByteBuffer;
-
-import org.openhab.binding.lifx.internal.fields.ByteField;
-import org.openhab.binding.lifx.internal.fields.Field;
-import org.openhab.binding.lifx.internal.fields.FloatField;
-import org.openhab.binding.lifx.internal.fields.UInt32Field;
-
-/**
- * @author Tim Buckley - Initial Contribution
- * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
- */
-public class StateHostInfoResponse extends Packet {
-
-    public static final int TYPE = 0x0D;
-
-    public static final Field<Float> FIELD_SIGNAL = new FloatField().little();
-    public static final Field<Long> FIELD_TX = new UInt32Field().little();
-    public static final Field<Long> FIELD_RX = new UInt32Field().little();
-    public static final Field<ByteBuffer> FIELD_RESERVED_5 = new ByteField(2);
-
-    private float signal;
-    private long tx;
-    private long rx;
-
-    public SignalStrength getSignalStrength() {
-        return new SignalStrength(signal);
-    }
-
-    public long getTx() {
-        return tx;
-    }
-
-    public long getRx() {
-        return rx;
-    }
-
-    public StateHostInfoResponse() {
-        setTagged(false);
-        setAddressable(true);
-        setResponseRequired(true);
-    }
-
-    @Override
-    public int packetType() {
-        return TYPE;
-    }
-
-    @Override
-    protected int packetLength() {
-        return 14;
-    }
-
-    @Override
-    protected void parsePacket(ByteBuffer bytes) {
-        signal = FIELD_SIGNAL.value(bytes);
-        tx = FIELD_TX.value(bytes);
-        rx = FIELD_RX.value(bytes);
-    }
-
-    @Override
-    protected ByteBuffer packetBytes() {
-        return ByteBuffer.allocate(packetLength()).put(FIELD_SIGNAL.bytes(signal)).put(FIELD_TX.bytes(tx))
-                .put(FIELD_RX.bytes(rx));
-    }
-
-    @Override
-    public int[] expectedResponses() {
-        return new int[] {};
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/StateInfoResponse.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/StateInfoResponse.java
deleted file mode 100644 (file)
index 5b7e914..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import java.nio.ByteBuffer;
-
-import org.openhab.binding.lifx.internal.fields.Field;
-import org.openhab.binding.lifx.internal.fields.UInt64Field;
-
-/**
- * @author Tim Buckley - Initial Contribution
- * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
- */
-public class StateInfoResponse extends Packet {
-
-    public static final int TYPE = 0x23;
-
-    public static final Field<Long> FIELD_TIME = new UInt64Field().little();
-    public static final Field<Long> FIELD_UPTIME = new UInt64Field().little();
-    public static final Field<Long> FIELD_DOWNTIME = new UInt64Field().little();
-
-    private long time;
-    private long uptime;
-    private long downtime;
-
-    public long getTime() {
-        return time;
-    }
-
-    public void setTime(long time) {
-        this.time = time;
-    }
-
-    public long getUptime() {
-        return uptime;
-    }
-
-    public void setUptime(long uptime) {
-        this.uptime = uptime;
-    }
-
-    public long getDowntime() {
-        return downtime;
-    }
-
-    public void setDowntime(long downtime) {
-        this.downtime = downtime;
-    }
-
-    public StateInfoResponse() {
-        setTagged(false);
-        setAddressable(true);
-        setResponseRequired(true);
-    }
-
-    @Override
-    public int packetType() {
-        return TYPE;
-    }
-
-    @Override
-    protected int packetLength() {
-        return 24;
-    }
-
-    @Override
-    protected void parsePacket(ByteBuffer bytes) {
-        time = FIELD_TIME.value(bytes);
-        uptime = FIELD_UPTIME.value(bytes);
-        downtime = FIELD_DOWNTIME.value(bytes);
-    }
-
-    @Override
-    protected ByteBuffer packetBytes() {
-        return ByteBuffer.allocate(packetLength()).put(FIELD_TIME.bytes(time)).put(FIELD_UPTIME.bytes(uptime))
-                .put(FIELD_DOWNTIME.bytes(downtime));
-    }
-
-    @Override
-    public int[] expectedResponses() {
-        return new int[] {};
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/StateLabelResponse.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/StateLabelResponse.java
deleted file mode 100644 (file)
index c41afa3..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import java.nio.ByteBuffer;
-
-import org.openhab.binding.lifx.internal.fields.Field;
-import org.openhab.binding.lifx.internal.fields.StringField;
-
-/**
- * @author Tim Buckley - Initial Contribution
- * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
- */
-public class StateLabelResponse extends Packet {
-
-    public static final int TYPE = 0x19;
-
-    public static final Field<String> FIELD_LABEL = new StringField(32).utf8();
-
-    private String label;
-
-    public static int getType() {
-        return TYPE;
-    }
-
-    public static Field<String> getFieldLabel() {
-        return FIELD_LABEL;
-    }
-
-    public String getLabel() {
-        return label;
-    }
-
-    @Override
-    public int packetType() {
-        return TYPE;
-    }
-
-    @Override
-    protected int packetLength() {
-        return 32;
-    }
-
-    @Override
-    protected void parsePacket(ByteBuffer bytes) {
-        label = FIELD_LABEL.value(bytes);
-    }
-
-    @Override
-    protected ByteBuffer packetBytes() {
-        return FIELD_LABEL.bytes(label);
-    }
-
-    @Override
-    public int[] expectedResponses() {
-        return new int[] {};
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/StateLightInfraredResponse.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/StateLightInfraredResponse.java
deleted file mode 100644 (file)
index 9012583..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import java.nio.ByteBuffer;
-
-import org.openhab.binding.lifx.internal.fields.Field;
-import org.openhab.binding.lifx.internal.fields.UInt16Field;
-
-/**
- * @author Wouter Born - Support LIFX 2016 product line-up and infrared functionality
- */
-public class StateLightInfraredResponse extends Packet {
-
-    public static final int TYPE = 0x79;
-
-    public static final Field<Integer> FIELD_STATE = new UInt16Field().little();
-
-    private int infrared;
-
-    public int getInfrared() {
-        return infrared;
-    }
-
-    @Override
-    public int packetType() {
-        return TYPE;
-    }
-
-    @Override
-    protected int packetLength() {
-        return 2;
-    }
-
-    @Override
-    protected void parsePacket(ByteBuffer bytes) {
-        infrared = FIELD_STATE.value(bytes);
-    }
-
-    @Override
-    protected ByteBuffer packetBytes() {
-        return ByteBuffer.allocate(packetLength()).put(FIELD_STATE.bytes(infrared));
-    }
-
-    @Override
-    public int[] expectedResponses() {
-        return new int[] {};
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/StateLightPowerResponse.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/StateLightPowerResponse.java
deleted file mode 100644 (file)
index 6b848af..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import java.nio.ByteBuffer;
-
-import org.openhab.binding.lifx.internal.fields.Field;
-import org.openhab.binding.lifx.internal.fields.UInt16Field;
-
-/**
- * @author Tim Buckley - Initial Contribution
- * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
- */
-public class StateLightPowerResponse extends Packet {
-
-    public static final int TYPE = 0x76;
-
-    public static final Field<Integer> FIELD_STATE = new UInt16Field();
-
-    private PowerState state;
-
-    public PowerState getState() {
-        return state;
-    }
-
-    @Override
-    public int packetType() {
-        return TYPE;
-    }
-
-    @Override
-    protected int packetLength() {
-        return 2;
-    }
-
-    @Override
-    protected void parsePacket(ByteBuffer bytes) {
-        int stateValue = FIELD_STATE.value(bytes);
-        state = PowerState.fromValue(stateValue);
-    }
-
-    @Override
-    protected ByteBuffer packetBytes() {
-        return ByteBuffer.allocate(packetLength()).put(FIELD_STATE.bytes(state.getValue()));
-    }
-
-    @Override
-    public int[] expectedResponses() {
-        return new int[] {};
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/StateLocationResponse.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/StateLocationResponse.java
deleted file mode 100644 (file)
index 35d726a..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import java.nio.ByteBuffer;
-
-import org.openhab.binding.lifx.internal.fields.ByteField;
-import org.openhab.binding.lifx.internal.fields.Field;
-import org.openhab.binding.lifx.internal.fields.StringField;
-import org.openhab.binding.lifx.internal.fields.UInt64Field;
-
-/**
- * @author Tim Buckley - Initial Contribution
- * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
- */
-public class StateLocationResponse extends Packet {
-
-    public static final int TYPE = 0x32;
-
-    public static final Field<ByteBuffer> FIELD_LOCATION = new ByteField(16);
-    public static final Field<String> FIELD_LABEL = new StringField(32).utf8();
-    public static final Field<Long> FIELD_UPDATED_AT = new UInt64Field().little();
-
-    private ByteBuffer location;
-    private String label;
-    private long updatedAt;
-
-    public static int getType() {
-        return TYPE;
-    }
-
-    public ByteBuffer getLocation() {
-        return location;
-    }
-
-    public void setLocation(ByteBuffer location) {
-        this.location = location;
-    }
-
-    public String getLabel() {
-        return label;
-    }
-
-    public void setLabel(String label) {
-        this.label = label;
-    }
-
-    public long getUpdatedAt() {
-        return updatedAt;
-    }
-
-    public void setUpdatedAt(long updatedAt) {
-        this.updatedAt = updatedAt;
-    }
-
-    @Override
-    public int packetType() {
-        return TYPE;
-    }
-
-    @Override
-    protected int packetLength() {
-        return 14;
-    }
-
-    @Override
-    protected void parsePacket(ByteBuffer bytes) {
-        location = FIELD_LOCATION.value(bytes);
-        label = FIELD_LABEL.value(bytes);
-        updatedAt = FIELD_UPDATED_AT.value(bytes);
-    }
-
-    @Override
-    protected ByteBuffer packetBytes() {
-        return ByteBuffer.allocate(packetLength()).put(FIELD_LOCATION.bytes(location)).put(FIELD_LABEL.bytes(label))
-                .put(FIELD_UPDATED_AT.bytes(updatedAt));
-    }
-
-    @Override
-    public int[] expectedResponses() {
-        return new int[] {};
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/StateMultiZoneResponse.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/StateMultiZoneResponse.java
deleted file mode 100644 (file)
index 47f167d..0000000
+++ /dev/null
@@ -1,98 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import java.nio.ByteBuffer;
-
-import org.openhab.binding.lifx.internal.fields.Field;
-import org.openhab.binding.lifx.internal.fields.HSBK;
-import org.openhab.binding.lifx.internal.fields.HSBKField;
-import org.openhab.binding.lifx.internal.fields.UInt8Field;
-
-/**
- * @author Wouter Born - Add support for MultiZone light control
- */
-public class StateMultiZoneResponse extends Packet {
-
-    public static final int TYPE = 0x1FA;
-    public static final int ZONES = 8;
-
-    public static final Field<Integer> FIELD_COUNT = new UInt8Field();
-    public static final Field<Integer> FIELD_INDEX = new UInt8Field();
-    public static final HSBKField FIELD_COLOR = new HSBKField();
-
-    private int count;
-    private int index;
-    private HSBK[] colors = new HSBK[ZONES];
-
-    @Override
-    public String toString() {
-        StringBuilder sb = new StringBuilder();
-        sb.append("count=");
-        sb.append(count);
-        sb.append(", index=");
-        sb.append(index);
-
-        for (int i = 0; i < ZONES; i++) {
-            sb.append(", ");
-            sb.append(colors[i].toString("color[" + i + "]"));
-        }
-
-        return sb.toString();
-    }
-
-    public int getCount() {
-        return count;
-    }
-
-    public int getIndex() {
-        return index;
-    }
-
-    public HSBK[] getColors() {
-        return colors;
-    }
-
-    @Override
-    public int packetType() {
-        return TYPE;
-    }
-
-    @Override
-    protected int packetLength() {
-        return 66;
-    }
-
-    @Override
-    protected void parsePacket(ByteBuffer bytes) {
-        count = FIELD_COUNT.value(bytes);
-        index = FIELD_INDEX.value(bytes);
-        for (int i = 0; i < ZONES; i++) {
-            colors[i] = FIELD_COLOR.value(bytes);
-        }
-    }
-
-    @Override
-    protected ByteBuffer packetBytes() {
-        ByteBuffer bb = ByteBuffer.allocate(packetLength()).put(FIELD_COUNT.bytes(count)).put(FIELD_INDEX.bytes(index));
-        for (int i = 0; i < ZONES; i++) {
-            bb.put(FIELD_COLOR.bytes(colors[i]));
-        }
-        return bb;
-    }
-
-    @Override
-    public int[] expectedResponses() {
-        return new int[] {};
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/StatePowerResponse.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/StatePowerResponse.java
deleted file mode 100644 (file)
index b6689a6..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import java.nio.ByteBuffer;
-
-import org.openhab.binding.lifx.internal.fields.Field;
-import org.openhab.binding.lifx.internal.fields.UInt16Field;
-
-/**
- * @author Tim Buckley - Initial Contribution
- * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
- */
-public class StatePowerResponse extends Packet {
-
-    public static final int TYPE = 0x16;
-
-    public static final Field<Integer> FIELD_STATE = new UInt16Field();
-
-    private PowerState state;
-
-    public PowerState getState() {
-        return state;
-    }
-
-    @Override
-    public int packetType() {
-        return TYPE;
-    }
-
-    @Override
-    protected int packetLength() {
-        return 2;
-    }
-
-    @Override
-    protected void parsePacket(ByteBuffer bytes) {
-        int stateValue = FIELD_STATE.value(bytes);
-        state = PowerState.fromValue(stateValue);
-    }
-
-    @Override
-    protected ByteBuffer packetBytes() {
-        return ByteBuffer.allocate(packetLength()).put(FIELD_STATE.bytes(state.getValue()));
-    }
-
-    @Override
-    public int[] expectedResponses() {
-        return new int[] {};
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/StateResponse.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/StateResponse.java
deleted file mode 100644 (file)
index ff3bf40..0000000
+++ /dev/null
@@ -1,98 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import java.nio.ByteBuffer;
-
-import org.openhab.binding.lifx.internal.fields.Field;
-import org.openhab.binding.lifx.internal.fields.HSBK;
-import org.openhab.binding.lifx.internal.fields.HSBKField;
-import org.openhab.binding.lifx.internal.fields.StringField;
-import org.openhab.binding.lifx.internal.fields.UInt16Field;
-import org.openhab.binding.lifx.internal.fields.UInt64Field;
-
-/**
- * @author Tim Buckley - Initial Contribution
- * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
- */
-public class StateResponse extends Packet {
-
-    public static final int TYPE = 0x6B;
-
-    public static final HSBKField FIELD_COLOR = new HSBKField();
-    public static final Field<Integer> FIELD_DIM = new UInt16Field().little();
-    public static final Field<Integer> FIELD_POWER = new UInt16Field();
-    public static final Field<String> FIELD_LABEL = new StringField(32);
-    public static final Field<Long> FIELD_TAGS = new UInt64Field();
-
-    private HSBK color;
-    private int dim;
-    private PowerState power;
-    private String label;
-    private long tags;
-
-    @Override
-    public String toString() {
-        return color.toString("color") + ", dim=" + dim + ", power=" + power + ", label=" + label;
-    }
-
-    public HSBK getColor() {
-        return color;
-    }
-
-    public int getDim() {
-        return dim;
-    }
-
-    public PowerState getPower() {
-        return power;
-    }
-
-    public String getLabel() {
-        return label;
-    }
-
-    public long getTags() {
-        return tags;
-    }
-
-    @Override
-    public int packetType() {
-        return TYPE;
-    }
-
-    @Override
-    protected int packetLength() {
-        return 52;
-    }
-
-    @Override
-    protected void parsePacket(ByteBuffer bytes) {
-        color = FIELD_COLOR.value(bytes);
-        dim = FIELD_DIM.value(bytes);
-        power = PowerState.fromValue(FIELD_POWER.value(bytes));
-        label = FIELD_LABEL.value(bytes);
-        tags = FIELD_TAGS.value(bytes);
-    }
-
-    @Override
-    protected ByteBuffer packetBytes() {
-        return ByteBuffer.allocate(packetLength()).put(FIELD_COLOR.bytes(color)).put(FIELD_DIM.bytes(dim))
-                .put(FIELD_POWER.bytes(power.getValue())).put(FIELD_LABEL.bytes(label)).put(FIELD_TAGS.bytes(tags));
-    }
-
-    @Override
-    public int[] expectedResponses() {
-        return new int[] {};
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/StateServiceResponse.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/StateServiceResponse.java
deleted file mode 100644 (file)
index 84c6a23..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import java.nio.ByteBuffer;
-
-import org.openhab.binding.lifx.internal.fields.Field;
-import org.openhab.binding.lifx.internal.fields.LittleField;
-import org.openhab.binding.lifx.internal.fields.UInt32Field;
-import org.openhab.binding.lifx.internal.fields.UInt8Field;
-
-/**
- * @author Tim Buckley - Initial Contribution
- * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
- */
-public class StateServiceResponse extends Packet {
-
-    public static final int TYPE = 0x03;
-
-    public static final Field<Integer> FIELD_SERVICE = new UInt8Field();
-    public static final Field<Long> FIELD_PORT = new LittleField<>(new UInt32Field());
-
-    private int service;
-    private long port;
-
-    public int getService() {
-        return service;
-    }
-
-    public long getPort() {
-        return port;
-    }
-
-    public StateServiceResponse() {
-    }
-
-    @Override
-    protected void parsePacket(ByteBuffer bytes) {
-        service = FIELD_SERVICE.value(bytes);
-        port = FIELD_PORT.value(bytes);
-    }
-
-    @Override
-    public int packetType() {
-        return TYPE;
-    }
-
-    @Override
-    protected int packetLength() {
-        return 5;
-    }
-
-    @Override
-    protected ByteBuffer packetBytes() {
-        return ByteBuffer.allocate(packetLength()).put(FIELD_SERVICE.bytes(service)).put(FIELD_PORT.bytes(port));
-    }
-
-    @Override
-    public int[] expectedResponses() {
-        return new int[] {};
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/StateTileEffectResponse.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/StateTileEffectResponse.java
deleted file mode 100644 (file)
index 6bfb630..0000000
+++ /dev/null
@@ -1,144 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import java.nio.ByteBuffer;
-
-import org.openhab.binding.lifx.internal.fields.Field;
-import org.openhab.binding.lifx.internal.fields.HSBK;
-import org.openhab.binding.lifx.internal.fields.HSBKField;
-import org.openhab.binding.lifx.internal.fields.UInt32Field;
-import org.openhab.binding.lifx.internal.fields.UInt64Field;
-import org.openhab.binding.lifx.internal.fields.UInt8Field;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Implementation of StateTileEffect packet
- *
- * @author Pawel Pieczul - Initial Contribution
- */
-public class StateTileEffectResponse extends Packet {
-
-    public static final int TYPE = 0x2D0;
-
-    // size.from.to....what
-    // ------------------------------
-    // 1....0....0.....reserved
-    // 4....1....4.....instance ID
-    // 1....5....5.....effect type
-    // 4....6....9.....speed
-    // 8....10...17....duration
-    // 4....18...21....reserved
-    // 4....22...25....reserved
-    // 32...26...57....parameters (8*32 bits)
-    // 1....58...58....palette count
-    // 128..59...186...palette (16*8 bits)
-
-    private static final Field<Integer> FIELD_RESERVED_0 = new UInt8Field();
-    private static final Field<Long> FIELD_INSTANCE_ID = new UInt32Field().little();
-    private static final Field<Integer> FIELD_TYPE = new UInt8Field();
-    private static final Field<Long> FIELD_SPEED = new UInt32Field().little();
-    private static final Field<Long> FIELD_DURATION = new UInt64Field().little();
-    private static final Field<Long> FIELD_RESERVED_18_TO_25 = new UInt32Field().little();
-    private static final Field<Long> FIELD_PARAMETER_26_TO_57 = new UInt32Field().little();
-    private static final Field<Integer> FIELD_PALETTE_COUNT = new UInt8Field();
-    private static final Field<HSBK> FIELD_PALETTE_59_TO_186 = new HSBKField();
-
-    private Integer reserved0 = 0;
-    private Long reserved18to21 = 0L;
-    private Long reserved22to25 = 0L;
-    private Effect effect;
-
-    private final Logger logger = LoggerFactory.getLogger(StateTileEffectResponse.class);
-
-    public Effect getEffect() {
-        return effect;
-    }
-
-    @Override
-    public int packetType() {
-        return TYPE;
-    }
-
-    @Override
-    protected int packetLength() {
-        return 187;
-    }
-
-    @Override
-    protected void parsePacket(ByteBuffer bytes) {
-        reserved0 = FIELD_RESERVED_0.value(bytes);
-        Long instanceId = FIELD_INSTANCE_ID.value(bytes);
-        Integer effectType = FIELD_TYPE.value(bytes);
-        Long speed = FIELD_SPEED.value(bytes);
-        Long duration = FIELD_DURATION.value(bytes);
-        reserved18to21 = FIELD_RESERVED_18_TO_25.value(bytes);
-        reserved22to25 = FIELD_RESERVED_18_TO_25.value(bytes);
-        Long[] parameters = new Long[8];
-        for (int i = 0; i < 8; i++) {
-            parameters[i] = FIELD_PARAMETER_26_TO_57.value(bytes);
-        }
-        Integer paletteCount = FIELD_PALETTE_COUNT.value(bytes);
-        HSBK[] palette = new HSBK[paletteCount];
-        for (int i = 0; i < palette.length; i++) {
-            palette[i] = FIELD_PALETTE_59_TO_186.value(bytes);
-        }
-        try {
-            effect = new Effect(effectType, speed, duration, palette);
-        } catch (IllegalArgumentException e) {
-            logger.debug("Wrong effect type received: {}", effectType);
-            effect = null;
-        }
-        if (logger.isDebugEnabled()) {
-            logger.debug("StateTileEffectResponse: instanceId={}, type={}, speed={}, duration={}, palette_count={}",
-                    instanceId, effectType, speed, duration, paletteCount);
-            logger.debug("StateTileEffectResponse parameters=[{}, {}, {}, {}, {}, {}, {}, {}]", parameters[0],
-                    parameters[1], parameters[2], parameters[3], parameters[4], parameters[5], parameters[6],
-                    parameters[7]);
-            for (int i = 0; i < palette.length; i++) {
-                logger.debug("StateTileEffectResponse palette[{}] = {}", i, palette[i]);
-            }
-        }
-    }
-
-    @Override
-    protected ByteBuffer packetBytes() {
-        ByteBuffer buffer = ByteBuffer.allocate(packetLength());
-        buffer.put(FIELD_RESERVED_0.bytes(reserved0));
-        buffer.put(FIELD_INSTANCE_ID.bytes(0L));
-        buffer.put(FIELD_TYPE.bytes(effect.getType().intValue()));
-        buffer.put(FIELD_SPEED.bytes(effect.getSpeed()));
-        buffer.put(FIELD_DURATION.bytes(effect.getDuration()));
-        buffer.put(FIELD_RESERVED_18_TO_25.bytes(reserved18to21));
-        buffer.put(FIELD_RESERVED_18_TO_25.bytes(reserved22to25));
-        for (int i = 0; i < 8; i++) {
-            buffer.put(FIELD_PARAMETER_26_TO_57.bytes(0L));
-        }
-        HSBK[] palette = effect.getPalette();
-        buffer.put(FIELD_PALETTE_COUNT.bytes(palette.length));
-        for (int i = 0; i < palette.length; i++) {
-            buffer.put(FIELD_PALETTE_59_TO_186.bytes(palette[i]));
-        }
-        HSBK hsbkZero = new HSBK(0, 0, 0, 0);
-        for (int i = 0; i < 16 - palette.length; i++) {
-            buffer.put(FIELD_PALETTE_59_TO_186.bytes(hsbkZero));
-        }
-        return buffer;
-    }
-
-    @Override
-    public int[] expectedResponses() {
-        return new int[] {};
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/StateVersionResponse.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/StateVersionResponse.java
deleted file mode 100644 (file)
index 410dc37..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import java.nio.ByteBuffer;
-
-import org.openhab.binding.lifx.internal.fields.Field;
-import org.openhab.binding.lifx.internal.fields.UInt32Field;
-
-/**
- * @author Tim Buckley - Initial Contribution
- * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
- */
-public class StateVersionResponse extends Packet {
-
-    public static final int TYPE = 0x21;
-
-    public static final Field<Long> FIELD_VENDOR = new UInt32Field().little();
-    public static final Field<Long> FIELD_PRODUCT = new UInt32Field().little();
-    public static final Field<Long> FIELD_VERSION = new UInt32Field().little();
-
-    private long vendor;
-    private long product;
-    private long version;
-
-    public long getVendor() {
-        return vendor;
-    }
-
-    public void setVendor(long build) {
-        this.vendor = build;
-    }
-
-    public long getProduct() {
-        return product;
-    }
-
-    public void setProduct(long product) {
-        this.product = product;
-    }
-
-    public long getVersion() {
-        return version;
-    }
-
-    public void setVersion(long version) {
-        this.version = version;
-    }
-
-    public StateVersionResponse() {
-        setTagged(false);
-        setAddressable(true);
-        setResponseRequired(true);
-    }
-
-    @Override
-    public int packetType() {
-        return TYPE;
-    }
-
-    @Override
-    protected int packetLength() {
-        return 12;
-    }
-
-    @Override
-    protected void parsePacket(ByteBuffer bytes) {
-        vendor = FIELD_VENDOR.value(bytes);
-        product = FIELD_PRODUCT.value(bytes);
-        version = FIELD_VERSION.value(bytes);
-    }
-
-    @Override
-    protected ByteBuffer packetBytes() {
-        return ByteBuffer.allocate(packetLength()).put(FIELD_VENDOR.bytes(vendor)).put(FIELD_PRODUCT.bytes(product))
-                .put(FIELD_VERSION.bytes(version));
-    }
-
-    @Override
-    public int[] expectedResponses() {
-        return new int[] {};
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/StateWifiFirmwareResponse.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/StateWifiFirmwareResponse.java
deleted file mode 100644 (file)
index b0cbc95..0000000
+++ /dev/null
@@ -1,87 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import java.nio.ByteBuffer;
-
-import org.openhab.binding.lifx.internal.fields.Field;
-import org.openhab.binding.lifx.internal.fields.UInt64Field;
-import org.openhab.binding.lifx.internal.fields.Version;
-import org.openhab.binding.lifx.internal.fields.VersionField;
-
-/**
- * @author Tim Buckley - Initial Contribution
- * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
- */
-public class StateWifiFirmwareResponse extends Packet {
-
-    public static final int TYPE = 0x13;
-
-    public static final Field<Long> FIELD_BUILD = new UInt64Field().little();
-    public static final Field<Long> FIELD_RESERVED = new UInt64Field().little();
-    public static final Field<Version> FIELD_VERSION = new VersionField().little();
-
-    private long build;
-    private long reserved;
-    private Version version;
-
-    public long getBuild() {
-        return build;
-    }
-
-    public void setBuild(long build) {
-        this.build = build;
-    }
-
-    public Version getVersion() {
-        return version;
-    }
-
-    public void setVersion(Version version) {
-        this.version = version;
-    }
-
-    public StateWifiFirmwareResponse() {
-        setTagged(false);
-        setAddressable(true);
-        setResponseRequired(true);
-    }
-
-    @Override
-    public int packetType() {
-        return TYPE;
-    }
-
-    @Override
-    protected int packetLength() {
-        return 20;
-    }
-
-    @Override
-    protected void parsePacket(ByteBuffer bytes) {
-        build = FIELD_BUILD.value(bytes);
-        reserved = FIELD_RESERVED.value(bytes);
-        version = FIELD_VERSION.value(bytes);
-    }
-
-    @Override
-    protected ByteBuffer packetBytes() {
-        return ByteBuffer.allocate(packetLength()).put(FIELD_BUILD.bytes(build)).put(FIELD_RESERVED.bytes(reserved))
-                .put(FIELD_VERSION.bytes(version));
-    }
-
-    @Override
-    public int[] expectedResponses() {
-        return new int[] {};
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/StateWifiInfoResponse.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/StateWifiInfoResponse.java
deleted file mode 100644 (file)
index 3cb832b..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import java.nio.ByteBuffer;
-
-import org.openhab.binding.lifx.internal.fields.Field;
-import org.openhab.binding.lifx.internal.fields.FloatField;
-import org.openhab.binding.lifx.internal.fields.UInt16Field;
-import org.openhab.binding.lifx.internal.fields.UInt32Field;
-
-/**
- * @author Tim Buckley - Initial Contribution
- * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
- */
-public class StateWifiInfoResponse extends Packet {
-
-    public static final int TYPE = 0x11;
-
-    public static final Field<Float> FIELD_SIGNAL = new FloatField().little();
-    public static final Field<Long> FIELD_RX = new UInt32Field().little();
-    public static final Field<Long> FIELD_TX = new UInt32Field().little();
-    public static final Field<Integer> FIELD_TEMP = new UInt16Field();
-
-    private float signal;
-    private long rx;
-    private long tx;
-    private int mcuTemperature;
-
-    public SignalStrength getSignalStrength() {
-        return new SignalStrength(signal);
-    }
-
-    public long getRx() {
-        return rx;
-    }
-
-    public long getTx() {
-        return tx;
-    }
-
-    public int getMcuTemperature() {
-        return mcuTemperature;
-    }
-
-    @Override
-    public int packetType() {
-        return TYPE;
-    }
-
-    @Override
-    protected int packetLength() {
-        return 14;
-    }
-
-    @Override
-    protected void parsePacket(ByteBuffer bytes) {
-        signal = FIELD_SIGNAL.value(bytes);
-        rx = FIELD_RX.value(bytes);
-        tx = FIELD_TX.value(bytes);
-        mcuTemperature = FIELD_TEMP.value(bytes);
-    }
-
-    @Override
-    protected ByteBuffer packetBytes() {
-        return ByteBuffer.allocate(packetLength()).put(FIELD_SIGNAL.bytes(signal)).put(FIELD_RX.bytes(rx))
-                .put(FIELD_TX.bytes(tx)).put(FIELD_TEMP.bytes(mcuTemperature));
-    }
-
-    @Override
-    public int[] expectedResponses() {
-        return new int[] {};
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/StateZoneResponse.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/StateZoneResponse.java
deleted file mode 100644 (file)
index e95135f..0000000
+++ /dev/null
@@ -1,81 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import java.nio.ByteBuffer;
-
-import org.openhab.binding.lifx.internal.fields.Field;
-import org.openhab.binding.lifx.internal.fields.HSBK;
-import org.openhab.binding.lifx.internal.fields.HSBKField;
-import org.openhab.binding.lifx.internal.fields.UInt8Field;
-
-/**
- * @author Wouter Born - Add support for MultiZone light control
- */
-public class StateZoneResponse extends Packet {
-
-    public static final int TYPE = 0x1F7;
-
-    public static final Field<Integer> FIELD_COUNT = new UInt8Field();
-    public static final Field<Integer> FIELD_INDEX = new UInt8Field();
-    public static final HSBKField FIELD_COLOR = new HSBKField();
-
-    private int count;
-    private int index;
-    private HSBK color;
-
-    @Override
-    public String toString() {
-        return "count=" + count + ", index=" + index + ", " + color.toString("color");
-    }
-
-    public int getCount() {
-        return count;
-    }
-
-    public int getIndex() {
-        return index;
-    }
-
-    public HSBK getColor() {
-        return color;
-    }
-
-    @Override
-    public int packetType() {
-        return TYPE;
-    }
-
-    @Override
-    protected int packetLength() {
-        return 10;
-    }
-
-    @Override
-    protected void parsePacket(ByteBuffer bytes) {
-        count = FIELD_COUNT.value(bytes);
-        index = FIELD_INDEX.value(bytes);
-        color = FIELD_COLOR.value(bytes);
-    }
-
-    @Override
-    protected ByteBuffer packetBytes() {
-        return ByteBuffer.allocate(packetLength()).put(FIELD_COUNT.bytes(count)).put(FIELD_INDEX.bytes(index))
-                .put(FIELD_COLOR.bytes(color));
-    }
-
-    @Override
-    public int[] expectedResponses() {
-        return new int[] {};
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/TagLabelsResponse.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/TagLabelsResponse.java
deleted file mode 100644 (file)
index ef3aa17..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import java.nio.ByteBuffer;
-
-import org.openhab.binding.lifx.internal.fields.Field;
-import org.openhab.binding.lifx.internal.fields.StringField;
-import org.openhab.binding.lifx.internal.fields.UInt64Field;
-
-/**
- * @author Tim Buckley - Initial Contribution
- * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
- */
-public class TagLabelsResponse extends Packet {
-
-    public static final int TYPE = 0x1F;
-
-    public static final Field<Long> FIELD_TAGS = new UInt64Field();
-    public static final Field<String> FIELD_LABEL = new StringField(32).utf8();
-
-    private long tags;
-    private String label;
-
-    public long getTags() {
-        return tags;
-    }
-
-    public String getLabel() {
-        return label;
-    }
-
-    @Override
-    public int packetType() {
-        return TYPE;
-    }
-
-    @Override
-    protected int packetLength() {
-        return 40;
-    }
-
-    @Override
-    protected void parsePacket(ByteBuffer bytes) {
-        tags = FIELD_TAGS.value(bytes);
-        label = FIELD_LABEL.value(bytes);
-    }
-
-    @Override
-    protected ByteBuffer packetBytes() {
-        return ByteBuffer.allocate(packetLength()).put(FIELD_TAGS.bytes(tags)).put(FIELD_LABEL.bytes(label));
-    }
-
-    @Override
-    public int[] expectedResponses() {
-        return new int[] {};
-    }
-}
diff --git a/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/TagsResponse.java b/bundles/org.openhab.binding.lifx/src/main/java/org/openhab/binding/lifx/internal/protocol/TagsResponse.java
deleted file mode 100644 (file)
index 257f28e..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.lifx.internal.protocol;
-
-import java.nio.ByteBuffer;
-
-import org.openhab.binding.lifx.internal.fields.Field;
-import org.openhab.binding.lifx.internal.fields.UInt64Field;
-
-/**
- * @author Tim Buckley - Initial Contribution
- * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
- */
-public class TagsResponse extends Packet {
-
-    public static final int TYPE = 0x1C;
-
-    public static final Field<Long> FIELD_TAGS = new UInt64Field();
-
-    private long tags;
-
-    public long getTags() {
-        return tags;
-    }
-
-    @Override
-    public int packetType() {
-        return TYPE;
-    }
-
-    @Override
-    protected int packetLength() {
-        return 8;
-    }
-
-    @Override
-    protected void parsePacket(ByteBuffer bytes) {
-        tags = FIELD_TAGS.value(bytes);
-    }
-
-    @Override
-    protected ByteBuffer packetBytes() {
-        return ByteBuffer.allocate(packetLength()).put(FIELD_TAGS.bytes(tags));
-    }
-
-    @Override
-    public int[] expectedResponses() {
-        return new int[] {};
-    }
-}
index 7218a29f3dcc57875f1952d52850229913ac2dfe..03c8135e2d7f39ac56da2c401ce5ed660a7be514 100644 (file)
@@ -17,8 +17,8 @@ import java.math.RoundingMode;
 import java.util.UUID;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.openhab.binding.lifx.internal.LifxProduct.TemperatureRange;
 import org.openhab.binding.lifx.internal.fields.HSBK;
-import org.openhab.binding.lifx.internal.protocol.Product.TemperatureRange;
 import org.openhab.core.library.types.DecimalType;
 import org.openhab.core.library.types.IncreaseDecreaseType;
 import org.openhab.core.library.types.PercentType;
@@ -26,7 +26,7 @@ import org.openhab.core.library.types.PercentType;
 /**
  * Utility class for sharing message utility methods between objects.
  *
- * @author Wouter Born - Extracted methods from LifxLightHandler
+ * @author Wouter Born - Initial contribution
  */
 @NonNullByDefault
 public final class LifxMessageUtil {
index 4d4774801447a677e99a2e9e7fcadb60c2226f99..eca9a34a17efaa3d9c4ee81af8179a22667b8dfc 100644 (file)
@@ -34,7 +34,7 @@ import org.slf4j.LoggerFactory;
  * The {@link LifxNetworkUtil} provides network interface information to the LIFX binding objects. The information is
  * updated when it is older than {@link #UPDATE_INTERVAL_MILLIS}.
  *
- * @author Wouter Born - Periodically update available interface information
+ * @author Wouter Born - Initial contribution
  */
 @NonNullByDefault
 public final class LifxNetworkUtil {
index 10dec21b90a22e0b4c7d62f2c20793724872a366..1630ec296acd5afe99ed10ce69a7082c515ac5d6 100644 (file)
@@ -32,17 +32,17 @@ import java.util.function.BiConsumer;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.openhab.binding.lifx.internal.LifxSelectorContext;
+import org.openhab.binding.lifx.internal.dto.Packet;
+import org.openhab.binding.lifx.internal.dto.PacketFactory;
+import org.openhab.binding.lifx.internal.dto.PacketHandler;
 import org.openhab.binding.lifx.internal.fields.MACAddress;
-import org.openhab.binding.lifx.internal.protocol.Packet;
-import org.openhab.binding.lifx.internal.protocol.PacketFactory;
-import org.openhab.binding.lifx.internal.protocol.PacketHandler;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
  * Utility class for sharing {@link Selector} logic between objects.
  *
- * @author Wouter Born - Make selector logic reusable between discovery and handlers
+ * @author Wouter Born - Initial contribution
  */
 @NonNullByDefault
 public class LifxSelectorUtil {
index 397df9e07ea02129c5497f41a0cfa9a070111ed6..8001d1e74b5e7d876b77b78455bb221c1ed89937 100644 (file)
@@ -31,7 +31,7 @@ import org.slf4j.LoggerFactory;
  * sent to LIFX lights. The LIFX LAN Protocol Specification states that lights can process up to 20 messages per second,
  * not more.
  *
- * @author Karel Goderis - Initial Contribution
+ * @author Karel Goderis - Initial contribution
  * @author Wouter Born - Deadlock fix
  */
 @NonNullByDefault
diff --git a/bundles/org.openhab.binding.lifx/src/test/java/org/openhab/binding/lifx/internal/fields/MACAddressTest.java b/bundles/org.openhab.binding.lifx/src/test/java/org/openhab/binding/lifx/internal/fields/MACAddressTest.java
new file mode 100644 (file)
index 0000000..78b620b
--- /dev/null
@@ -0,0 +1,88 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.lifx.internal.fields;
+
+import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+import static org.openhab.binding.lifx.internal.fields.MACAddress.BROADCAST_ADDRESS;
+import static org.openhab.core.util.HexUtils.bytesToHex;
+
+import java.nio.ByteBuffer;
+
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.junit.jupiter.api.Test;
+import org.openhab.core.util.HexUtils;
+
+/**
+ * Tests {@link MACAddress}.
+ *
+ * @author Wouter Born - Initial contribution
+ */
+@NonNullByDefault
+public class MACAddressTest {
+
+    @Test
+    public void broadcastAddress() {
+        assertThat(BROADCAST_ADDRESS.getAsLabel(), is("000000000000"));
+        assertThat(BROADCAST_ADDRESS.getHex(), is("00:00:00:00:00:00"));
+        assertThat(bytesToHex(BROADCAST_ADDRESS.getBytes().array()), is("000000000000"));
+    }
+
+    @Test
+    public void defaultConstructor() {
+        MACAddress macAddress = new MACAddress();
+        assertThat(macAddress.getAsLabel(), is("000000000000"));
+        assertThat(macAddress.getHex(), is("00:00:00:00:00:00"));
+    }
+
+    @Test
+    public void constructFromByteBuffer() {
+        MACAddress macAddress = new MACAddress(ByteBuffer.wrap(HexUtils.hexToBytes("D073D5123456")));
+        assertThat(macAddress.getAsLabel(), is("D073D5123456"));
+        assertThat(macAddress.getHex(), is("D0:73:D5:12:34:56"));
+        assertThat(bytesToHex(macAddress.getBytes().array()), is("D073D5123456"));
+    }
+
+    @Test
+    public void constructFromString() {
+        MACAddress macAddress = new MACAddress("D073D5ABCDEF");
+        assertThat(macAddress.getAsLabel(), is("D073D5ABCDEF"));
+        assertThat(macAddress.getHex(), is("D0:73:D5:AB:CD:EF"));
+        assertThat(bytesToHex(macAddress.getBytes().array()), is("D073D5ABCDEF"));
+    }
+
+    @Test
+    public void broadcastAddressComparison() {
+        assertThat(BROADCAST_ADDRESS, is(BROADCAST_ADDRESS));
+        assertThat(BROADCAST_ADDRESS.hashCode(), is(BROADCAST_ADDRESS.hashCode()));
+
+        assertThat(BROADCAST_ADDRESS, is(new MACAddress()));
+        assertThat(BROADCAST_ADDRESS.hashCode(), is(new MACAddress().hashCode()));
+
+        assertThat(BROADCAST_ADDRESS, is(not(new MACAddress("D073D5ABCDEF"))));
+        assertThat(BROADCAST_ADDRESS, is(not(new MACAddress("D073D5ABCDEF").hashCode())));
+    }
+
+    @Test
+    public void macAddressComparison() {
+        assertThat(new MACAddress("D073D5ABCDEF"), is(new MACAddress("D073D5ABCDEF")));
+        assertThat(new MACAddress("D073D5ABCDEF").hashCode(), is(new MACAddress("D073D5ABCDEF").hashCode()));
+
+        assertThat(new MACAddress("D073D5ABCDEF"), is(not(BROADCAST_ADDRESS)));
+        assertThat(new MACAddress("D073D5ABCDEF").hashCode(), is(not(BROADCAST_ADDRESS.hashCode())));
+
+        assertThat(new MACAddress("D073D5ABCDEF"), is(not(new MACAddress("D073D5123456"))));
+        assertThat(new MACAddress("D073D5ABCDEF").hashCode(), is(not(new MACAddress("D073D5123456").hashCode())));
+    }
+}