YinHangCode / homebridge-mi-aqara

a homebridge plugin for XiaoMi Aqara plugin.
1.08k stars 154 forks source link

Wireless Switch not working in homebridge but shown on logs #314

Open semih-akbas opened 1 year ago

semih-akbas commented 1 year ago

Hi, my homebridge-mi-aqara installation is working just fine, however despite showing up on the accessories, it is not updating the state on accessories list. Below, you can find the logs when I physically clicked, long pressed and double clicked the device. Why is it not updating in the homebridge UI like it does for other accessories.

[22/05/2023, 21:32:54] [MiAqaraPlatform] [DEBUG][Revc]{"cmd":"report","model":"switch","sid":"158d00018b49c1","short_id":31625,"data":"{\"status\":\"click\"}"} [22/05/2023, 21:32:56] [MiAqaraPlatform] [DEBUG][Revc]{"cmd":"report","model":"switch","sid":"158d00018b49c1","short_id":31625,"data":"{\"status\":\"long_click_press\"}"} [22/05/2023, 21:32:57] [MiAqaraPlatform] [DEBUG][Revc]{"cmd":"report","model":"switch","sid":"158d00018b49c1","short_id":31625,"data":"{\"status\":\"long_click_release\"}"} [22/05/2023, 21:32:59] [MiAqaraPlatform] [DEBUG][Revc]{"cmd":"report","model":"switch","sid":"158d00018b49c1","short_id":31625,"data":"{\"status\":\"double_click\"}"}

semih-akbas commented 1 year ago

I think I've found the root cause. If I check the MotionSensorParser class, parserAccessories method, as seen in the code below, the event is advertised with the callbacks to the upper levels. However, this routine does not exist for any ButtonParsers. @YinHangCode I hope this helps.


if(that.platform.ConfigUtil.getAccessorySyncValue(deviceSid, that.accessoryType)) {
                if (motionDetectedCharacteristic.listeners('get').length == 0) {
                    motionDetectedCharacteristic.on("get", function(callback) {
                        var command = '{"cmd":"read", "sid":"' + deviceSid + '"}';
                        that.platform.sendReadCommand(deviceSid, command).then(result => {
                            var value = that.getMotionDetectedCharacteristicValue(result, null);
                            if(null != value) {
                                callback(null, value);
                            } else {
                                callback(new Error('get value fail: ' + result));
                            }
                        }).catch(function(err) {
                            that.platform.log.error(err);
                            callback(err);
                        });
                    });
                }
            }