-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from sajmonr/7-add-device-feature-detection
- Loading branch information
Showing
13 changed files
with
172 additions
and
55 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
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { DeviceFunction } from './device-functions'; | ||
|
||
/** | ||
* Device function definition | ||
*/ | ||
export interface DeviceFunctionDef{ | ||
/** Type of device this applies to */ | ||
type: DeviceFunction; | ||
|
||
/** API attribute ID */ | ||
attributeId: number; | ||
|
||
/** API function instance name string */ | ||
functionInstanceName?: string; | ||
|
||
/** Device function class */ | ||
functionClass: string; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { DeviceFunctionDef } from './device-function-def'; | ||
|
||
/** | ||
* Device functions types | ||
*/ | ||
export enum DeviceFunction{ | ||
LightPower, | ||
Brightness, | ||
FanPower, | ||
FanSpeed | ||
} | ||
|
||
/** | ||
* Supported/implemented device functions | ||
* with identifiers for discovery and/or manipulation. | ||
*/ | ||
export const DeviceFunctions: DeviceFunctionDef[] = [ | ||
{ | ||
type: DeviceFunction.LightPower, | ||
attributeId: 2, | ||
functionClass: 'power', | ||
functionInstanceName: 'light-power' | ||
}, | ||
{ | ||
type: DeviceFunction.Brightness, | ||
attributeId: 4, | ||
functionClass: 'brightness' | ||
}, | ||
{ | ||
type: DeviceFunction.FanPower, | ||
attributeId: 3, | ||
functionClass: 'power', | ||
functionInstanceName: 'fan-power' | ||
}, | ||
{ | ||
type: DeviceFunction.FanSpeed, | ||
attributeId: 6, | ||
functionClass: 'fan-speed', | ||
functionInstanceName: 'fan-speed' | ||
} | ||
]; | ||
|
||
/** | ||
* Gets function definition for a type | ||
* @param deviceFunction Function type | ||
* @returns Function definition for type | ||
* @throws {@link Error} when a type has no definition associated with it | ||
*/ | ||
export function getDeviceFunctionDef(deviceFunction: DeviceFunction): DeviceFunctionDef{ | ||
const fc = DeviceFunctions.find(fc => fc.type === deviceFunction); | ||
|
||
// Throw an error when not found - function definition must be set during development, | ||
// otherwise the plugin will not work as expected. | ||
if(!fc){ | ||
throw new Error(`Failed to get function definition for '${deviceFunction}'. Each function requires to set a definition.`); | ||
} | ||
|
||
return fc; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* Response for device function | ||
*/ | ||
export interface DeviceFunctionResponse{ | ||
/** Class of the function */ | ||
functionClass: string; | ||
/** Instance name of the function */ | ||
functionInstance: string; | ||
} |
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
Oops, something went wrong.