studioimaginaire / phue

A Python library for the Philips Hue system
Other
1.52k stars 267 forks source link

Bridge.get_light_objects() can return stale data #116

Open ticalc-travis opened 6 years ago

ticalc-travis commented 6 years ago

If new lights are added to the bridge (and presumably also if existing ones are removed) after the Bridge object is instantiated, the return value of get_light_objects() does not reflect the changes. Looking at the code, it appears that get_light_objects just caches the data after first requesting it from the bridge, then never updates it again.

At the very least, there should be a way to explicitly tell the Bridge object to do a refetch of the data. But I would propose simply having get_light_objects fetch the data anew from the bridge each time. Unless there's some other way to know if the lights have actually changed, this seems to be the only sensible thing to do. If performance of polling the bridge is a concern, it's simple enough for users of the module to save the return value themselves if necessary.

Edit: Though I haven't directly tested, it looks like get_sensor_objects() is subject to the same issue.