UNPKG

@pmouli/isy-matter-server

Version:

Service to expose an ISY device as a Matter Border router

81 lines (65 loc) 2.52 kB
import { DimmableLightDevice } from '@matter/node/devices'; import { OnOffServer } from '@matter/node/behaviors'; import { Converter } from 'isy-nodejs'; import { Devices } from 'isy-nodejs/ISY'; import { BehaviorRegistry } from '../BehaviorRegistry.js'; import { ISYClusterBehavior } from '../ISYClusterBehavior.js'; //@ts-ignore const BaseLevelControlServer = DimmableLightDevice.requirements.LevelControlServer; export class DimmerLevelControlBehavior extends ISYClusterBehavior(BaseLevelControlServer, Devices.Insteon.DimmerLamp) { override async handleOnOffChange(value: boolean): Promise<void> { /*if(value) { this.state.currentLevel = this.state.onLevel; } else { this.state.currentLevel = this.minLevel; }*/ //Do nothing - the current level is already being set by the level control } override async initialize(_options?: {}): Promise<void> { await super.initialize(_options); this.state.minLevel = 1; this.state.maxLevel = 254; this.state.currentLevel = this.state.onLevel ?? 254; } /*override async moveToLevel(request: LevelControl.MoveToLevelRequest): Promise<void> { this.logger.debug('MoveToLevel Request received: ' + JSON.stringify(request)); if(request.level == this.state.maxLevel && this.state.currentLevel == this.state.minLevel) //If the light is off and we are setting it to max, set it to onLevel { let onOffServer = this.agent.get(OnOffServer); this.logger.debug('Turning on light to onLevel'); await this.device.on(); this.state.currentLevel = this.state.onLevel; onOffServer.state.onOff = true; return Promise.resolve(); } else { return super.moveToLevel(request); } }*/ override async setLevel(level: number): Promise<void> { if(level == this.state.maxLevel && this.state.currentLevel == this.state.minLevel) //If the light is off and we are setting it to max, set it to onLevel { let onOffServer = this.agent.get(OnOffServer); this.logger.debug('Turning on light to onLevel'); await onOffServer.on(); this.state.currentLevel = this.state.onLevel; return Promise.resolve(); } const inLevel = Converter.Matter.Percent.LightingLevel.from(level); if (inLevel > 0) { await this.device.on(inLevel); this.state.currentLevel = level; } else { let onOffServer = this.agent.get(OnOffServer); this.logger.debug('Turning light off'); await onOffServer.off(); this.state.currentLevel = this.minLevel; } } } BehaviorRegistry.register(DimmerLevelControlBehavior);