[lifx] Fix all SAT findings (#10307)

* Remove dependency on commons-lang classes
* Use HexUtils
* Fix/add missing initial contribution author lines
* Add unit test for MACAddress
* Rename protocol package to dto

Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
Wouter Born 2021-03-10 09:52:39 +01:00 committed by GitHub
parent e9cd6de033
commit f3a517e4e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
96 changed files with 348 additions and 306 deletions

View File

@ -19,7 +19,7 @@ import org.openhab.core.thing.ThingUID;
/**
* The {@link LifxChannelFactory} creates dynamic LIFX channels.
*
* @author Wouter Born - Add i18n support
* @author Wouter Born - Initial contribution
*/
@NonNullByDefault
public interface LifxChannelFactory {

View File

@ -34,7 +34,7 @@ import org.osgi.service.component.annotations.Reference;
/**
* The {@link LifxChannelFactoryImpl} creates dynamic LIFX channels.
*
* @author Wouter Born - Add i18n support
* @author Wouter Born - Initial contribution
*/
@NonNullByDefault
@Component(service = LifxChannelFactory.class)

View File

@ -32,12 +32,12 @@ import java.util.function.Supplier;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.lifx.internal.dto.GetServiceRequest;
import org.openhab.binding.lifx.internal.dto.Packet;
import org.openhab.binding.lifx.internal.dto.StateServiceResponse;
import org.openhab.binding.lifx.internal.fields.MACAddress;
import org.openhab.binding.lifx.internal.handler.LifxLightHandler.CurrentLightState;
import org.openhab.binding.lifx.internal.listener.LifxResponsePacketListener;
import org.openhab.binding.lifx.internal.protocol.GetServiceRequest;
import org.openhab.binding.lifx.internal.protocol.Packet;
import org.openhab.binding.lifx.internal.protocol.StateServiceResponse;
import org.openhab.binding.lifx.internal.util.LifxNetworkUtil;
import org.openhab.binding.lifx.internal.util.LifxSelectorUtil;
import org.slf4j.Logger;
@ -46,7 +46,7 @@ import org.slf4j.LoggerFactory;
/**
* The {@link LifxLightCommunicationHandler} is responsible for the communications with a light.
*
* @author Wouter Born - Extracted class from LifxLightHandler
* @author Wouter Born - Initial contribution
*/
@NonNullByDefault
public class LifxLightCommunicationHandler {

View File

@ -33,7 +33,7 @@ public class LifxLightConfig {
public @Nullable MACAddress getMACAddress() {
String localDeviceId = deviceId;
return localDeviceId == null ? null : new MACAddress(localDeviceId, true);
return localDeviceId == null ? null : new MACAddress(localDeviceId);
}
public @Nullable InetSocketAddress getHost() {

View File

@ -17,12 +17,11 @@ import java.util.concurrent.ScheduledExecutorService;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.lifx.internal.handler.LifxLightHandler;
import org.openhab.binding.lifx.internal.handler.LifxLightHandler.CurrentLightState;
import org.openhab.binding.lifx.internal.protocol.Product;
/**
* The {@link LifxLightContext} shares the context of a light with {@link LifxLightHandler} helper objects.
*
* @author Wouter Born - Add optional host configuration parameter
* @author Wouter Born - Initial contribution
*/
@NonNullByDefault
public class LifxLightContext {
@ -31,10 +30,10 @@ public class LifxLightContext {
private final LifxLightConfig configuration;
private final CurrentLightState currentLightState;
private final LifxLightState pendingLightState;
private final Product product;
private final LifxProduct product;
private final ScheduledExecutorService scheduler;
public LifxLightContext(String logId, Product product, LifxLightConfig configuration,
public LifxLightContext(String logId, LifxProduct product, LifxLightConfig configuration,
CurrentLightState currentLightState, LifxLightState pendingLightState, ScheduledExecutorService scheduler) {
this.logId = logId;
this.configuration = configuration;
@ -52,7 +51,7 @@ public class LifxLightContext {
return configuration;
}
public Product getProduct() {
public LifxProduct getProduct() {
return product;
}

View File

@ -13,7 +13,7 @@
package org.openhab.binding.lifx.internal;
import static org.openhab.binding.lifx.internal.LifxBindingConstants.MIN_ZONE_INDEX;
import static org.openhab.binding.lifx.internal.protocol.Product.Feature.*;
import static org.openhab.binding.lifx.internal.LifxProduct.Feature.*;
import static org.openhab.binding.lifx.internal.util.LifxMessageUtil.infraredToPercentType;
import java.util.concurrent.ScheduledExecutorService;
@ -23,22 +23,21 @@ import java.util.concurrent.locks.ReentrantLock;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.lifx.internal.dto.GetColorZonesRequest;
import org.openhab.binding.lifx.internal.dto.GetLightInfraredRequest;
import org.openhab.binding.lifx.internal.dto.GetRequest;
import org.openhab.binding.lifx.internal.dto.GetTileEffectRequest;
import org.openhab.binding.lifx.internal.dto.GetWifiInfoRequest;
import org.openhab.binding.lifx.internal.dto.Packet;
import org.openhab.binding.lifx.internal.dto.StateLightInfraredResponse;
import org.openhab.binding.lifx.internal.dto.StateLightPowerResponse;
import org.openhab.binding.lifx.internal.dto.StateMultiZoneResponse;
import org.openhab.binding.lifx.internal.dto.StatePowerResponse;
import org.openhab.binding.lifx.internal.dto.StateResponse;
import org.openhab.binding.lifx.internal.dto.StateTileEffectResponse;
import org.openhab.binding.lifx.internal.dto.StateWifiInfoResponse;
import org.openhab.binding.lifx.internal.fields.HSBK;
import org.openhab.binding.lifx.internal.handler.LifxLightHandler.CurrentLightState;
import org.openhab.binding.lifx.internal.protocol.GetColorZonesRequest;
import org.openhab.binding.lifx.internal.protocol.GetLightInfraredRequest;
import org.openhab.binding.lifx.internal.protocol.GetRequest;
import org.openhab.binding.lifx.internal.protocol.GetTileEffectRequest;
import org.openhab.binding.lifx.internal.protocol.GetWifiInfoRequest;
import org.openhab.binding.lifx.internal.protocol.Packet;
import org.openhab.binding.lifx.internal.protocol.Product;
import org.openhab.binding.lifx.internal.protocol.StateLightInfraredResponse;
import org.openhab.binding.lifx.internal.protocol.StateLightPowerResponse;
import org.openhab.binding.lifx.internal.protocol.StateMultiZoneResponse;
import org.openhab.binding.lifx.internal.protocol.StatePowerResponse;
import org.openhab.binding.lifx.internal.protocol.StateResponse;
import org.openhab.binding.lifx.internal.protocol.StateTileEffectResponse;
import org.openhab.binding.lifx.internal.protocol.StateWifiInfoResponse;
import org.openhab.core.library.types.PercentType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -47,7 +46,7 @@ import org.slf4j.LoggerFactory;
* The {@link LifxLightCurrentStateUpdater} sends packets to a light in order to update the {@code currentLightState} to
* the actual light state.
*
* @author Wouter Born - Extracted class from LifxLightHandler
* @author Wouter Born - Initial contribution
*/
@NonNullByDefault
public class LifxLightCurrentStateUpdater {
@ -57,7 +56,7 @@ public class LifxLightCurrentStateUpdater {
private final Logger logger = LoggerFactory.getLogger(LifxLightCurrentStateUpdater.class);
private final String logId;
private final Product product;
private final LifxProduct product;
private final CurrentLightState currentLightState;
private final ScheduledExecutorService scheduler;
private final LifxLightCommunicationHandler communicationHandler;

View File

@ -26,18 +26,16 @@ import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
import org.apache.commons.lang.StringUtils;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.lifx.internal.dto.GetLabelRequest;
import org.openhab.binding.lifx.internal.dto.GetServiceRequest;
import org.openhab.binding.lifx.internal.dto.GetVersionRequest;
import org.openhab.binding.lifx.internal.dto.Packet;
import org.openhab.binding.lifx.internal.dto.StateLabelResponse;
import org.openhab.binding.lifx.internal.dto.StateServiceResponse;
import org.openhab.binding.lifx.internal.dto.StateVersionResponse;
import org.openhab.binding.lifx.internal.fields.MACAddress;
import org.openhab.binding.lifx.internal.protocol.GetLabelRequest;
import org.openhab.binding.lifx.internal.protocol.GetServiceRequest;
import org.openhab.binding.lifx.internal.protocol.GetVersionRequest;
import org.openhab.binding.lifx.internal.protocol.Packet;
import org.openhab.binding.lifx.internal.protocol.Product;
import org.openhab.binding.lifx.internal.protocol.StateLabelResponse;
import org.openhab.binding.lifx.internal.protocol.StateServiceResponse;
import org.openhab.binding.lifx.internal.protocol.StateVersionResponse;
import org.openhab.binding.lifx.internal.util.LifxSelectorUtil;
import org.openhab.core.config.discovery.AbstractDiscoveryService;
import org.openhab.core.config.discovery.DiscoveryResult;
@ -87,7 +85,7 @@ public class LifxLightDiscovery extends AbstractDiscoveryService {
private InetSocketAddress socketAddress;
private String logId;
private @Nullable String label;
private @Nullable Product product;
private @Nullable LifxProduct product;
private long productVersion;
private boolean supportedProduct = true;
private LifxSelectorContext selectorContext;
@ -300,7 +298,8 @@ public class LifxLightDiscovery extends AbstractDiscoveryService {
light.label = ((StateLabelResponse) packet).getLabel().trim();
} else if (packet instanceof StateVersionResponse) {
try {
light.product = Product.getProductFromProductID(((StateVersionResponse) packet).getProduct());
light.product = LifxProduct
.getProductFromProductID(((StateVersionResponse) packet).getProduct());
light.productVersion = ((StateVersionResponse) packet).getVersion();
} catch (IllegalArgumentException e) {
logger.debug("Discovered an unsupported light ({}): {}", light.macAddress.getAsLabel(),
@ -322,7 +321,7 @@ public class LifxLightDiscovery extends AbstractDiscoveryService {
}
private DiscoveryResult createDiscoveryResult(DiscoveredLight light) throws IllegalArgumentException {
Product product = light.product;
LifxProduct product = light.product;
if (product == null) {
throw new IllegalArgumentException("Product of discovered light is null");
}
@ -331,7 +330,7 @@ public class LifxLightDiscovery extends AbstractDiscoveryService {
ThingUID thingUID = new ThingUID(product.getThingTypeUID(), macAsLabel);
String label = light.label;
if (StringUtils.isBlank(label)) {
if (label == null || label.isBlank()) {
label = product.getName();
}

View File

@ -21,17 +21,17 @@ import java.util.concurrent.locks.ReentrantLock;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.lifx.internal.dto.GetEchoRequest;
import org.openhab.binding.lifx.internal.dto.GetServiceRequest;
import org.openhab.binding.lifx.internal.dto.Packet;
import org.openhab.binding.lifx.internal.handler.LifxLightHandler.CurrentLightState;
import org.openhab.binding.lifx.internal.protocol.GetEchoRequest;
import org.openhab.binding.lifx.internal.protocol.GetServiceRequest;
import org.openhab.binding.lifx.internal.protocol.Packet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The {@link LifxLightOnlineStateUpdater} sets the state of a light offline when it no longer responds to echo packets.
*
* @author Wouter Born - Extracted class from LifxLightHandler
* @author Wouter Born - Initial contribution
*/
@NonNullByDefault
public class LifxLightOnlineStateUpdater {

View File

@ -27,17 +27,16 @@ import java.util.concurrent.locks.ReentrantLock;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.lifx.internal.dto.GetHostFirmwareRequest;
import org.openhab.binding.lifx.internal.dto.GetVersionRequest;
import org.openhab.binding.lifx.internal.dto.GetWifiFirmwareRequest;
import org.openhab.binding.lifx.internal.dto.Packet;
import org.openhab.binding.lifx.internal.dto.StateHostFirmwareResponse;
import org.openhab.binding.lifx.internal.dto.StateVersionResponse;
import org.openhab.binding.lifx.internal.dto.StateWifiFirmwareResponse;
import org.openhab.binding.lifx.internal.fields.MACAddress;
import org.openhab.binding.lifx.internal.handler.LifxLightHandler.CurrentLightState;
import org.openhab.binding.lifx.internal.listener.LifxPropertiesUpdateListener;
import org.openhab.binding.lifx.internal.protocol.GetHostFirmwareRequest;
import org.openhab.binding.lifx.internal.protocol.GetVersionRequest;
import org.openhab.binding.lifx.internal.protocol.GetWifiFirmwareRequest;
import org.openhab.binding.lifx.internal.protocol.Packet;
import org.openhab.binding.lifx.internal.protocol.Product;
import org.openhab.binding.lifx.internal.protocol.StateHostFirmwareResponse;
import org.openhab.binding.lifx.internal.protocol.StateVersionResponse;
import org.openhab.binding.lifx.internal.protocol.StateWifiFirmwareResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -45,7 +44,7 @@ import org.slf4j.LoggerFactory;
* The {@link LifxLightPropertiesUpdater} updates the light properties when a light goes online. When packets get lost
* the requests are resent when the {@code UPDATE_INTERVAL} elapses.
*
* @author Wouter Born - Update light properties when online
* @author Wouter Born - Initial contribution
*/
@NonNullByDefault
public class LifxLightPropertiesUpdater {
@ -157,7 +156,7 @@ public class LifxLightPropertiesUpdater {
properties.put(LifxBindingConstants.PROPERTY_PRODUCT_VERSION, Long.toString(productVersion));
try {
Product product = Product.getProductFromProductID(productId);
LifxProduct product = LifxProduct.getProductFromProductID(productId);
properties.put(LifxBindingConstants.PROPERTY_PRODUCT_NAME, product.getName());
properties.put(LifxBindingConstants.PROPERTY_VENDOR_ID, Long.toString(product.getVendor().getID()));
properties.put(LifxBindingConstants.PROPERTY_VENDOR_NAME, product.getVendor().getName());

View File

@ -22,11 +22,11 @@ import java.util.concurrent.CopyOnWriteArrayList;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.lifx.internal.dto.Effect;
import org.openhab.binding.lifx.internal.dto.PowerState;
import org.openhab.binding.lifx.internal.dto.SignalStrength;
import org.openhab.binding.lifx.internal.fields.HSBK;
import org.openhab.binding.lifx.internal.listener.LifxLightStateListener;
import org.openhab.binding.lifx.internal.protocol.Effect;
import org.openhab.binding.lifx.internal.protocol.PowerState;
import org.openhab.binding.lifx.internal.protocol.SignalStrength;
import org.openhab.core.library.types.HSBType;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.library.types.PercentType;
@ -34,7 +34,7 @@ import org.openhab.core.library.types.PercentType;
/**
* The {@link LifxLightState} stores the properties that represent the state of a light.
*
* @author Wouter Born - Extracted class from LifxLightHandler, added listener logic
* @author Wouter Born - Initial contribution
*/
@NonNullByDefault
public class LifxLightState {

View File

@ -13,7 +13,7 @@
package org.openhab.binding.lifx.internal;
import static org.openhab.binding.lifx.internal.LifxBindingConstants.PACKET_INTERVAL;
import static org.openhab.binding.lifx.internal.protocol.Product.Feature.MULTIZONE;
import static org.openhab.binding.lifx.internal.LifxProduct.Feature.MULTIZONE;
import static org.openhab.binding.lifx.internal.util.LifxMessageUtil.*;
import java.time.Duration;
@ -29,25 +29,24 @@ import java.util.concurrent.locks.ReentrantLock;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.lifx.internal.dto.AcknowledgementResponse;
import org.openhab.binding.lifx.internal.dto.ApplicationRequest;
import org.openhab.binding.lifx.internal.dto.Effect;
import org.openhab.binding.lifx.internal.dto.GetColorZonesRequest;
import org.openhab.binding.lifx.internal.dto.GetLightInfraredRequest;
import org.openhab.binding.lifx.internal.dto.GetLightPowerRequest;
import org.openhab.binding.lifx.internal.dto.GetRequest;
import org.openhab.binding.lifx.internal.dto.Packet;
import org.openhab.binding.lifx.internal.dto.PowerState;
import org.openhab.binding.lifx.internal.dto.SetColorRequest;
import org.openhab.binding.lifx.internal.dto.SetColorZonesRequest;
import org.openhab.binding.lifx.internal.dto.SetLightInfraredRequest;
import org.openhab.binding.lifx.internal.dto.SetLightPowerRequest;
import org.openhab.binding.lifx.internal.dto.SetPowerRequest;
import org.openhab.binding.lifx.internal.dto.SetTileEffectRequest;
import org.openhab.binding.lifx.internal.dto.SignalStrength;
import org.openhab.binding.lifx.internal.fields.HSBK;
import org.openhab.binding.lifx.internal.listener.LifxLightStateListener;
import org.openhab.binding.lifx.internal.protocol.AcknowledgementResponse;
import org.openhab.binding.lifx.internal.protocol.ApplicationRequest;
import org.openhab.binding.lifx.internal.protocol.Effect;
import org.openhab.binding.lifx.internal.protocol.GetColorZonesRequest;
import org.openhab.binding.lifx.internal.protocol.GetLightInfraredRequest;
import org.openhab.binding.lifx.internal.protocol.GetLightPowerRequest;
import org.openhab.binding.lifx.internal.protocol.GetRequest;
import org.openhab.binding.lifx.internal.protocol.Packet;
import org.openhab.binding.lifx.internal.protocol.PowerState;
import org.openhab.binding.lifx.internal.protocol.Product;
import org.openhab.binding.lifx.internal.protocol.SetColorRequest;
import org.openhab.binding.lifx.internal.protocol.SetColorZonesRequest;
import org.openhab.binding.lifx.internal.protocol.SetLightInfraredRequest;
import org.openhab.binding.lifx.internal.protocol.SetLightPowerRequest;
import org.openhab.binding.lifx.internal.protocol.SetPowerRequest;
import org.openhab.binding.lifx.internal.protocol.SetTileEffectRequest;
import org.openhab.binding.lifx.internal.protocol.SignalStrength;
import org.openhab.core.library.types.PercentType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -57,7 +56,7 @@ import org.slf4j.LoggerFactory;
* light so the change the actual light state to that of the {@code pendingLightState}. When the light does not
* acknowledge a packet, it resends it (max 3 times).
*
* @author Wouter Born - Extracted class from LifxLightHandler, added logic for handling packet loss
* @author Wouter Born - Initial contribution
*/
@NonNullByDefault
public class LifxLightStateChanger implements LifxLightStateListener {
@ -75,7 +74,7 @@ public class LifxLightStateChanger implements LifxLightStateListener {
private final Logger logger = LoggerFactory.getLogger(LifxLightStateChanger.class);
private final String logId;
private final Product product;
private final LifxProduct product;
private final Duration fadeTime;
private final LifxLightState pendingLightState;
private final ScheduledExecutorService scheduler;

View File

@ -10,17 +10,16 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal;
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 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.binding.lifx.internal.LifxBindingConstants;
import org.openhab.core.thing.ThingTypeUID;
/**
@ -28,11 +27,11 @@ import org.openhab.core.thing.ThingTypeUID;
*
* @see https://lan.developer.lifx.com/docs/lifx-products
*
* @author Wouter Born - Support LIFX 2016 product line-up and infrared functionality
* @author Wouter Born - Initial contribution
* @author Wouter Born - Add temperature ranges and simplify feature definitions
*/
@NonNullByDefault
public enum Product {
public enum LifxProduct {
PRODUCT_1(1, "LIFX Original 1000", TR_2500_9000, COLOR),
PRODUCT_3(3, "LIFX Color 650", TR_2500_9000, COLOR),
@ -215,19 +214,19 @@ public enum Product {
private final TemperatureRange temperatureRange;
private final EnumSet<Feature> features = EnumSet.noneOf(Feature.class);
private Product(long id, String name, TemperatureRange temperatureRange) {
private LifxProduct(long id, String name, TemperatureRange temperatureRange) {
this(LIFX, id, name, temperatureRange);
}
private Product(long id, String name, TemperatureRange temperatureRange, Feature... features) {
private LifxProduct(long id, String name, TemperatureRange temperatureRange, Feature... features) {
this(LIFX, id, name, temperatureRange, features);
}
private Product(Vendor vendor, long id, String name, TemperatureRange temperatureRange) {
private LifxProduct(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) {
private LifxProduct(Vendor vendor, long id, String name, TemperatureRange temperatureRange, Feature... features) {
this.vendor = vendor;
this.id = id;
this.name = name;
@ -283,8 +282,8 @@ public enum Product {
* @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()) {
public static LifxProduct getLikelyProduct(ThingTypeUID uid) throws IllegalArgumentException {
for (LifxProduct product : LifxProduct.values()) {
if (product.getThingTypeUID().equals(uid)) {
return product;
}
@ -300,8 +299,8 @@ public enum Product {
* @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()) {
public static LifxProduct getProductFromProductID(long id) throws IllegalArgumentException {
for (LifxProduct product : LifxProduct.values()) {
if (product.id == id) {
return product;
}

View File

@ -25,7 +25,7 @@ import org.openhab.binding.lifx.internal.fields.MACAddress;
* The {@link LifxSelectorContext} stores the context that is used for broadcast and unicast communications with a
* light using a {@link Selector}.
*
* @author Wouter Born - Make selector logic reusable between discovery and handlers
* @author Wouter Born - Initial contribution
*/
@NonNullByDefault
public class LifxSelectorContext {

View File

@ -20,7 +20,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
/**
* Supplies sequence numbers for packets in the range [0, 255].
*
* @author Wouter Born - Make selector logic reusable between discovery and handlers
* @author Wouter Born - Initial contribution
*/
@NonNullByDefault
public class LifxSequenceNumberSupplier implements Supplier<Integer> {

View File

@ -10,12 +10,12 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import java.nio.ByteBuffer;
/**
* @author Tim Buckley - Initial Contribution
* @author Tim Buckley - Initial contribution
* @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
*/
public class AcknowledgementResponse extends Packet {

View File

@ -10,10 +10,10 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
/**
* @author Wouter Born - Add support for MultiZone light control
* @author Wouter Born - Initial contribution
*/
public enum ApplicationRequest {

View File

@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import java.nio.ByteBuffer;
@ -18,7 +18,7 @@ import org.openhab.binding.lifx.internal.fields.ByteField;
import org.openhab.binding.lifx.internal.fields.Field;
/**
* @author Tim Buckley - Initial Contribution
* @author Tim Buckley - Initial contribution
* @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
*/
public class EchoRequestResponse extends Packet {

View File

@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
@ -20,7 +20,7 @@ import org.openhab.binding.lifx.internal.fields.HSBK;
/**
* This class represents LIFX Tile effect
*
* @author Pawel Pieczul - initial contribution
* @author Pawel Pieczul - Initial contribution
*/
@NonNullByDefault
public class Effect {

View File

@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
@ -27,7 +27,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
*
* @param <T> the packet subtype this handler constructs
*
* @author Tim Buckley - Initial Contribution
* @author Tim Buckley - Initial contribution
* @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
*/
@NonNullByDefault

View File

@ -10,12 +10,12 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import java.nio.ByteBuffer;
/**
* @author Tim Buckley - Initial Contribution
* @author Tim Buckley - Initial contribution
* @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
*/
public class GenericPacket extends Packet {

View File

@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import static org.openhab.binding.lifx.internal.LifxBindingConstants.*;
@ -20,7 +20,7 @@ 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
* @author Wouter Born - Initial contribution
*/
public class GetColorZonesRequest extends Packet {

View File

@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import java.nio.ByteBuffer;
@ -18,7 +18,7 @@ import org.openhab.binding.lifx.internal.fields.ByteField;
import org.openhab.binding.lifx.internal.fields.Field;
/**
* @author Tim Buckley - Initial Contribution
* @author Tim Buckley - Initial contribution
* @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
*/
public class GetEchoRequest extends Packet {

View File

@ -10,12 +10,12 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import java.nio.ByteBuffer;
/**
* @author Tim Buckley - Initial Contribution
* @author Tim Buckley - Initial contribution
* @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
*/
public class GetGroupRequest extends Packet {

View File

@ -10,12 +10,12 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import java.nio.ByteBuffer;
/**
* @author Tim Buckley - Initial Contribution
* @author Tim Buckley - Initial contribution
* @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
*/
public class GetHostFirmwareRequest extends Packet {

View File

@ -10,12 +10,12 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import java.nio.ByteBuffer;
/**
* @author Tim Buckley - Initial Contribution
* @author Tim Buckley - Initial contribution
* @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
*/
public class GetHostInfoRequest extends Packet {

View File

@ -10,12 +10,12 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import java.nio.ByteBuffer;
/**
* @author Tim Buckley - Initial Contribution
* @author Tim Buckley - Initial contribution
* @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
*/
public class GetInfoRequest extends Packet {

View File

@ -10,12 +10,12 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import java.nio.ByteBuffer;
/**
* @author Tim Buckley - Initial Contribution
* @author Tim Buckley - Initial contribution
* @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
*/
public class GetLabelRequest extends Packet {

View File

@ -10,12 +10,12 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import java.nio.ByteBuffer;
/**
* @author Wouter Born - Support LIFX 2016 product line-up and infrared functionality
* @author Wouter Born - Initial contribution
*/
public class GetLightInfraredRequest extends Packet {

View File

@ -10,12 +10,12 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import java.nio.ByteBuffer;
/**
* @author Tim Buckley - Initial Contribution
* @author Tim Buckley - Initial contribution
* @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
*/
public class GetLightPowerRequest extends Packet {

View File

@ -10,12 +10,12 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import java.nio.ByteBuffer;
/**
* @author Tim Buckley - Initial Contribution
* @author Tim Buckley - Initial contribution
* @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
*/
public class GetLocationRequest extends Packet {

View File

@ -10,12 +10,12 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import java.nio.ByteBuffer;
/**
* @author Tim Buckley - Initial Contribution
* @author Tim Buckley - Initial contribution
* @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
*/
public class GetPowerRequest extends Packet {

View File

@ -10,12 +10,12 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import java.nio.ByteBuffer;
/**
* @author Tim Buckley - Initial Contribution
* @author Tim Buckley - Initial contribution
* @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
*/
public class GetRequest extends Packet {

View File

@ -10,12 +10,12 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import java.nio.ByteBuffer;
/**
* @author Tim Buckley - Initial Contribution
* @author Tim Buckley - Initial contribution
* @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
*/
public class GetServiceRequest extends Packet {

View File

@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import java.nio.ByteBuffer;
@ -18,7 +18,7 @@ import org.openhab.binding.lifx.internal.fields.Field;
import org.openhab.binding.lifx.internal.fields.UInt64Field;
/**
* @author Tim Buckley - Initial Contribution
* @author Tim Buckley - Initial contribution
* @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
*/
public class GetTagLabelsRequest extends Packet {

View File

@ -10,12 +10,12 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import java.nio.ByteBuffer;
/**
* @author Tim Buckley - Initial Contribution
* @author Tim Buckley - Initial contribution
* @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
*/
public class GetTagsRequest extends Packet {

View File

@ -10,14 +10,14 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import java.nio.ByteBuffer;
/**
* Implementation of GetTileEffect packet
*
* @author Pawel Pieczul - Add support for Tile Effects
*
* @author Pawel Pieczul - Initial contribution
*/
public class GetTileEffectRequest extends Packet {

View File

@ -10,12 +10,12 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import java.nio.ByteBuffer;
/**
* @author Tim Buckley - Initial Contribution
* @author Tim Buckley - Initial contribution
* @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
*/
public class GetVersionRequest extends Packet {

View File

@ -10,12 +10,12 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import java.nio.ByteBuffer;
/**
* @author Tim Buckley - Initial Contribution
* @author Tim Buckley - Initial contribution
* @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
*/
public class GetWifiFirmwareRequest extends Packet {

View File

@ -10,12 +10,12 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import java.nio.ByteBuffer;
/**
* @author Tim Buckley - Initial Contribution
* @author Tim Buckley - Initial contribution
* @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
*/
public class GetWifiInfoRequest extends Packet {

View File

@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import java.nio.ByteBuffer;
@ -36,7 +36,7 @@ import org.openhab.binding.lifx.internal.fields.UInt8Field;
* Field definitions should remain accessible to outside classes in the event
* they need to worked with directly elsewhere.
*
* @author Tim Buckley - Initial Contribution
* @author Tim Buckley - Initial contribution
* @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
*/
public abstract class Packet {

View File

@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import java.util.HashMap;
import java.util.Map;
@ -24,7 +24,7 @@ import org.eclipse.jdt.annotation.Nullable;
* e. Packet handlers (used to construct actual packet
* instances) may be retrieved via their packet type.
*
* @author Tim Buckley - Initial Contribution
* @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
*/

View File

@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import java.nio.ByteBuffer;
@ -22,7 +22,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
*
* @param <T> the generic packet type
*
* @author Tim Buckley - Initial Contribution
* @author Tim Buckley - Initial contribution
* @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
*/
@NonNullByDefault

View File

@ -10,14 +10,14 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
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 Tim Buckley - Initial contribution
* @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
* @author Wouter Born - Added OnOffType conversion methods
*/

View File

@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import java.nio.ByteBuffer;
@ -21,7 +21,7 @@ import org.openhab.binding.lifx.internal.fields.HSBKField;
import org.openhab.binding.lifx.internal.fields.UInt32Field;
/**
* @author Tim Buckley - Initial Contribution
* @author Tim Buckley - Initial contribution
* @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
*/
public class SetColorRequest extends Packet {

View File

@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import static org.openhab.binding.lifx.internal.LifxBindingConstants.*;
@ -23,7 +23,7 @@ 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
* @author Wouter Born - Initial contribution
*/
public class SetColorZonesRequest extends Packet {

View File

@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import java.nio.ByteBuffer;
@ -19,7 +19,7 @@ import org.openhab.binding.lifx.internal.fields.UInt16Field;
import org.openhab.binding.lifx.internal.fields.UInt32Field;
/**
* @author Tim Buckley - Initial Contribution
* @author Tim Buckley - Initial contribution
* @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
*/
public class SetDimAbsoluteRequest extends Packet {

View File

@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import java.nio.ByteBuffer;
@ -18,7 +18,7 @@ import org.openhab.binding.lifx.internal.fields.Field;
import org.openhab.binding.lifx.internal.fields.StringField;
/**
* @author Tim Buckley - Initial Contribution
* @author Tim Buckley - Initial contribution
* @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
*/
public class SetLabelRequest extends Packet {

View File

@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import java.nio.ByteBuffer;
@ -18,7 +18,7 @@ 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
* @author Wouter Born - Initial contribution
*/
public class SetLightInfraredRequest extends Packet {

View File

@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import java.nio.ByteBuffer;
@ -19,7 +19,7 @@ import org.openhab.binding.lifx.internal.fields.UInt16Field;
import org.openhab.binding.lifx.internal.fields.UInt32Field;
/**
* @author Tim Buckley - Initial Contribution
* @author Tim Buckley - Initial contribution
* @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
*/
public class SetLightPowerRequest extends Packet {

View File

@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import java.nio.ByteBuffer;
@ -18,7 +18,7 @@ import org.openhab.binding.lifx.internal.fields.Field;
import org.openhab.binding.lifx.internal.fields.UInt16Field;
/**
* @author Tim Buckley - Initial Contribution
* @author Tim Buckley - Initial contribution
* @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
*/
public class SetPowerRequest extends Packet {

View File

@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import java.nio.ByteBuffer;
@ -18,7 +18,7 @@ import org.openhab.binding.lifx.internal.fields.Field;
import org.openhab.binding.lifx.internal.fields.UInt64Field;
/**
* @author Tim Buckley - Initial Contribution
* @author Tim Buckley - Initial contribution
* @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
*/
public class SetTagsRequest extends Packet {

View File

@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import java.nio.ByteBuffer;

View File

@ -10,12 +10,12 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
/**
* The signal strength of a light.
*
* @author Wouter Born - Add signal strength channel
* @author Wouter Born - Initial contribution
*/
public class SignalStrength {

View File

@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import java.nio.ByteBuffer;
@ -20,7 +20,7 @@ import org.openhab.binding.lifx.internal.fields.StringField;
import org.openhab.binding.lifx.internal.fields.UInt64Field;
/**
* @author Tim Buckley - Initial Contribution
* @author Tim Buckley - Initial contribution
* @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
*/
public class StateGroupResponse extends Packet {

View File

@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import java.nio.ByteBuffer;
@ -20,7 +20,7 @@ import org.openhab.binding.lifx.internal.fields.Version;
import org.openhab.binding.lifx.internal.fields.VersionField;
/**
* @author Tim Buckley - Initial Contribution
* @author Tim Buckley - Initial contribution
* @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
*/
public class StateHostFirmwareResponse extends Packet {

View File

@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import java.nio.ByteBuffer;
@ -20,7 +20,7 @@ import org.openhab.binding.lifx.internal.fields.FloatField;
import org.openhab.binding.lifx.internal.fields.UInt32Field;
/**
* @author Tim Buckley - Initial Contribution
* @author Tim Buckley - Initial contribution
* @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
*/
public class StateHostInfoResponse extends Packet {

View File

@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import java.nio.ByteBuffer;
@ -18,7 +18,7 @@ import org.openhab.binding.lifx.internal.fields.Field;
import org.openhab.binding.lifx.internal.fields.UInt64Field;
/**
* @author Tim Buckley - Initial Contribution
* @author Tim Buckley - Initial contribution
* @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
*/
public class StateInfoResponse extends Packet {

View File

@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import java.nio.ByteBuffer;
@ -18,7 +18,7 @@ import org.openhab.binding.lifx.internal.fields.Field;
import org.openhab.binding.lifx.internal.fields.StringField;
/**
* @author Tim Buckley - Initial Contribution
* @author Tim Buckley - Initial contribution
* @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
*/
public class StateLabelResponse extends Packet {

View File

@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import java.nio.ByteBuffer;
@ -18,7 +18,7 @@ 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
* @author Wouter Born - Initial contribution
*/
public class StateLightInfraredResponse extends Packet {

View File

@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import java.nio.ByteBuffer;
@ -18,7 +18,7 @@ import org.openhab.binding.lifx.internal.fields.Field;
import org.openhab.binding.lifx.internal.fields.UInt16Field;
/**
* @author Tim Buckley - Initial Contribution
* @author Tim Buckley - Initial contribution
* @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
*/
public class StateLightPowerResponse extends Packet {

View File

@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import java.nio.ByteBuffer;
@ -20,7 +20,7 @@ import org.openhab.binding.lifx.internal.fields.StringField;
import org.openhab.binding.lifx.internal.fields.UInt64Field;
/**
* @author Tim Buckley - Initial Contribution
* @author Tim Buckley - Initial contribution
* @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
*/
public class StateLocationResponse extends Packet {

View File

@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import java.nio.ByteBuffer;
@ -20,7 +20,7 @@ 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
* @author Wouter Born - Initial contribution
*/
public class StateMultiZoneResponse extends Packet {

View File

@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import java.nio.ByteBuffer;
@ -18,7 +18,7 @@ import org.openhab.binding.lifx.internal.fields.Field;
import org.openhab.binding.lifx.internal.fields.UInt16Field;
/**
* @author Tim Buckley - Initial Contribution
* @author Tim Buckley - Initial contribution
* @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
*/
public class StatePowerResponse extends Packet {

View File

@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import java.nio.ByteBuffer;
@ -22,7 +22,7 @@ import org.openhab.binding.lifx.internal.fields.UInt16Field;
import org.openhab.binding.lifx.internal.fields.UInt64Field;
/**
* @author Tim Buckley - Initial Contribution
* @author Tim Buckley - Initial contribution
* @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
*/
public class StateResponse extends Packet {

View File

@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import java.nio.ByteBuffer;
@ -20,7 +20,7 @@ import org.openhab.binding.lifx.internal.fields.UInt32Field;
import org.openhab.binding.lifx.internal.fields.UInt8Field;
/**
* @author Tim Buckley - Initial Contribution
* @author Tim Buckley - Initial contribution
* @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
*/
public class StateServiceResponse extends Packet {

View File

@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import java.nio.ByteBuffer;
@ -26,7 +26,7 @@ import org.slf4j.LoggerFactory;
/**
* Implementation of StateTileEffect packet
*
* @author Pawel Pieczul - Initial Contribution
* @author Pawel Pieczul - Initial contribution
*/
public class StateTileEffectResponse extends Packet {

View File

@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import java.nio.ByteBuffer;
@ -18,7 +18,7 @@ import org.openhab.binding.lifx.internal.fields.Field;
import org.openhab.binding.lifx.internal.fields.UInt32Field;
/**
* @author Tim Buckley - Initial Contribution
* @author Tim Buckley - Initial contribution
* @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
*/
public class StateVersionResponse extends Packet {

View File

@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import java.nio.ByteBuffer;
@ -20,7 +20,7 @@ import org.openhab.binding.lifx.internal.fields.Version;
import org.openhab.binding.lifx.internal.fields.VersionField;
/**
* @author Tim Buckley - Initial Contribution
* @author Tim Buckley - Initial contribution
* @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
*/
public class StateWifiFirmwareResponse extends Packet {

View File

@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import java.nio.ByteBuffer;
@ -20,7 +20,7 @@ import org.openhab.binding.lifx.internal.fields.UInt16Field;
import org.openhab.binding.lifx.internal.fields.UInt32Field;
/**
* @author Tim Buckley - Initial Contribution
* @author Tim Buckley - Initial contribution
* @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
*/
public class StateWifiInfoResponse extends Packet {

View File

@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import java.nio.ByteBuffer;
@ -20,7 +20,7 @@ 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
* @author Wouter Born - Initial contribution
*/
public class StateZoneResponse extends Packet {

View File

@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import java.nio.ByteBuffer;
@ -19,7 +19,7 @@ import org.openhab.binding.lifx.internal.fields.StringField;
import org.openhab.binding.lifx.internal.fields.UInt64Field;
/**
* @author Tim Buckley - Initial Contribution
* @author Tim Buckley - Initial contribution
* @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
*/
public class TagLabelsResponse extends Packet {

View File

@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.protocol;
package org.openhab.binding.lifx.internal.dto;
import java.nio.ByteBuffer;
@ -18,7 +18,7 @@ import org.openhab.binding.lifx.internal.fields.Field;
import org.openhab.binding.lifx.internal.fields.UInt64Field;
/**
* @author Tim Buckley - Initial Contribution
* @author Tim Buckley - Initial contribution
* @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
*/
public class TagsResponse extends Packet {

View File

@ -17,7 +17,7 @@ import java.nio.ByteBuffer;
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
* @author Tim Buckley
* @author Tim Buckley - Initial contribution
*/
@NonNullByDefault
public class ByteField extends Field<ByteBuffer> {

View File

@ -22,7 +22,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
*
* @param <T> the field datatype
*
* @author Tim Buckley
* @author Tim Buckley - Initial contribution
*/
@NonNullByDefault
public abstract class Field<T> {

View File

@ -17,7 +17,7 @@ import java.nio.ByteBuffer;
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
* @author Tim Buckley
* @author Tim Buckley - Initial contribution
*/
@NonNullByDefault
public class FloatField extends Field<Float> {

View File

@ -21,7 +21,7 @@ import org.openhab.core.library.types.HSBType;
import org.openhab.core.library.types.PercentType;
/**
* @author Wouter Born - Add support for MultiZone light control
* @author Wouter Born - Initial contribution
*/
@NonNullByDefault
public class HSBK {

View File

@ -17,7 +17,7 @@ import java.nio.ByteBuffer;
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
* @author Wouter Born - Add support for MultiZone light control
* @author Wouter Born - Initial contribution
*/
@NonNullByDefault
public class HSBKField extends Field<HSBK> {

View File

@ -19,7 +19,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
/**
* Reads a wrapped field in reversed byte order.
*
* @author Tim Buckley
* @author Tim Buckley - Initial contribution
*/
@NonNullByDefault
public class LittleField<T> extends Field<T> {

View File

@ -12,30 +12,23 @@
*/
package org.openhab.binding.lifx.internal.fields;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import org.apache.commons.lang.StringUtils;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.openhab.core.util.HexUtils;
/**
* @author Tim Buckley
* @author Karel Goderis
* @author Tim Buckley - Initial contribution
* @author Karel Goderis - Initial contribution
*/
@NonNullByDefault
public class MACAddress {
public static final MACAddress BROADCAST_ADDRESS = new MACAddress("000000000000", true);
private final Logger logger = LoggerFactory.getLogger(MACAddress.class);
public static final MACAddress BROADCAST_ADDRESS = new MACAddress("000000000000");
private ByteBuffer bytes;
private String hex = "";
@ -54,28 +47,10 @@ public class MACAddress {
createHex();
}
public MACAddress(String string, boolean isHex) {
if (!isHex) {
this.bytes = ByteBuffer.wrap(string.getBytes());
createHex();
} else {
this.bytes = ByteBuffer.wrap(parseHexBinary(string));
try {
formatHex(string, 2, ":");
} catch (IOException e) {
logger.error("An exception occurred while formatting an HEX string : '{}'", e.getMessage());
}
}
}
private byte[] parseHexBinary(String s) {
int len = s.length();
byte[] data = new byte[len / 2];
for (int i = 0; i < len; i += 2) {
data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s.charAt(i + 1), 16));
}
return data;
public MACAddress(String string) {
byte[] byteArray = HexUtils.hexToBytes(string);
this.bytes = ByteBuffer.wrap(byteArray);
this.hex = HexUtils.bytesToHex(byteArray, ":");
}
public MACAddress() {
@ -90,7 +65,7 @@ public class MACAddress {
byteStrings.add(String.format("%02X", bytes.get()));
}
hex = StringUtils.join(byteStrings, ':');
hex = String.join(":", byteStrings);
bytes.rewind();
}
@ -108,21 +83,6 @@ public class MACAddress {
return hex.toString();
}
private void formatHex(String original, int length, String separator) throws IOException {
ByteArrayInputStream bis = new ByteArrayInputStream(original.getBytes());
byte[] buffer = new byte[length];
String result = "";
while (bis.read(buffer) > 0) {
for (byte b : buffer) {
result += (char) b;
}
Arrays.fill(buffer, (byte) 0);
result += separator;
}
hex = StringUtils.left(result, result.length() - 1);
}
@Override
public int hashCode() {
int hash = 7;

View File

@ -17,8 +17,8 @@ import java.nio.ByteBuffer;
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
* @author Tim Buckley
* @author Karel Goderis
* @author Tim Buckley - Initial contribution
* @author Karel Goderis - Initial contribution
*/
@NonNullByDefault
public class MACAddressField extends Field<MACAddress> {

View File

@ -19,7 +19,7 @@ import java.nio.charset.StandardCharsets;
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
* @author Tim Buckley
* @author Tim Buckley - Initial contribution
*/
@NonNullByDefault
public class StringField extends Field<String> {

View File

@ -17,7 +17,7 @@ import java.nio.ByteBuffer;
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
* @author Tim Buckley
* @author Tim Buckley - Initial contribution
*/
@NonNullByDefault
public class UInt16Field extends Field<Integer> {

View File

@ -17,7 +17,7 @@ import java.nio.ByteBuffer;
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
* @author Tim Buckley
* @author Tim Buckley - Initial contribution
*/
@NonNullByDefault
public class UInt32Field extends Field<Long> {

View File

@ -21,7 +21,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
* unexpected values will likely be shown if exposed to users. Most bit-level
* operations should still work (addition, multiplication, shifting, etc).
*
* @author Tim Buckley
* @author Tim Buckley - Initial contribution
*/
@NonNullByDefault
public class UInt64Field extends Field<Long> {

View File

@ -17,7 +17,7 @@ import java.nio.ByteBuffer;
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
* @author Tim Buckley
* @author Tim Buckley - Initial contribution
*/
@NonNullByDefault
public class UInt8Field extends Field<Integer> {

View File

@ -15,7 +15,7 @@ package org.openhab.binding.lifx.internal.fields;
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
* @author Wouter Born - Add Thing properties
* @author Wouter Born - Initial contribution
*/
@NonNullByDefault
public class Version {

View File

@ -17,7 +17,7 @@ import java.nio.ByteBuffer;
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
* @author Wouter Born - Add Thing properties
* @author Wouter Born - Initial contribution
*/
@NonNullByDefault
public class VersionField extends Field<Version> {

View File

@ -13,7 +13,7 @@
package org.openhab.binding.lifx.internal.handler;
import static org.openhab.binding.lifx.internal.LifxBindingConstants.*;
import static org.openhab.binding.lifx.internal.protocol.Product.Feature.*;
import static org.openhab.binding.lifx.internal.LifxProduct.Feature.*;
import static org.openhab.binding.lifx.internal.util.LifxMessageUtil.*;
import java.net.InetSocketAddress;
@ -38,18 +38,18 @@ import org.openhab.binding.lifx.internal.LifxLightOnlineStateUpdater;
import org.openhab.binding.lifx.internal.LifxLightPropertiesUpdater;
import org.openhab.binding.lifx.internal.LifxLightState;
import org.openhab.binding.lifx.internal.LifxLightStateChanger;
import org.openhab.binding.lifx.internal.LifxProduct;
import org.openhab.binding.lifx.internal.dto.Effect;
import org.openhab.binding.lifx.internal.dto.GetLightInfraredRequest;
import org.openhab.binding.lifx.internal.dto.GetLightPowerRequest;
import org.openhab.binding.lifx.internal.dto.GetRequest;
import org.openhab.binding.lifx.internal.dto.GetTileEffectRequest;
import org.openhab.binding.lifx.internal.dto.GetWifiInfoRequest;
import org.openhab.binding.lifx.internal.dto.Packet;
import org.openhab.binding.lifx.internal.dto.PowerState;
import org.openhab.binding.lifx.internal.dto.SignalStrength;
import org.openhab.binding.lifx.internal.fields.HSBK;
import org.openhab.binding.lifx.internal.fields.MACAddress;
import org.openhab.binding.lifx.internal.protocol.Effect;
import org.openhab.binding.lifx.internal.protocol.GetLightInfraredRequest;
import org.openhab.binding.lifx.internal.protocol.GetLightPowerRequest;
import org.openhab.binding.lifx.internal.protocol.GetRequest;
import org.openhab.binding.lifx.internal.protocol.GetTileEffectRequest;
import org.openhab.binding.lifx.internal.protocol.GetWifiInfoRequest;
import org.openhab.binding.lifx.internal.protocol.Packet;
import org.openhab.binding.lifx.internal.protocol.PowerState;
import org.openhab.binding.lifx.internal.protocol.Product;
import org.openhab.binding.lifx.internal.protocol.SignalStrength;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.HSBType;
@ -90,7 +90,7 @@ public class LifxLightHandler extends BaseThingHandler {
private static final Duration MAX_STATE_CHANGE_DURATION = Duration.ofSeconds(4);
private final LifxChannelFactory channelFactory;
private @NonNullByDefault({}) Product product;
private @NonNullByDefault({}) LifxProduct product;
private @Nullable PercentType powerOnBrightness;
private @Nullable HSBType powerOnColor;
@ -405,10 +405,10 @@ public class LifxLightHandler extends BaseThingHandler {
return speed == null ? null : new Double(speed.toString());
}
private Product getProduct() {
private LifxProduct getProduct() {
Object propertyValue = getThing().getProperties().get(LifxBindingConstants.PROPERTY_PRODUCT_ID);
if (propertyValue == null) {
return Product.getLikelyProduct(getThing().getThingTypeUID());
return LifxProduct.getLikelyProduct(getThing().getThingTypeUID());
}
try {
// Without first conversion to double, on a very first thing creation from discovery inbox,
@ -416,9 +416,9 @@ public class LifxLightHandler extends BaseThingHandler {
// (e.g. 50.0 instead of 50)
Double d = Double.parseDouble((String) propertyValue);
long productID = d.longValue();
return Product.getProductFromProductID(productID);
return LifxProduct.getProductFromProductID(productID);
} catch (IllegalArgumentException e) {
return Product.getLikelyProduct(getThing().getThingTypeUID());
return LifxProduct.getLikelyProduct(getThing().getThingTypeUID());
}
}

View File

@ -15,10 +15,10 @@ package org.openhab.binding.lifx.internal.listener;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.lifx.internal.LifxLightState;
import org.openhab.binding.lifx.internal.dto.Effect;
import org.openhab.binding.lifx.internal.dto.PowerState;
import org.openhab.binding.lifx.internal.dto.SignalStrength;
import org.openhab.binding.lifx.internal.fields.HSBK;
import org.openhab.binding.lifx.internal.protocol.Effect;
import org.openhab.binding.lifx.internal.protocol.PowerState;
import org.openhab.binding.lifx.internal.protocol.SignalStrength;
import org.openhab.core.library.types.PercentType;
/**

View File

@ -21,7 +21,7 @@ import org.openhab.binding.lifx.internal.LifxLightPropertiesUpdater;
* The {@link LifxPropertiesUpdateListener} is notified when the {@link LifxLightPropertiesUpdater} has
* updated light properties.
*
* @author Wouter Born - Update light properties when online
* @author Wouter Born - Initial contribution
*/
@NonNullByDefault
public interface LifxPropertiesUpdateListener {

View File

@ -14,7 +14,7 @@ package org.openhab.binding.lifx.internal.listener;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.lifx.internal.LifxLightCommunicationHandler;
import org.openhab.binding.lifx.internal.protocol.Packet;
import org.openhab.binding.lifx.internal.dto.Packet;
/**
* The {@link LifxResponsePacketListener} is notified when the {@link LifxLightCommunicationHandler} receives a response

View File

@ -17,8 +17,8 @@ import java.math.RoundingMode;
import java.util.UUID;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.lifx.internal.LifxProduct.TemperatureRange;
import org.openhab.binding.lifx.internal.fields.HSBK;
import org.openhab.binding.lifx.internal.protocol.Product.TemperatureRange;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.IncreaseDecreaseType;
import org.openhab.core.library.types.PercentType;
@ -26,7 +26,7 @@ import org.openhab.core.library.types.PercentType;
/**
* Utility class for sharing message utility methods between objects.
*
* @author Wouter Born - Extracted methods from LifxLightHandler
* @author Wouter Born - Initial contribution
*/
@NonNullByDefault
public final class LifxMessageUtil {

View File

@ -34,7 +34,7 @@ import org.slf4j.LoggerFactory;
* The {@link LifxNetworkUtil} provides network interface information to the LIFX binding objects. The information is
* updated when it is older than {@link #UPDATE_INTERVAL_MILLIS}.
*
* @author Wouter Born - Periodically update available interface information
* @author Wouter Born - Initial contribution
*/
@NonNullByDefault
public final class LifxNetworkUtil {

View File

@ -32,17 +32,17 @@ import java.util.function.BiConsumer;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.lifx.internal.LifxSelectorContext;
import org.openhab.binding.lifx.internal.dto.Packet;
import org.openhab.binding.lifx.internal.dto.PacketFactory;
import org.openhab.binding.lifx.internal.dto.PacketHandler;
import org.openhab.binding.lifx.internal.fields.MACAddress;
import org.openhab.binding.lifx.internal.protocol.Packet;
import org.openhab.binding.lifx.internal.protocol.PacketFactory;
import org.openhab.binding.lifx.internal.protocol.PacketHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Utility class for sharing {@link Selector} logic between objects.
*
* @author Wouter Born - Make selector logic reusable between discovery and handlers
* @author Wouter Born - Initial contribution
*/
@NonNullByDefault
public class LifxSelectorUtil {

View File

@ -31,7 +31,7 @@ import org.slf4j.LoggerFactory;
* sent to LIFX lights. The LIFX LAN Protocol Specification states that lights can process up to 20 messages per second,
* not more.
*
* @author Karel Goderis - Initial Contribution
* @author Karel Goderis - Initial contribution
* @author Wouter Born - Deadlock fix
*/
@NonNullByDefault

View File

@ -0,0 +1,88 @@
/**
* Copyright (c) 2010-2021 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.lifx.internal.fields;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.openhab.binding.lifx.internal.fields.MACAddress.BROADCAST_ADDRESS;
import static org.openhab.core.util.HexUtils.bytesToHex;
import java.nio.ByteBuffer;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.junit.jupiter.api.Test;
import org.openhab.core.util.HexUtils;
/**
* Tests {@link MACAddress}.
*
* @author Wouter Born - Initial contribution
*/
@NonNullByDefault
public class MACAddressTest {
@Test
public void broadcastAddress() {
assertThat(BROADCAST_ADDRESS.getAsLabel(), is("000000000000"));
assertThat(BROADCAST_ADDRESS.getHex(), is("00:00:00:00:00:00"));
assertThat(bytesToHex(BROADCAST_ADDRESS.getBytes().array()), is("000000000000"));
}
@Test
public void defaultConstructor() {
MACAddress macAddress = new MACAddress();
assertThat(macAddress.getAsLabel(), is("000000000000"));
assertThat(macAddress.getHex(), is("00:00:00:00:00:00"));
}
@Test
public void constructFromByteBuffer() {
MACAddress macAddress = new MACAddress(ByteBuffer.wrap(HexUtils.hexToBytes("D073D5123456")));
assertThat(macAddress.getAsLabel(), is("D073D5123456"));
assertThat(macAddress.getHex(), is("D0:73:D5:12:34:56"));
assertThat(bytesToHex(macAddress.getBytes().array()), is("D073D5123456"));
}
@Test
public void constructFromString() {
MACAddress macAddress = new MACAddress("D073D5ABCDEF");
assertThat(macAddress.getAsLabel(), is("D073D5ABCDEF"));
assertThat(macAddress.getHex(), is("D0:73:D5:AB:CD:EF"));
assertThat(bytesToHex(macAddress.getBytes().array()), is("D073D5ABCDEF"));
}
@Test
public void broadcastAddressComparison() {
assertThat(BROADCAST_ADDRESS, is(BROADCAST_ADDRESS));
assertThat(BROADCAST_ADDRESS.hashCode(), is(BROADCAST_ADDRESS.hashCode()));
assertThat(BROADCAST_ADDRESS, is(new MACAddress()));
assertThat(BROADCAST_ADDRESS.hashCode(), is(new MACAddress().hashCode()));
assertThat(BROADCAST_ADDRESS, is(not(new MACAddress("D073D5ABCDEF"))));
assertThat(BROADCAST_ADDRESS, is(not(new MACAddress("D073D5ABCDEF").hashCode())));
}
@Test
public void macAddressComparison() {
assertThat(new MACAddress("D073D5ABCDEF"), is(new MACAddress("D073D5ABCDEF")));
assertThat(new MACAddress("D073D5ABCDEF").hashCode(), is(new MACAddress("D073D5ABCDEF").hashCode()));
assertThat(new MACAddress("D073D5ABCDEF"), is(not(BROADCAST_ADDRESS)));
assertThat(new MACAddress("D073D5ABCDEF").hashCode(), is(not(BROADCAST_ADDRESS.hashCode())));
assertThat(new MACAddress("D073D5ABCDEF"), is(not(new MACAddress("D073D5123456"))));
assertThat(new MACAddress("D073D5ABCDEF").hashCode(), is(not(new MACAddress("D073D5123456").hashCode())));
}
}