New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[hue] Fix potential NPE when new battery devices are added to bridge #16619
Conversation
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
} | ||
return BatteryStateType.CRITICAL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if reporting a critical level is the right thing for an unknown state. This might cause some negative sideeffects. Would it be possible to extend the enum with an Unknown
state?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oups, sorry @lsiepel , you submitted you comment at the same time I approved.
But your question is good, I asked me the same.
As I understood the description, it should happen only during a short time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Waiting for @andrewfg answer ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I understood the description, it should happen only during a short time.
This is correct. Hue battery devices communicate their status to the Hue bridge by means of two processes..
- event driven: if someone presses a button on such a device, it immediately sends its new status to the bridge.
- polling: in case nobody presses a button, the bridge also does a slow polling of the battery state; the polling interval is not too fast in order to prevent waking the device too often
This bug would only occur if a new device is added to the Hue bridge and then immediately also added to OH before either case 1. or 2. will have occurred. Prior to this PR that case would cause an NPE, whereas after this PR the battery state is reported as critical until either case 1. or 2. actually occurs, at which time it is updated to the new actual value.
This is quite a seldom case that rights itself quite quickly, so IMHO temporarily reporting critical is actually perfectly Ok.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
Resolves #16617
Sometimes when new battery devices are added to the bridge, the device will not have had enough time on the network for its battery state to have been queried by the bridge. In such cases the bridge returns null in the
Power.batteryState
DTO field, and this causes an NPE.This PR resolves that issue.
Signed-off-by: Andrew Fiddian-Green software@whitebear.ch