@@ -134,9 +134,9 @@ function handleMessage(msg) {
134
134
135
135
// Find a parser for this modelID and cid.
136
136
const cid = msg . data . cid ;
137
- const parser = parsers . find ( ( p ) => p . devices . includes ( mappedModel . model ) && p . cid === cid ) ;
137
+ const _parsers = parsers . filter ( ( p ) => p . devices . includes ( mappedModel . model ) && p . cid === cid ) ;
138
138
139
- if ( ! parser ) {
139
+ if ( ! _parsers . length ) {
140
140
console . log ( `
141
141
WARNING: No parser available for '${ mappedModel . model } ' with cid '${ cid } '
142
142
Please create an issue on https://github.com/Koenkk/xiaomi-zb2mqtt/issues
@@ -146,19 +146,20 @@ function handleMessage(msg) {
146
146
147
147
// Parse generic information from message.
148
148
const friendlyName = settings . devices [ device . ieeeAddr ] . friendly_name ;
149
- const topic = `${ settings . mqtt . base_topic } /${ friendlyName } /${ parser . topic } ` ;
150
-
151
- // Define publish function.
152
- const publish = ( payload ) => mqttPublish ( topic , payload . toString ( ) ) ;
153
149
154
150
// Get payload for the message.
155
151
// - If a payload is returned publish it to the MQTT broker
156
152
// - If NO payload is returned do nothing. This is for non-standard behaviour
157
153
// for e.g. click switches where we need to count number of clicks and detect long presses.
158
- const payload = parser . parse ( msg , publish ) ;
159
- if ( payload ) {
160
- publish ( payload ) ;
161
- }
154
+ _parsers . forEach ( ( parser ) => {
155
+ const topic = `${ settings . mqtt . base_topic } /${ friendlyName } /${ parser . topic } ` ;
156
+ const publish = ( payload ) => mqttPublish ( topic , payload . toString ( ) ) ;
157
+ const payload = parser . parse ( msg , publish ) ;
158
+
159
+ if ( payload ) {
160
+ publish ( payload ) ;
161
+ }
162
+ } ) ;
162
163
}
163
164
164
165
function handleQuit ( ) {
0 commit comments