import type { Maybe , MessageOrCCLogEntry , MessageRecord , ValueID , } from "@zwave-js/core" ; import { CommandClasses , Duration , validatePayload , ValueMetadata , } from "@zwave-js/core" ; import type { Driver } from "../driver/Driver" ; import { CCAPI , SetValueImplementation , SET_VALUE , throwUnsupportedProperty , throwWrongValueType , } from "./API" ; import { API , CCCommand , CCCommandOptions , ccValue , ccValueMetadata , CommandClass , commandClass , CommandClassDeserializationOptions , gotDeserializationOptions , implementedVersion , } from "./CommandClass" ; export function getSceneIdValueID ( endpoint ) { return { commandClass : CommandClasses [ "Scene Activation" ] , endpoint , property : "sceneId" } ; } export function getDimmingDurationValueID ( endpoint ) { return { commandClass : CommandClasses [ "Scene Activation" ] , endpoint , property : "dimmingDuration" } ; } export enum SceneActivationCommand { Set = 0x01 } @ API ( CommandClasses [ "Scene Activation" ] ) export class SceneActivationCCAPI extends CCAPI { public supportsCommand ( _cmd ) { return true ; } protected [ SET_VALUE ] : SetValueImplementation = async ( { property } , value , options ) : Promise < void > => { if ( property !== "sceneId" ) { throwUnsupportedProperty ( this . ccId , property ) ; } if ( typeof value !== "number" ) { throwWrongValueType ( this . ccId , property , "number" , typeof value ) ; } const duration = Duration . from ( options ?. transitionDuration ) ; await this . set ( value , duration ) ; } ; param duration public async set ( sceneId , dimmingDuration ? ) { this . assertSupportsCommand ( SceneActivationCommand , SceneActivationCommand . Set ) ; const cc = new SceneActivationCCSet ( this . driver , { nodeId : this . endpoint . nodeId , endpoint : this . endpoint . index , sceneId , dimmingDuration : Duration . from ( dimmingDuration ) } ) ; await this . driver . sendCommand ( cc , this . commandOptions ) ; } } @ commandClass ( CommandClasses [ "Scene Activation" ] ) @ implementedVersion ( 1 ) export class SceneActivationCC extends CommandClass { declare ccCommand : SceneActivationCommand ; } interface SceneActivationCCSetOptions extends CCCommandOptions { sceneId : number ; dimmingDuration ? : Duration ; } @ CCCommand ( SceneActivationCommand . Set ) export class SceneActivationCCSet extends SceneActivationCC { public constructor ( driver , options ) { super ( driver , options ) ; if ( gotDeserializationOptions ( options ) ) { validatePayload ( this . payload . length >= 2 ) ; this . sceneId = this . payload [ 0 ] ; this . dimmingDuration = Duration . parseSet ( this . payload [ 1 ] ) ; validatePayload ( this . sceneId >= 1 , this . sceneId <= 255 ) ; this . persistValues ( ) ; } else { this . sceneId = options . sceneId ; this . dimmingDuration = options . dimmingDuration ; } } @ ccValue ( { stateful : false } ) @ ccValueMetadata ( { ... ValueMetadata . UInt8 , min : 1 , label : "Scene ID" , valueChangeOptions : [ "transitionDuration" ] } ) public sceneId : number ; @ ccValue ( ) @ ccValueMetadata ( { ... ValueMetadata . Any , label : "Dimming duration" } ) public dimmingDuration : Duration | undefined ; public serialize ( ) { this . payload = Buffer . from ( [ this . sceneId , this . dimmingDuration ?. serializeSet ( ) ?? 0xff , ] ) ; return super . serialize ( ) ; } public toLogEntry ( ) { const message = { "scene id" : this . sceneId } ; if ( this . dimmingDuration != undefined ) { message [ "dimming duration" ] = this . dimmingDuration . toString ( ) ; } return { ... super . toLogEntry ( ) , message } ; } }