import { MessageOrCCLogEntry , NodeType } from "@zwave-js/core" ; import { getEnumMemberName } from "@zwave-js/shared" ; 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 { MultiStageCallback , SuccessIndicator , } from "../message/SuccessIndicator" ; import { computeNeighborDiscoveryTimeout } from "./AddNodeToNetworkRequest" ; export enum NodeNeighborUpdateStatus { UpdateStarted = 0x21 , UpdateDone = 0x22 , UpdateFailed = 0x23 } export interface RequestNodeNeighborUpdateRequestOptions extends MessageBaseOptions { nodeId : number ; } @ messageTypes ( MessageType . Request , FunctionType . RequestNodeNeighborUpdate ) @ priority ( MessagePriority . Controller ) export class RequestNodeNeighborUpdateRequestBase extends Message { public constructor ( driver , options ) { if ( gotDeserializationOptions ( options ) && ( new . target as any ) !== RequestNodeNeighborUpdateReport ) { return new RequestNodeNeighborUpdateReport ( driver , options ) ; } super ( driver , options ) ; } } @ expectedCallback ( FunctionType . RequestNodeNeighborUpdate ) export class RequestNodeNeighborUpdateRequest extends RequestNodeNeighborUpdateRequestBase { public constructor ( driver , options ) { super ( driver , options ) ; this . nodeId = options . nodeId ; } public nodeId : number ; public serialize ( ) { this . payload = Buffer . from ( [ this . nodeId , this . callbackId ] ) ; return super . serialize ( ) ; } public getCallbackTimeout ( ) { return computeNeighborDiscoveryTimeout ( this . driver , NodeType . Controller ) ; } public toLogEntry ( ) { return { ... super . toLogEntry ( ) , message : { "callback id" : this . callbackId } } ; } } export class RequestNodeNeighborUpdateReport extends RequestNodeNeighborUpdateRequestBase implements SuccessIndicator , MultiStageCallback { public constructor ( driver , options ) { super ( driver , options ) ; this . callbackId = this . payload [ 0 ] ; this . _updateStatus = this . payload [ 1 ] ; } isOK ( ) { return this . _updateStatus !== NodeNeighborUpdateStatus . UpdateFailed ; } isFinal ( ) { return this . _updateStatus === NodeNeighborUpdateStatus . UpdateDone ; } private _updateStatus : NodeNeighborUpdateStatus ; public get updateStatus ( ) : NodeNeighborUpdateStatus { return this . _updateStatus ; } public toLogEntry ( ) { return { ... super . toLogEntry ( ) , message : { "callback id" : this . callbackId , "update status" : getEnumMemberName ( NodeNeighborUpdateStatus , this . _updateStatus ) } } ; } }