Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Current »

Overview

Represents a Light on the network.

As a sub-class of Device, it inherits everything from that interface, as well as providing convenience methods for interacting with Lights.

API

on()

Usage

Sends a command over the network to turn the LightDevice on.

Returns a PropertyCommandData object containing the future result of the Property modified by the command.

This is a non-blocking call.

Parameters

None.

Returns

Return TypeDescription
PropertyCommandData

Contains a CompletableFuture<Property> of the property being modified by the command.

Contains the last known (cached) value of the property being modified by the command.

Examples

GatewayClient gateway = new GatewayClient(new ConnectionInfo(ConnectionType.ZIGBEE_UART, "/dev/ttyUSB0"),
...
Collection<Device> lights = gateway.getDevices( d -> d.getDeviceType().equals(LightDevice.DEVICE_TYPE) );
for (Device device : lights) {
    LightDevice light = (LightDevice) device;
	light.on();
}

off()

Usage

Sends a command over the network to turn the LightDevice off.

Returns a PropertyCommandData object containing the future result of the Property modified by the command.

This is a non-blocking call.

Parameters

None.

Returns

Return TypeDescription
PropertyCommandData

Contains a CompletableFuture<Property> of the property being modified by the command.

Contains the last known (cached) value of the property being modified by the command.

Examples

GatewayClient gateway = new GatewayClient(new ConnectionInfo(ConnectionType.ZIGBEE_UART, "/dev/ttyUSB0"),
...
Collection<Device> lights = gateway.getDevices( d -> d.getDeviceType().equals(LightDevice.DEVICE_TYPE) );
for (Device device : lights) {
    LightDevice light = (LightDevice) device;
	light.off();
}

readLevel()

Usage

Sends a command over the network to read the level of the LightDevice (i.e. the dimming level)

Returns a CompletableFuture of the 'level' Property.

This is a non-blocking call.

Parameters

None.

Returns

Return TypeDescription
CompletableFuture<Property>A CompletableFuture of the 'level' Property.

Examples

GatewayClient gateway = new GatewayClient(new ConnectionInfo(ConnectionType.ZIGBEE_UART, "/dev/ttyUSB0"),
...
Collection<Device> lights = gateway.getDevices( d -> d.getDeviceType().equals(LightDevice.DEVICE_TYPE) );
for (Device device : lights) {
    final LightDevice light = (LightDevice) device;
	CompletableFuture<Property> futureLevel = light.readLevel();
    // you can block on the future, or handle it asynchronously
    
    // blocking example
    Property level = futureLevel.get();

    // async example
    futureLevel.thenAccept( levelProperty -> System.out.println("Level: " + levelProperty) );
}

moveToLevel(int levelPercentage)

Usage

Sends a command to move the level of the LightDevice (i.e. the dimming level)

Returns a PropertyCommandData object containing the future result of the Property modified by the command.

This is a non-blocking call.

Parameters

NameTypeDescription
levelPercentageintA value between 0 and 100 representing the dimming level of a light.

Returns

Return TypeDescription
PropertyCommandData

Contains a CompletableFuture<Property> of the property being modified by the command.

Contains the last known (cached) value of the property being modified by the command.

Examples

GatewayClient gateway = new GatewayClient(new ConnectionInfo(ConnectionType.ZIGBEE_UART, "/dev/ttyUSB0"),
...
Collection<Device> lights = gateway.getDevices( d -> d.getDeviceType().equals(LightDevice.DEVICE_TYPE) );
for (Device device : lights) {
    LightDevice light = (LightDevice) device;
	light.moveToLevel(50);
}

moveToLevel(int levelPercentage, int transitionTime)

Usage

Same as moveToLevel, with the addition of a transition time (in tenths of a second, or as close as the remote device is able to adhere to).

Parameters

NameTypeDescription
levelPercentageintA value between 0 and 100 representing the dimming level of a light.
transitionTimeintThe time to transition to the desired dimming level, in tenths of a second (or as close as the remote device is able to adhere to).

Returns

Return TypeDescription
PropertyCommandData

Contains a CompletableFuture<Property> of the property being modified by the command.

Contains the last known (cached) value of the property being modified by the command.

Examples

GatewayClient gateway = new GatewayClient(new ConnectionInfo(ConnectionType.ZIGBEE_UART, "/dev/ttyUSB0"),
...
Collection<Device> lights = gateway.getDevices( d -> d.getDeviceType().equals(LightDevice.DEVICE_TYPE) );
for (Device device : lights) {
    LightDevice light = (LightDevice) device;
	light.moveToLevel(25, 10); // move to 25% dim level, over 1 second
}

getDeviceType()

Usage

Returns the DeviceType that the Device belongs to. DeviceType contains a type and category. For a LightDevice, this would be:

  • Category: Lighting
  • Type: Light

The value returned from this method can be used to search the network for Devices of the same type.

Parameters

None.

Returns

Return TypeDescription
DeviceTypeThe DeviceType object categorizing and identifying the LightDevice.

Examples

...
Collection<Device> lights = gw.getDevices( d -> d.getDeviceType().equals(LightDevice.DEVICE_TYPE));
...
System.out.println("LightDevice type: " + gw.getDevice(idStr).getDeviceType().getType() );
...
  • No labels