dkerr64 / homebridge-yolink

Apache License 2.0
12 stars 2 forks source link

Device offline. Error in update battery info #66

Closed killi23 closed 1 year ago

killi23 commented 1 year ago

just purchased a door sensor and hub to use as a post box sensor. Everything works really well .Your plugin registers the plugin and it shows in the home app but always as "open" . The error message I get "[05/12/2022, 18:41:18] [YoLink] [verbose] checkDeviceState for post box (d88b4c01000508d8) (refresh after 1000 seconds) [05/12/2022, 18:41:18] [YoLink] Device offline or other error for post box (d88b4c01000508d8) [05/12/2022, 18:41:20] [YoLink] [verbose] checkDeviceState for post box (d88b4c01000508d8) (refresh after 1000 seconds) [05/12/2022, 18:41:20] [YoLink] Error in updateBatteryInfo Please report all bugs at https://github.com/dkerr64/homebridge-yolink/issues TypeError: Cannot read properties of undefined (reading 'battery') at YoLinkPlatformAccessory.updateBatteryInfo (/var/lib/homebridge/node_modules/homebridge-yolink/src/platformAccessory.ts:216:67) at YoLinkPlatformAccessory.handleBatteryGet (/var/lib/homebridge/node_modules/homebridge-yolink/src/platformAccessory.ts:246:55)"

Running the latest version of Homebridge on a PI4.Node v18.12.0

Config.

{ "name": "YoLink", "platform": "YoLink", "tokenURL": "https://api.yosmart.com/open/yolink/token", "apiURL": "https://api.yosmart.com/open/yolink/v2/api", "mqttPort": 8003, "userAccessId": "ua_xxx", "secretKey": "sec_xxx", "refreshAfter": 1000, "verboseLog": true, "liteLog": true, "allDevices": true, "excludeTypes": [ "Hub", "SpeakerHub" ], "enableExperimental": true, "_bridge": { "username": "0E:1C:D9:00:67:BD", "port": 52646 } }

Any help appreciated.

dkerr64 commented 1 year ago

Thanks for reporting the error. Could you send me the verbose log please so that I can see the data going to/from YoLink.

FYI, That I use a vibration sensor to monitor my mail box and that it also reports "offline" from time-to-time (probably due to distance) however the plugin should never give error due to undefined variable so I do want to track down what is going on with your device.

Also... I edited your text above to remove the userAccessID and secretKey... you should never post that sort of info.

Thanks.

killi23 commented 1 year ago

Thank you. Yes I had already edited the uuid and secret key prior to posting . Thank you for your concern though.I hope this is what you are looking for ? I am not very familiar with individual logging. According to the Yolink app the signal is very good which I am quite please with .

Thank you for your help.

[05/12/2022, 22:04:11] [YoLink] [verbose] RECEIVED: {"code":"000000","time":1670277851468,"msgid":1670277851468,"method":"Home.getDeviceList","desc":"Success","data":{"devices":[{"deviceId":"d88b4c01000508d8","deviceUDID":"5f5bb596c38b46c7af3fxxxxxxxx","name":"post box","token":"F62FB4BE5497A831CA4015098xxxxxxxx","type":"DoorSensor","parentDeviceId":null},{"deviceId":"d88b4c160400xxxx","deviceUDID":"098a67bf9ae94700b7d5c6e32cxxxxx","name":"Speaker Hub","token":"0533AA43EE77F21C3019E8464EAxxxx","type":"SpeakerHub","parentDeviceId":null}]}} [05/12/2022, 22:04:11] [YoLink] YoLinkAPI.getDeviceList found 2 devices [05/12/2022, 22:04:11] [YoLink] [verbose] {"deviceId":"d88b4c010005xxxxxx","deviceUDID":"5f5bb596c38b46c7af3f8f82f3xxxx","name":"post box","token":"F62FB4BE5497A831CA4015098B8xxxxx","type":"DoorSensor","parentDeviceId":null} [05/12/2022, 22:04:11] [YoLink] [verbose] Restoring accessory from cache: post box (d88b4c01000508d8) [05/12/2022, 22:04:11] [YoLink] [verbose] Data refresh timer for post box (d88b4c01000508d8) fired [05/12/2022, 22:04:11] [YoLink] [verbose] {"deviceId":"d88b4c160400a9a0","deviceUDID":"098a67bf9ae94700b7d5c6e3xxxxx","name":"Speaker Hub","token":"0533AA43EE77F21C3019E8464Exxxx","type":"SpeakerHub","parentDeviceId":null} [05/12/2022, 22:04:11] [YoLink] Not registering device Speaker Hub (d88b4c160400a9a0) as config 'hide=true' [05/12/2022, 22:04:11] [YoLink] Create MQTT client to connect to YoLink message service [05/12/2022, 22:04:11] [YoLink] [verbose] MQTT options: {"clean":true,"username":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE2NzAyNzc4NDksImV4cCI6MTY3MDI4NTA0OSwiaXNzIjoidWFfQjFBRTVCRENBOUFBNDA4MkFFMkU3RUJBMTJBNjdDRTUiLCJhdWQiOiI2YjM0M2UxMzdkYjQ0OWYxOWQ5NWU2OWUxN2I0MmUzMiIsInN1YiI6Ijk4YmQ4Njk0N2VlNzQ5Y2ViMmNmNjQ3OGZiZDM0MTkxIiwic2NvcGUiOlsiYXMvYXUiXX0.R1-1cZ3Mxxxxx0","reconnectPeriod":2000}

dkerr64 commented 1 year ago

The log you sent is only the initialization of the plugin. I need to see what it looks like closer to the error condition. For example, in my log I can find the section below. In particular I need to see the SENDING and RECEIVED logs.

[12/6/2022, 2:31:59 PM] [YoLink] [verbose] SENDING:
{"time":1670355119096,"method":"DoorSensor.getState","targetDevice":"d88b4cxxxxx","token":"D51DXXXXXXXXXX"}
[12/6/2022, 2:31:59 PM] [YoLink] [verbose] RECEIVED:
{"code":"000000","time":1670355119360,"msgid":1670355119360,"method":"DoorSensor.getState","desc":"Success","data":{"online":true,"state":{"alertInterval":0,"battery":4,"delay":0,"openRemindDelay":0,"state":"closed","version":"060d","stateChangedAt":1670201191438},"deviceId":"d88b4cxxxxx","reportAt":"2022-12-06T16:46:17.626Z"}}
[12/6/2022, 2:31:59 PM] [YoLink] [verbose] Battery level for Garage Door Sensor (d88b4c0200067636) is: 100%

You can see in my case I get a 'true' for my online state. It would appear that you get something different, and then are possibly missing the other fields that give the battery state... and then you error out. At a minimum I need to make my code more resilient to that condition, but if you are indeed getting 'false' back for online then that is outside my control.

I do think, however, that even with the current state (not handling possible missing battery information) the plugin should continue to work through the error and if the data retrieved from the door sensor starts to come back as online, then things should work,

dkerr64 commented 1 year ago

Updated the code to allow for undefined battery state