import { CommandClasses , parseNodeUpdatePayload } from "@zwave-js/core" ; import type { Driver } from "../driver/Driver" ; import { FunctionType , MessagePriority , MessageType , } from "../message/Constants" ; import { expectedCallback , gotDeserializationOptions , Message , MessageBaseOptions , MessageDeserializationOptions , MessageOptions , messageTypes , priority , } from "../message/Message" ; import type { SuccessIndicator } from "../message/SuccessIndicator" ; export enum RemoveNodeType { Any = 1 , Controller = 2 , Slave = 3 , Stop = 5 } export enum RemoveNodeStatus { Ready = 1 , NodeFound = 2 , RemovingSlave = 3 , RemovingController = 4 , Done = 6 , Failed = 7 } enum RemoveNodeFlags { HighPower = 0x80 , NetworkWide = 0x40 } interface RemoveNodeFromNetworkRequestOptions extends MessageBaseOptions { removeNodeType ? : RemoveNodeType ; highPower ? : boolean ; networkWide ? : boolean ; } @ messageTypes ( MessageType . Request , FunctionType . RemoveNodeFromNetwork ) @ priority ( MessagePriority . Controller ) export class RemoveNodeFromNetworkRequestBase extends Message { public constructor ( driver , options ) { if ( gotDeserializationOptions ( options ) && ( new . target as any ) !== RemoveNodeFromNetworkRequestStatusReport ) { return new RemoveNodeFromNetworkRequestStatusReport ( driver , options ) ; } super ( driver , options ) ; } } function testCallbackForRemoveNodeRequest ( sent , received ) { if ( ! ( received instanceof RemoveNodeFromNetworkRequestStatusReport ) ) { return false ; } switch ( sent . removeNodeType ) { case RemoveNodeType . Any : case RemoveNodeType . Controller : case RemoveNodeType . Slave : return ( received . status === RemoveNodeStatus . Ready || received . status === RemoveNodeStatus . Failed ) ; case RemoveNodeType . Stop : return ( received . status === RemoveNodeStatus . Done || received . status === RemoveNodeStatus . Failed ) ; default : return false ; } } @ expectedCallback ( testCallbackForRemoveNodeRequest ) export class RemoveNodeFromNetworkRequest extends RemoveNodeFromNetworkRequestBase { public constructor ( driver , options = { } ) { super ( driver , options ) ; this . removeNodeType = options . removeNodeType ; this . highPower = ! ! options . highPower ; this . networkWide = ! ! options . networkWide ; } /** The type of node to remove */ public removeNodeType : RemoveNodeType | undefined ; /** Whether to use high power */ public highPower : boolean = false ; /** Whether to exclude network wide */ public networkWide : boolean = false ; public serialize ( ) { let data = this . removeNodeType || RemoveNodeType . Any ; if ( this . highPower ) data |= RemoveNodeFlags . HighPower ; if ( this . networkWide ) data |= RemoveNodeFlags . NetworkWide ; this . payload = Buffer . from ( [ data , this . callbackId ] ) ; return super . serialize ( ) ; } } export class RemoveNodeFromNetworkRequestStatusReport extends RemoveNodeFromNetworkRequestBase implements SuccessIndicator { public constructor ( driver , options ) { super ( driver , options ) ; this . callbackId = this . payload [ 0 ] ; this . status = this . payload [ 1 ] ; switch ( this . status ) { case RemoveNodeStatus . Ready : case RemoveNodeStatus . NodeFound : case RemoveNodeStatus . Failed : case RemoveNodeStatus . Done : break ; case RemoveNodeStatus . RemovingController : case RemoveNodeStatus . RemovingSlave : this . statusContext = parseNodeUpdatePayload ( this . payload . slice ( 2 ) ) ; break ; } } isOK ( ) { return this . status !== RemoveNodeStatus . Failed ; } public readonly status : RemoveNodeStatus ; public readonly statusContext : RemoveNodeStatusContext | undefined ; } interface RemoveNodeStatusContext { nodeId : number ; basic ? : number ; generic ? : number ; specific ? : number ; supportedCCs ? : CommandClasses [ ] ; controlledCCs ? : CommandClasses [ ] ; }