plasticrake / homebridge-tplink-smarthome

TP-Link Smarthome Plugin for Homebridge
MIT License
474 stars 70 forks source link

Deliver last cached value on Characteristic 'get'; async fetch and update value in background #65

Closed timcharper closed 6 years ago

timcharper commented 6 years ago

When this plugin is active it takes a substantial amount of time to load the home app as each switch is queried and, unfortunately, no statuses are reported until homebridge delivers all of the requests (I presume it does it in a single payload). Would it be better to just store the last state seen in each of the classes, and then asynchronously fetch the new state in the background, and update if needed?

I can hack on this but I wanted to get your take on it first. I've done a similar strategy for my other homebridge plugins and the home app loads instantly with them.

plasticrake commented 6 years ago

Hi @timcharper! Can you show me an example? I wasn't aware that this could cause any blocking. I'm not really familiar with the inner workings of homekit. The responses are already callbacks, so it shouldn't block, but I guess you're saying that until a real value is returned it is causing slowness in the Home app? So inside the callback you'd return old or dummy data, but then asynchronously get the real value then update the homekit value?

keith721 commented 6 years ago

I'd like to express support for this request. I use the plugin with three HS110 smart plugs and two HS200 smart switches. Wireless network to the devices is solid, and signal strength/connectivity is not an issue. RPi is connected via wired Ethernet. iPhone6 Plus constantly drops the connection to the bridge because refreshes time out. :( Only resolution is to shutdown and restart the iPhone. Worse is that it disables automation actions for the two HS200 smart switches. Thanks to @timcharper for the suggestion.

timcharper commented 6 years ago

Sorry, @plasticrake ; It turned out it was a different plugin at fault (the homebridge plum plugin... I have a single plum lightpad). I've split the plugins out to multiple homebridge instances and the tplink plugin is loading just fine now.

@keith721 You might try the same thing.

keith721 commented 6 years ago

Thanks for the update, Tim. The TP-Link plugin is the only platform I'm using. It's disappointing the Home app times out. You'd think Apple would be more fault-tolerant, but they simply abandon the bridge until you restart the phone and app.