File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -74,21 +74,24 @@ export abstract class MQTTAccessory<C extends AccessoryConfig> {
7474 getTopic : keyof C , getHandler : CharacteristicGetHandler ,
7575 setTopic : keyof C | undefined = undefined , setHandler : CharacteristicSetHandler | undefined = undefined ) {
7676
77+ if ( this . config [ getTopic ] === undefined && ( setTopic === undefined || setHandler === undefined || this . config [ setTopic ] !== undefined ) ) {
78+ for ( const characteristic of this . accessoryService . characteristics ) {
79+ if ( characteristic . UUID === constructor . UUID ) {
80+ this . accessoryService . removeCharacteristic ( characteristic ) ;
81+ break ;
82+ }
83+ }
84+ return ;
85+ }
86+
7787 const characteristic = this . accessoryService . getCharacteristic ( constructor ) ;
78- let used = false ;
7988
8089 if ( this . config [ getTopic ] !== undefined ) {
8190 characteristic . onGet ( getHandler ) ;
82- used = true ;
8391 }
8492
8593 if ( setTopic !== undefined && setHandler !== undefined && this . config [ setTopic ] !== undefined ) {
8694 characteristic . onSet ( setHandler ) ;
87- used = true ;
88- }
89-
90- if ( ! used ) {
91- this . accessoryService . removeCharacteristic ( characteristic ) ;
9295 }
9396 }
9497
You can’t perform that action at this time.
0 commit comments