Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.

Commit

Permalink
[LIFX] Add optional host configuration parameter, support new product…
Browse files Browse the repository at this point in the history
…s and improvements (#4231)

* [LIFX] Add optional host configuration parameter, support new products

* Add host configuration parameter for lights that do not respond to UDP broadcasts (fixes #3913)
* Add support for new products (most notably the new Downlights)
* Add deviceId configuration parameter pattern to prevent mistakes/exceptions
* Fix static code analysis findings
* Make broadcastEnabled final
* Makes the LIFX Binding periodically update network interface information. This for instance resolves the issue that network interfaces are not (or still) being used for broadcasts after they go up (or down).
* The code for this information was duplicated across the LifxLightDiscovery and LifxLightCommunicationHandler classes and has now been extracted into LifxNetworkUtil.
* All utility classes have now been grouped in the .util package.
* Make Device ID an optional configuration paramater, use lambdas and fix updating properties
* Update Thing status to configuration error when Device ID and Host are null
* Introduce logId property so logging identifies light depending on MAC/IP configuration
* Add logId where missing to simplify debugging
* Use lambdas for listener registration and iteratating over listeners
* Resolve @nonnull warnings
* Fix properties not always being updated
* Use a LifxLightContext for sharing common variables between handler helper objects
* Improve exception handling by catching specific exceptions and using more specific error messages
* Don't set host property on discovered lights

Signed-off-by: Wouter Born <eclipse@maindrain.net>
  • Loading branch information
wborn authored and kaikreuzer committed Sep 25, 2017
1 parent 4dd53d9 commit 52d22b3
Show file tree
Hide file tree
Showing 29 changed files with 997 additions and 823 deletions.
Expand Up @@ -4,8 +4,14 @@
xsi:schemaLocation="http://eclipse.org/smarthome/schemas/config-description/v1.0.0 http://eclipse.org/smarthome/schemas/config-description-1.0.0.xsd">

<config-description uri="thing-type:lifx:light">
<parameter name="deviceId" type="text" required="true">
<parameter name="deviceId" type="text" pattern="([0-9A-Fa-f]{12})" required="false">
<label>LIFX device ID</label>
<description>Identifies the light e.g. "D073D5A1A1A1"</description>
</parameter>
<parameter name="host" type="text" required="false">
<label>Host</label>
<description>Hostname or IP address of the light. Use empty value for automatic discovery.</description>
<context>network-address</context>
</parameter>
<parameter name="fadetime" type="integer" required="false">
<label>Fade time</label>
Expand Down
Expand Up @@ -10,6 +10,9 @@ thing-type.lifx.whitelight.label = LIFX White Light

# thing type configuration
thing-type.config.lifx.light.deviceId.label = LIFX device ID
thing-type.config.lifx.light.deviceId.description = Identifies the light, e.g. "D073D5A1A1A1"
thing-type.config.lifx.light.host.label = Host
thing-type.config.lifx.light.host.description = Hostname or IP address of the light. Use empty value for automatic discovery.
thing-type.config.lifx.light.fadetime.label = Fade time
thing-type.config.lifx.light.fadetime.description = The time to fade to the new color value (in ms).

Expand Down
Expand Up @@ -10,6 +10,9 @@ thing-type.lifx.whitelight.label = LIFX Wittinten Lamp

# thing type configuration
thing-type.config.lifx.light.deviceId.label = LIFX apparaat ID
thing-type.config.lifx.light.deviceId.description = Identificeert de lamp, bv. "D073D5A1A1A1"
thing-type.config.lifx.light.host.label = Host
thing-type.config.lifx.light.host.description = Hostnaam of IP adres van de lamp. Gebruik lege waarde voor automatische detectie.
thing-type.config.lifx.light.fadetime.label = Vervagingsduur
thing-type.config.lifx.light.fadetime.description = De tijdsduur van het vervagen naar een nieuwe kleur (in ms).

Expand Down
30 changes: 18 additions & 12 deletions extensions/binding/org.eclipse.smarthome.binding.lifx/README.md
Expand Up @@ -16,6 +16,7 @@ The following table lists the thing types of the supported LIFX devices:
| Color 1000 BR30 | colorlight |
| LIFX A19 | colorlight |
| LIFX BR30 | colorlight |
| LIFX Downlight | colorlight |
| | |
| LIFX+ A19 | colorirlight |
| LIFX+ BR30 | colorirlight |
Expand Down Expand Up @@ -43,7 +44,7 @@ The binding is able to auto-discover all lights in a network over the LIFX UDP p

## Thing Configuration

Each light needs the device ID as a configuration parameter. The device ID is printed as a serial number on the light and can also be found within the native LIFX Android or iOS application. But usually the discovery works quite reliably, so that a manual configuration is not needed.
Each light needs a Device ID or Host as a configuration parameter. The device ID is printed as a serial number on the light and can also be found within the native LIFX Android or iOS application. But usually the discovery works quite reliably, so that a manual configuration is not needed.

However, in the thing file, a manual configuration looks e.g. like

Expand All @@ -53,20 +54,25 @@ Thing lifx:colorlight:living [ deviceId="D073D5A1A1A1", fadetime=200 ]

The *fadetime* is an optional thing configuration parameter which configures the time to fade to a new color value (in ms). When the *fadetime* is not configured, the binding uses 300ms as default.

You can optionally also configure a fixed Host or IP address when lights are in a different subnet and are not discovered.

```
Thing lifx:colorirlight:porch [ host="10.120.130.4", fadetime=0 ]
```

## Channels

All devices support some of the following channels:

| Channel Type ID | Item Type | Description | Thing Types |
|-----------------|-----------|--------------------------------------------------------------------------------------|----------------------------------------|
| brightness | Dimmer | This channel supports adjusting the brightness value. | whitelight |
| color | Color | This channel supports full color control with hue, saturation and brightness values. | colorlight, colorirlight, colormzlight |
| colorzone | Color | This channel supports full zone color control with hue, saturation and brightness values. | colormzlight |
| infrared | Dimmer | This channel supports adjusting the infrared value. *Note:* IR capable lights only activate their infrared LEDs when the brightness drops below a certain level. | colorirlight |
| signalstrength | Number | This channel represents signal strength with values 0, 1, 2, 3 or 4; 0 being worst strength and 4 being best strength. | colorlight, colorirlight, colormzlight, whitelight |
| temperature | Dimmer | This channel supports adjusting the color temperature from cold (0%) to warm (100%). | colorlight, colorirlight, colormzlight, whitelight |
| temperaturezone | Dimmer | This channel supports adjusting the zone color temperature from cold (0%) to warm (100%). | colormzlight |
| Channel Type ID | Item Type | Description | Thing Types |
|-----------------|-----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------|
| brightness | Dimmer | This channel supports adjusting the brightness value. | whitelight |
| color | Color | This channel supports full color control with hue, saturation and brightness values. | colorlight, colorirlight, colormzlight |
| colorzone | Color | This channel supports full zone color control with hue, saturation and brightness values. | colormzlight |
| infrared | Dimmer | This channel supports adjusting the infrared value. *Note:* IR capable lights only activate their infrared LEDs when the brightness drops below a certain level. | colorirlight |
| signalstrength | Number | This channel represents signal strength with values 0, 1, 2, 3 or 4; 0 being worst strength and 4 being best strength. | colorlight, colorirlight, colormzlight, whitelight |
| temperature | Dimmer | This channel supports adjusting the color temperature from cold (0%) to warm (100%). | colorlight, colorirlight, colormzlight, whitelight |
| temperaturezone | Dimmer | This channel supports adjusting the zone color temperature from cold (0%) to warm (100%). | colormzlight |

The *color* and *brightness* channels have a "Power on brightness" configuration option that is used to determine the brightness when a light is switched on. When it is left empty, the brightness of a light remains unchanged when a light is switched on or off.

Expand Down Expand Up @@ -97,12 +103,12 @@ Thing lifx:colorlight:living2 [ deviceId="D073D5A2A2A2" ] {
Type color : color [ powerOnBrightness=50 ]
}
Thing lifx:colorirlight:porch [ deviceId="D073D5B2B2B2", fadetime=0 ] {
Thing lifx:colorirlight:porch [ deviceId="D073D5B2B2B2", host="10.120.130.4", fadetime=0 ] {
Channels:
Type color : color [ powerOnBrightness=75 ]
}
Thing lifx:colormzlight:ceiling [ deviceId="D073D5C3C3C3" ]
Thing lifx:colormzlight:ceiling [ host="10.120.130.5" ]
Thing lifx:whitelight:kitchen [ deviceId="D073D5D4D4D4", fadetime=150 ]
```
Expand Down
Expand Up @@ -25,4 +25,4 @@ <h3>License</h3>
and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>

</body>
</html>
</html>
Expand Up @@ -7,12 +7,13 @@
*/
package org.eclipse.smarthome.binding.lifx;

import static org.eclipse.smarthome.binding.lifx.internal.LifxUtils.kelvinToPercentType;
import static org.eclipse.smarthome.binding.lifx.internal.util.LifxMessageUtil.kelvinToPercentType;

import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.smarthome.binding.lifx.internal.fields.HSBK;
import org.eclipse.smarthome.core.library.types.HSBType;
import org.eclipse.smarthome.core.library.types.PercentType;
Expand All @@ -26,13 +27,18 @@
* @author Dennis Nobel - Initial contribution
* @author Wouter Born - Added packet interval, power on brightness constants
*/
@NonNullByDefault
public class LifxBindingConstants {

public static final String BINDING_ID = "lifx";

// The LIFX LAN Protocol Specification states that lights can process up to 20 messages per second, not more.
public static final long PACKET_INTERVAL = 50;

// Port constants
public static final int BROADCAST_PORT = 56700;
public static final int UNICAST_PORT = 56700;

// Minimum and maximum of MultiZone light indices
public static final int MIN_ZONE_INDEX = 0;
public static final int MAX_ZONE_INDEX = 255;
Expand Down Expand Up @@ -67,6 +73,7 @@ public class LifxBindingConstants {
public static final String CONFIG_PROPERTY_POWER_ON_BRIGHTNESS = "powerOnBrightness";

// Property keys
public static final String PROPERTY_HOST = "host";
public static final String PROPERTY_HOST_VERSION = "hostVersion";
public static final String PROPERTY_MAC_ADDRESS = "macAddress";
public static final String PROPERTY_PRODUCT_ID = "productId";
Expand All @@ -83,6 +90,7 @@ public class LifxBindingConstants {
public static final ThingTypeUID THING_TYPE_COLORMZLIGHT = new ThingTypeUID(BINDING_ID, "colormzlight");
public static final ThingTypeUID THING_TYPE_WHITELIGHT = new ThingTypeUID(BINDING_ID, "whitelight");

@SuppressWarnings("null")
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Stream
.of(THING_TYPE_COLORLIGHT, THING_TYPE_COLORIRLIGHT, THING_TYPE_COLORMZLIGHT, THING_TYPE_WHITELIGHT)
.collect(Collectors.toSet());
Expand Down

0 comments on commit 52d22b3

Please sign in to comment.