generated from homebridge/homebridge-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5c219fb
commit e6ddfba
Showing
4 changed files
with
45 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,34 @@ | ||
import { color, openRgbColor, rgbDevice, rgbDeviceStates } from './rgb'; | ||
import { Color, OpenRgbColor, RgbDevice, RgbDeviceStates } from './rgb'; | ||
|
||
/** Gets the RGB color that is set on the provided device */ | ||
export function getDeviceLedRgbColor(device: rgbDevice): color { | ||
const ledColor: openRgbColor = device.colors[0]; | ||
const ledRgb: color = [ledColor.red, ledColor.green, ledColor.blue]; | ||
export function getDeviceLedRgbColor(device: RgbDevice): Color { | ||
const ledColor: OpenRgbColor = device.colors[0]; | ||
const ledRgb: Color = [ledColor.red, ledColor.green, ledColor.blue]; | ||
return ledRgb; | ||
} | ||
|
||
/** Gets the HSV color that is currently represented by an accessory's state */ | ||
export function getStateHsvColor(states: rgbDeviceStates): color { | ||
export function getStateHsvColor(states: RgbDeviceStates): Color { | ||
return [states.Hue, states.Saturation, states.Brightness]; | ||
} | ||
|
||
/** Determines whether the provided color is black */ | ||
export function isLedOff(color: color): boolean { | ||
export function isLedOff(color: Color): boolean { | ||
return color[0] === 0 && color[1] === 0 && color[2] === 0; | ||
} | ||
|
||
/** Finds the ID of a device mode by name or returns undefined if the device has no matching mode */ | ||
export function findDeviceModeId(device: rgbDevice, modeName: string): number | undefined { | ||
export function findDeviceModeId(device: RgbDevice, modeName: string): number | undefined { | ||
return device.modes?.find(mode => mode.name?.trim().toLowerCase() === modeName.trim().toLowerCase())?.id; | ||
} | ||
|
||
/** Takes an RGB color and builds an array that can be used to set all of the given device's LED's */ | ||
export function createDeviceLedConfig(rgbColor: color, device: rgbDevice): openRgbColor[] { | ||
const ledColor: openRgbColor = { | ||
export function createDeviceLedConfig(rgbColor: Color, device: RgbDevice): OpenRgbColor[] { | ||
const ledColor: OpenRgbColor = { | ||
red: rgbColor[0], | ||
green: rgbColor[1], | ||
blue: rgbColor[2], | ||
}; | ||
const ledColors: openRgbColor[] = Array(device.colors.length).fill(ledColor); | ||
const ledColors: OpenRgbColor[] = Array(device.colors.length).fill(ledColor); | ||
return ledColors; | ||
} |