Util

Util

new Util()

Utility class with several color and range conversion methods.

Methods

calculateColorControlTransitionTime

(static) calculateColorControlTransitionTime(optsopt): number

Calculate a transitionTime value for the color control cluster, it takes one parameter: the opts object provided by a Homey.Device.registerCapabilityListener which can hold a duration property (in milliseconds).

Parameters

Name Type Description
opts
object <optional>
duration
number <optional>

Duration property in milliseconds (preferred over 'transition_time')

}

Returns

transitionTime - Transition time (0 - 65535) in tenths of seconds as per Zigbee Cluster Specification section 5.2.2.3.3.4.

number

calculateLevelControlTransitionTime

(static) calculateLevelControlTransitionTime(optsopt): number

Calculate a transitionTime value for the level control cluster, it takes one parameter: the opts object provided by a Homey.Device.registerCapabilityListener which can hold a duration property (in milliseconds).

Parameters

Name Type Description
opts
object <optional>
duration
number <optional>

Duration property in milliseconds (preferred over 'transition_time')

}

Returns

transitionTime - Transition time (0 - 65534) in tenths of seconds as per Zigbee Cluster Specification section 3.10.2.4.1.2.

number

convertCIEToHSV

(static) convertCIEToHSV(): HSV

Method that converts colors from the CIE (xyY) color space to the HSV color space. Note: do not use this for converting xy values from Zigbee devices to HSV, that seems to be inaccurate (see: https://github.com/colorjs/color-space/issues/48).

Parameters

Type Description
CIExyY

xyY color object

Returns

  • HSV color object
HSV

convertHSVToCIE

(static) convertHSVToCIE(): CIExyY

Method that converts colors from the HSV (or HSL) color space to the CIE (1931) color space.

Parameters

Type Description
HSV

HSV color object

Returns

  • CIExyY color space object

debounce

(static) debounce(fn, interval, immediateopt): function

Plain JS implementation of debounce, returns a function which will be debounced when called.

Parameters

Name Type Description
fn
function

Function to debounce

interval
number

Time in ms the function will be debounced.

immediate
boolean <optional>
default:false

If true then leading debounce, false then trailing debounce.

Returns

  • Debounced function
function

debugZigbeeClusters

(static) debugZigbeeClusters(flag, namespaces)

Note: this method has been deprecated since 1.5.0, please use debug from zigbee-clusters.

Enables or disables debug logging in the zigbee-clusters module.

Parameters

Name Type Description
flag
boolean

Set to true to enable logging

namespaces
string

As specified by debug npm module (e.g. zigbee-clusters:bound-cluster:*).

Example

const { Util } = require('homey-zigbeedriver');
Util.debugZigbeeClusters(true);

limitValue

(static) limitValue(value, min, max): number

Limit a value between min and max.

Parameters

Name Type Description
value
number
min
number
max
number

Returns

number

mapTemperatureToHueSaturation

(static) mapTemperatureToHueSaturation(temperature): HSV

Takes a temperature value (0-1) and returns a HSV object. It tries to mimic the light temperature capabilities some devices have for RGB devices.

Parameters

Name Type Description
temperature
number

Returns

  • Range 0 - 1
HSV

mapValueRange

(static) mapValueRange(originalRangeStart, originalRangeEnd, newRangeStart, newRangeEnd, value): number

Map a range of values to a new range.

Parameters

Name Type Description
originalRangeStart
number
originalRangeEnd
number
newRangeStart
number
newRangeEnd
number
value
number

Returns

  • Value mapped from original range to new range.
number

throttle

(static) throttle(fn, interval): function

Plain JS implementation of throttle, returns a function that will be throttled when called.

Parameters

Name Type Description
fn
function

Function to throttle.

interval
number

Time to wait in ms.

Returns

  • Throttled function
function