/**
* The {@link LifxChannelFactory} creates dynamic LIFX channels.
*
- * @author Wouter Born - Add i18n support
+ * @author Wouter Born - Initial contribution
*/
@NonNullByDefault
public interface LifxChannelFactory {
/**
* The {@link LifxChannelFactoryImpl} creates dynamic LIFX channels.
*
- * @author Wouter Born - Add i18n support
+ * @author Wouter Born - Initial contribution
*/
@NonNullByDefault
@Component(service = LifxChannelFactory.class)
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;
/**
* 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 {
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() {
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 {
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;
return configuration;
}
- public Product getProduct() {
+ public LifxProduct getProduct() {
return product;
}
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;
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;
* 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 {
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;
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;
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;
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(),
}
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");
}
ThingUID thingUID = new ThingUID(product.getThingTypeUID(), macAsLabel);
String label = light.label;
- if (StringUtils.isBlank(label)) {
+ if (label == null || label.isBlank()) {
label = product.getName();
}
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 {
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;
* 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 {
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());
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;
/**
* 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 {
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;
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;
* 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 {
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;
--- /dev/null
+/**
+ * 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");
+ }
+}
* 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 {
/**
* 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> {
--- /dev/null
+/**
+ * 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[] {};
+ }
+}
--- /dev/null
+/**
+ * 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;
+ }
+}
--- /dev/null
+/**
+ * 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[] {};
+ }
+}
--- /dev/null
+/**
+ * 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();
+ }
+}
--- /dev/null
+/**
+ * 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);
+ }
+ }
+}
--- /dev/null
+/**
+ * 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[] {};
+ }
+}
--- /dev/null
+/**
+ * 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 };
+ }
+}
--- /dev/null
+/**
+ * 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;
+ }
+}
--- /dev/null
+/**
+ * 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 };
+ }
+}
--- /dev/null
+/**
+ * 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 };
+ }
+}
--- /dev/null
+/**
+ * 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 };
+ }
+}
--- /dev/null
+/**
+ * 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 };
+ }
+}
--- /dev/null
+/**
+ * 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 };
+ }
+}
--- /dev/null
+/**
+ * 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 };
+ }
+}
--- /dev/null
+/**
+ * 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 };
+ }
+}
--- /dev/null
+/**
+ * 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 };
+ }
+}
--- /dev/null
+/**
+ * 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 };
+ }
+}
--- /dev/null
+/**
+ * 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 };
+ }
+}
--- /dev/null
+/**
+ * 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 };
+ }
+}
--- /dev/null
+/**
+ * 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 };
+ }
+}
--- /dev/null
+/**
+ * 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 };
+ }
+}
--- /dev/null
+/**
+ * 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 };
+ }
+}
--- /dev/null
+/**
+ * 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 };
+ }
+}
--- /dev/null
+/**
+ * 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 };
+ }
+}
--- /dev/null
+/**
+ * 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 };
+ }
+}
--- /dev/null
+/**
+ * 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;
+ }
+}
--- /dev/null
+/**
+ * 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);
+ }
+}
--- /dev/null
+/**
+ * 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);
+}
--- /dev/null
+/**
+ * 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;
+ }
+}
--- /dev/null
+/**
+ * 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 };
+ }
+}
--- /dev/null
+/**
+ * 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[] {};
+ }
+}
--- /dev/null
+/**
+ * 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[] {};
+ }
+}
--- /dev/null
+/**
+ * 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[] {};
+ }
+}
--- /dev/null
+/**
+ * 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 };
+ }
+}
--- /dev/null
+/**
+ * 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 };
+ }
+}
--- /dev/null
+/**
+ * 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 };
+ }
+}
--- /dev/null
+/**
+ * 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[] {};
+ }
+}
--- /dev/null
+/**
+ * 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[] {};
+ }
+}
--- /dev/null
+/**
+ * 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()) + "]";
+ }
+}
--- /dev/null
+/**
+ * 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[] {};
+ }
+}
--- /dev/null
+/**
+ * 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[] {};
+ }
+}
--- /dev/null
+/**
+ * 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[] {};
+ }
+}
--- /dev/null
+/**
+ * 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[] {};
+ }
+}
--- /dev/null
+/**
+ * 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[] {};
+ }
+}
--- /dev/null
+/**
+ * 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[] {};
+ }
+}
--- /dev/null
+/**
+ * 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[] {};
+ }
+}
--- /dev/null
+/**
+ * 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[] {};
+ }
+}
--- /dev/null
+/**
+ * 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[] {};
+ }
+}
--- /dev/null
+/**
+ * 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[] {};
+ }
+}
--- /dev/null
+/**
+ * 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[] {};
+ }
+}
--- /dev/null
+/**
+ * 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[] {};
+ }
+}
--- /dev/null
+/**
+ * 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[] {};
+ }
+}
--- /dev/null
+/**
+ * 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[] {};
+ }
+}
--- /dev/null
+/**
+ * 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[] {};
+ }
+}
--- /dev/null
+/**
+ * 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[] {};
+ }
+}
--- /dev/null
+/**
+ * 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[] {};
+ }
+}
--- /dev/null
+/**
+ * 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[] {};
+ }
+}
--- /dev/null
+/**
+ * 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[] {};
+ }
+}
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
- * @author Tim Buckley
+ * @author Tim Buckley - Initial contribution
*/
@NonNullByDefault
public class ByteField extends Field<ByteBuffer> {
*
* @param <T> the field datatype
*
- * @author Tim Buckley
+ * @author Tim Buckley - Initial contribution
*/
@NonNullByDefault
public abstract class Field<T> {
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
- * @author Tim Buckley
+ * @author Tim Buckley - Initial contribution
*/
@NonNullByDefault
public class FloatField extends Field<Float> {
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 {
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> {
/**
* Reads a wrapped field in reversed byte order.
*
- * @author Tim Buckley
+ * @author Tim Buckley - Initial contribution
*/
@NonNullByDefault
public class LittleField<T> extends Field<T> {
*/
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 = "";
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() {
byteStrings.add(String.format("%02X", bytes.get()));
}
- hex = StringUtils.join(byteStrings, ':');
+ hex = String.join(":", byteStrings);
bytes.rewind();
}
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;
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> {
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
- * @author Tim Buckley
+ * @author Tim Buckley - Initial contribution
*/
@NonNullByDefault
public class StringField extends Field<String> {
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
- * @author Tim Buckley
+ * @author Tim Buckley - Initial contribution
*/
@NonNullByDefault
public class UInt16Field extends Field<Integer> {
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
- * @author Tim Buckley
+ * @author Tim Buckley - Initial contribution
*/
@NonNullByDefault
public class UInt32Field extends Field<Long> {
* 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> {
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
- * @author Tim Buckley
+ * @author Tim Buckley - Initial contribution
*/
@NonNullByDefault
public class UInt8Field extends Field<Integer> {
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
- * @author Wouter Born - Add Thing properties
+ * @author Wouter Born - Initial contribution
*/
@NonNullByDefault
public class Version {
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
- * @author Wouter Born - Add Thing properties
+ * @author Wouter Born - Initial contribution
*/
@NonNullByDefault
public class VersionField extends Field<Version> {
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;
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;
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;
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,
// (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());
}
}
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;
/**
* 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 {
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
+++ /dev/null
-/**
- * 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[] {};
- }
-}
+++ /dev/null
-/**
- * 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;
- }
-}
+++ /dev/null
-/**
- * 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[] {};
- }
-}
+++ /dev/null
-/**
- * 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();
- }
-}
+++ /dev/null
-/**
- * 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);
- }
- }
-}
+++ /dev/null
-/**
- * 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[] {};
- }
-}
+++ /dev/null
-/**
- * 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 };
- }
-}
+++ /dev/null
-/**
- * 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;
- }
-}
+++ /dev/null
-/**
- * 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 };
- }
-}
+++ /dev/null
-/**
- * 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 };
- }
-}
+++ /dev/null
-/**
- * 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 };
- }
-}
+++ /dev/null
-/**
- * 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 };
- }
-}
+++ /dev/null
-/**
- * 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 };
- }
-}
+++ /dev/null
-/**
- * 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 };
- }
-}
+++ /dev/null
-/**
- * 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 };
- }
-}
+++ /dev/null
-/**
- * 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 };
- }
-}
+++ /dev/null
-/**
- * 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 };
- }
-}
+++ /dev/null
-/**
- * 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 };
- }
-}
+++ /dev/null
-/**
- * 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 };
- }
-}
+++ /dev/null
-/**
- * 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 };
- }
-}
+++ /dev/null
-/**
- * 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 };
- }
-}
+++ /dev/null
-/**
- * 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 };
- }
-}
+++ /dev/null
-/**
- * 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 };
- }
-}
+++ /dev/null
-/**
- * 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 };
- }
-}
+++ /dev/null
-/**
- * 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 };
- }
-}
+++ /dev/null
-/**
- * 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;
- }
-}
+++ /dev/null
-/**
- * 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);
- }
-}
+++ /dev/null
-/**
- * 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);
-}
+++ /dev/null
-/**
- * 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;
- }
-}
+++ /dev/null
-/**
- * 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");
- }
-}
+++ /dev/null
-/**
- * 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 };
- }
-}
+++ /dev/null
-/**
- * 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[] {};
- }
-}
+++ /dev/null
-/**
- * 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[] {};
- }
-}
+++ /dev/null
-/**
- * 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[] {};
- }
-}
+++ /dev/null
-/**
- * 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 };
- }
-}
+++ /dev/null
-/**
- * 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 };
- }
-}
+++ /dev/null
-/**
- * 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 };
- }
-}
+++ /dev/null
-/**
- * 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[] {};
- }
-}
+++ /dev/null
-/**
- * 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[] {};
- }
-}
+++ /dev/null
-/**
- * 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()) + "]";
- }
-}
+++ /dev/null
-/**
- * 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[] {};
- }
-}
+++ /dev/null
-/**
- * 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[] {};
- }
-}
+++ /dev/null
-/**
- * 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[] {};
- }
-}
+++ /dev/null
-/**
- * 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[] {};
- }
-}
+++ /dev/null
-/**
- * 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[] {};
- }
-}
+++ /dev/null
-/**
- * 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[] {};
- }
-}
+++ /dev/null
-/**
- * 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[] {};
- }
-}
+++ /dev/null
-/**
- * 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[] {};
- }
-}
+++ /dev/null
-/**
- * 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[] {};
- }
-}
+++ /dev/null
-/**
- * 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[] {};
- }
-}
+++ /dev/null
-/**
- * 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[] {};
- }
-}
+++ /dev/null
-/**
- * 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[] {};
- }
-}
+++ /dev/null
-/**
- * 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[] {};
- }
-}
+++ /dev/null
-/**
- * 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[] {};
- }
-}
+++ /dev/null
-/**
- * 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[] {};
- }
-}
+++ /dev/null
-/**
- * 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[] {};
- }
-}
+++ /dev/null
-/**
- * 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[] {};
- }
-}
+++ /dev/null
-/**
- * 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[] {};
- }
-}
+++ /dev/null
-/**
- * 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[] {};
- }
-}
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;
/**
* 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 {
* 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 {
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 {
* 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
--- /dev/null
+/**
+ * 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())));
+ }
+}