Skip to content
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

[Main UI] Added Badge for BatteryLow warning #1063

Merged
merged 3 commits into from
May 21, 2021

Conversation

cweitkamp
Copy link
Contributor

  • Added Badge for BatteryLow warning

Closes #1060

@ghys Untested new feature. I need your advice. Is it really that easy? Or did I miss something?

Signed-off-by: Christoph Weitkamp [email protected]

Signed-off-by: Christoph Weitkamp <[email protected]>
@cweitkamp cweitkamp requested a review from a team as a code owner May 20, 2021 18:41
@@ -70,6 +71,10 @@ export default {
query () {
let direct, equipment, allPoints, points
switch (this.type) {
case 'battery':
direct = findPoints(this.element.properties, 'Point_LowBattery', true)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we check for property "Energy" too?

Suggested change
direct = findPoints(this.element.properties, 'Point_LowBattery', true)
direct = findPoints(this.element.properties, 'Point_LowBattery', true, 'Property_Energy')

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we check for property "Energy" too?

I think that's superfluous since the point class alone is self-describing.

Also it's Point_Status_LowBattery, not Point_LowBattery.

@relativeci
Copy link

relativeci bot commented May 20, 2021

Job #129: Bundle Size — 10.41MB (~+0.01%).

d2c7905 vs 15f49a3

Changed metrics (1/8)
Metric Current Baseline
Initial JS 1.6MB(~+0.01%) 1.6MB
Changed assets by type (1/7)
            Current     Baseline
JS 8.14MB (~+0.01%) 8.14MB

View Job #129 report on app.relative-ci.com

Copy link
Member

@ghys ghys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, yes basically that's it - you got the class name wrong though and I'd suggest another icon.

The code of these status badges could definitely be improved to be more generic and extensible, so people could add their own badges (the code to map related items is rather similar for each types).

Perhaps a check on BatteryLevel points with a numerical state below 10 % could be also considered since this is what I usually see as channels, never "low battery" explicitely. Though probably LowBattery items could be linked to the actual level with a 0-10 Range profile...

@@ -70,6 +71,10 @@ export default {
query () {
let direct, equipment, allPoints, points
switch (this.type) {
case 'battery':
direct = findPoints(this.element.properties, 'Point_LowBattery', true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we check for property "Energy" too?

I think that's superfluous since the point class alone is self-describing.

Also it's Point_Status_LowBattery, not Point_LowBattery.

Signed-off-by: Christoph Weitkamp <[email protected]>
@cweitkamp
Copy link
Contributor Author

Thanks for your feedback. I changed the class name and the icon. I finally got it running in my own dev environment.

It would be a nice enhancement if users can define their own Badges or change the existing logic. I already have another improvement in my mind. I would like to consider equipment of type "VoiceAssitant" and state "PLAY" for speakers.

I am no friend of fixed values. e.g. I would prefer 15% for Battery Low. Thus I think the Profiles Hysteresis and Range are the best solutions.

Copy link
Member

@ghys ghys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the purpose of these badges wasn't originally designed with user extensibility in mind, rather provide sensible hardcoded defaults for common equipment so that stuff appears automatically, but of course it was a poor choice since the OH users like customizability, and since it proves quite popular and needs arise we can revisit this goal.

That's also why I mentioned the "battery level < 10%" as a suggestion as an additional criteria for bringing up the "battery low" icon, as many devices only have battery level channels that are likely to be mapped as-is with the default profile, and few users would bother to define dedicated "battery low" items with profiles for their equipment (or even know how to) if it's not offered as a channel.
But for now let's just agree on the BatteryLow point requirement 👍

case 'battery':
direct = findPoints(this.element.properties, 'Point_Status_LowBattery', true)
if (direct.length) return direct
return findPoints(allEquipmentPoints(this.element.equipment), 'Point_LowBattery', true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You missed this one!

Suggested change
return findPoints(allEquipmentPoints(this.element.equipment), 'Point_LowBattery', true)
return findPoints(allEquipmentPoints(this.element.equipment), 'Point_Status_LowBattery', true)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦🏼 Ups ... changed it.

Signed-off-by: Christoph Weitkamp <[email protected]>
@@ -70,6 +71,10 @@ export default {
query () {
let direct, equipment, allPoints, points
switch (this.type) {
case 'battery':
direct = findPoints(this.element.properties, 'Point_Status_LowBattery', true)
Copy link
Member

@ghys ghys May 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just realizing now that lines 75 & 76 here might even be unnecessary - these prioritize points directly under the Location over those under an Equipment... but having LowBattery points directly under a Location makes little sense I think, you would expect batteries to be under Equipment all the time?

Edit: Never mind, let's be open-minded, some locations might have batteries, whataver that means :)

@ghys ghys merged commit c71db73 into openhab:main May 21, 2021
@ghys
Copy link
Member

ghys commented May 21, 2021

@cweitkamp I think an update to the docs (https://www.openhab.org/docs/tutorial/model.html#badges) is in order - I wish these would be in a reference doc rather than the tutorial...

@cweitkamp cweitkamp deleted the feature-battery-low-badge branch May 21, 2021 14:21
@cweitkamp
Copy link
Contributor Author

Of course: openhab/openhab-docs#1583.

@ghys ghys added this to the 3.1 milestone May 30, 2021
@ghys ghys added main ui Main UI enhancement New feature or request labels May 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request main ui Main UI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Main UI] Add system default Badge for BatteryLow
2 participants