File tree 4 files changed +12
-0
lines changed
4 files changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,7 @@ type HomieEvent = HomieDeviceEvent | HomieNodeEvent | HomiePropertyEvent;
40
40
interface MqttMessageHandler {
41
41
handleMessage ( topic : string , message : Buffer ) : void ;
42
42
subscribe ( topic : string ) : void ;
43
+ publish ( topic : string , message : string | Buffer ) : void ;
43
44
}
44
45
declare class MqttClient implements MqttMessageHandler {
45
46
private client ;
@@ -49,6 +50,7 @@ declare class MqttClient implements MqttMessageHandler {
49
50
homiePrefix ?: string | undefined ;
50
51
} | undefined , messageCallback : ( event : HomieEvent ) => void ) ;
51
52
subscribe ( pattern : string ) : void ;
53
+ publish ( topic : string , message : string | Buffer ) : void ;
52
54
private getSubscriptionTopic ;
53
55
handleMessage ( topic : string , message : Buffer ) : void ;
54
56
private handleDeviceState ;
Original file line number Diff line number Diff line change @@ -50,6 +50,7 @@ type HomieEvent = HomieDeviceEvent | HomieNodeEvent | HomiePropertyEvent;
50
50
interface MqttMessageHandler {
51
51
handleMessage ( topic : string , message : Buffer ) : void ;
52
52
subscribe ( topic : string ) : void ;
53
+ publish ( topic : string , message : string | Buffer ) : void ;
53
54
}
54
55
55
56
// MQTT Client class
@@ -71,6 +72,10 @@ class MqttClient implements MqttMessageHandler {
71
72
this . client . subscribe ( subscriptionTopic ) ;
72
73
}
73
74
75
+ public publish ( topic : string , message : string | Buffer ) : void {
76
+ this . client . publish ( this . homiePrefix + "/" + topic , message ) ;
77
+ }
78
+
74
79
private getSubscriptionTopic ( pattern : string ) : string {
75
80
return pattern . startsWith ( this . homiePrefix ) ? pattern : `${ this . homiePrefix } /${ pattern } ` ;
76
81
}
Original file line number Diff line number Diff line change @@ -36,6 +36,10 @@ class MockMqttClient implements MqttMessageHandler {
36
36
subscribe ( topic : string ) : void {
37
37
// no-op - mock implementation
38
38
}
39
+
40
+ publish ( topic : string , message : string | Buffer ) : void {
41
+ // no-op - mock implementation
42
+ }
39
43
}
40
44
41
45
describe ( 'HomieObserver' , ( ) => {
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ class MockMqttClient implements MqttMessageHandler {
19
19
}
20
20
21
21
subscribe ( topic : string ) : void { }
22
+ publish ( topic : string , message : string | Buffer ) : void { }
22
23
}
23
24
24
25
describe ( 'HomiePropertyBuffer' , ( ) => {
You can’t perform that action at this time.
0 commit comments