apexad / homebridge-sensor-cmd

Homebridge plugin that creates a contact sensor with state determined by a command-line/shell command in only 25 lines of code"
MIT License
4 stars 1 forks source link

Async calls with polling support? #3

Open ryrun opened 1 year ago

ryrun commented 1 year ago

I used your plugin to do ping to check if a device is active or not, but it seems the "get" function of services for homebridge v1.6.1 doesn't get called in the background regularly, so motion detection is not triggered / get missed. Especially when you want to use it for automation.

I manually "hacked" the .js for to do Async requests and it's working fine now. Maybe you can implement something like this? https://github.com/homebridge/homebridge-plugin-template/blob/d0bca523f5cd56f68d9d1e9b21ae20389bbcb2e5/src/platformAccessory.ts#L80C1-L92C4

This would also fix warnings, when the shell command is "slow".

apexad commented 1 month ago

I know it is about a year later. However, if you are still using this plugin with your hack, could you make a Pull request with the change so I can review it?

ryrun commented 1 month ago

My dirty hack version can be found here: https://github.com/ryrun/homebridge-sensor-cmd. I switched it to JavaScript because I directly modified the JS files. If needed, I could try a TypeScript version once I have a bit more time.