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

Allow customisation of location-card badges. #890

Merged
merged 3 commits into from
Mar 22, 2021

Conversation

crnjan
Copy link
Contributor

@crnjan crnjan commented Feb 7, 2021

Was using OH 3 before #771 was merged - at that time blinds badges were displayed on location card(s) when rollershutters were closed (in my case position > 0) - and after fix was merged, really still cannot get used seeing badge when blinds are open (up) :)

So instead of arguing what is better, let's make it configurable so each can decide what suits best.

For example - Living Room, 3 blinds, 2 closed - default configuration:

If we want to see blind's badge when position > 0 we can write

config:
  label: Home Page
locations:
  - component: oh-locations-tab
    config:
      cardOrder:
       ...
      excludedCards: []
    slots:
      gGF_Living:
        - component: oh-location-card
          config:
            badges:
              blinds:
                expression: Number.parseInt(state) > 0          

result

We can override icon too

        - component: oh-location-card
          config:
            badges:
              blinds:
                expression: Number.parseInt(state) > 0       
                badge:
                  icon: f7:logo_windows

Badges can be overridden per card (as above example) or for all cards

config:
  label: Home Page
locations:
  - component: oh-locations-tab
    config:
      badges:
        blinds:
          badge:
            icon: f7:logo_windows
          expression: Number.parseInt(state) > 0

If both are specified, per-card definition takes precedence.

All badges can be overridden, i.e. both lights&blinds

config:
  label: Home Page
locations:
  - component: oh-locations-tab
    config:
      badges:
        blinds:
          expression: Number.parseInt(state) > 0
        lights:
          badge:
            icon: f7:sun_max

result

I look forward to any feedback or comments.

Signed-off-by: Boris Krivonog boris.krivonog@inova.si

@crnjan crnjan requested a review from a team as a code owner February 7, 2021 22:23
@crnjan crnjan force-pushed the feature/location_card_badge_customization branch from 0f96cf1 to 4ebc895 Compare February 10, 2021 13:11
@ghys ghys added the rebuild trigger a new Jenkins job label Feb 10, 2021
@eikowagenknecht
Copy link
Contributor

Just wanted to say I really like this idea. Having all "open" Rollershutters shown makes no sense for me either, but for other types of Blinds I like it, so being able to configure it would indeed be nice.

@ghys
Copy link
Member

ghys commented Mar 8, 2021

Thanks @crnjan and sorry for the delay.
First about #771 - it seems it was indeed a regression and feels less intuitive for most, so it might be wise to revert it altogether - and adjust the documentation to make it clear that for blinds/rollershutters the icons is shown for those which are closed, whereas for doors/windows it's shown for those which are open, as this also might be considered less consistent - but as long as it's documented, it's fine.

Part of the reason I sat on this PR is that while we're at it, it could be good to go all the way and add some parameters to also specify not only the "reduce" part but also the "map" part: arrays of equipment classes to consider, with or without subclasses, possibly other criteria too.
This would unlock the ability to maybe offer the ability to add custom badges, not only the hardcoded list of those which already exist - this could be in a badges slot of the oh-location-card?

I'd be tempted to approve this PR as-is, as it looks good, to be honest, that being said, if we have to change the API afterwards again it's probably best to figure out what we aim to do before introducing new options.
Wdyt?

@crnjan
Copy link
Contributor Author

crnjan commented Mar 10, 2021

Thx for the feedback, totally agree - but unfortunately don't get much (spare) time last days, will try to figure something up ASAP.

crnjan added 3 commits March 11, 2021 21:52
Signed-off-by: Boris Krivonog <boris.krivonog@inova.si>
Signed-off-by: Boris Krivonog <boris.krivonog@inova.si>
Signed-off-by: Boris Krivonog <boris.krivonog@inova.si>
@crnjan crnjan force-pushed the feature/location_card_badge_customization branch from ad913a4 to 97a20ef Compare March 11, 2021 20:53
@relativeci
Copy link

relativeci bot commented Mar 11, 2021

Job #23: Bundle Size — 10.88MB (~+0.01%).

1ec3222 vs 1cfec4b

Changed metrics (2/8)
Metric Current Baseline
Initial JS 1.59MB(+0.04%) 1.59MB
Cache Invalidation 15% 2.61%
Changed assets by type (1/7)
            Current     Baseline
JS 8.55MB (+0.01%) 8.55MB

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

@@ -73,14 +73,14 @@ export default {
}
},
map () {
return this.query.map((item) => this.store[item.name].state).filter((state) => Number.isFinite(Number.parseFloat(state.split(' ')[0])))
return this.query.map((item) => this.store[item.name].state).filter((state) => Number.isFinite(Number.parseFloat(state)))
Copy link
Member

@ghys ghys Mar 16, 2021

Choose a reason for hiding this comment

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

Can you explain why these .split(' ')|0] were removed? They seemed to be useful when you had math operations to perform on quantity types (represented as strings with the unit in the API, you can't perform e.g. averages with them).

Copy link
Contributor Author

@crnjan crnjan Mar 22, 2021

Choose a reason for hiding this comment

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

If parseFloat encounters a character other than a plus sign (+), minus sign (- U+002D HYPHEN-MINUS), numeral (0–9), decimal point (.), or exponent (e or E), it returns the value up to that character, ignoring the invalid character and characters following it.

So IMHO it's not needed ... from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseFloat

The following examples all return 3.14:

parseFloat(3.14);
parseFloat('3.14');
parseFloat('  3.14  ');
parseFloat('314e-2');
parseFloat('0.0314E+2');
parseFloat('3.14some non-digit characters');

so parseFloat('3.14 C'); should work ...

@crnjan
Copy link
Contributor Author

crnjan commented Mar 22, 2021

Sorry for delayed responses, I hope I'll find some spare time over the weekend to make some progress, if not before ...

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.

Sorry Boris for the long delay. I think your changes are valuable and if we're ever to change the API, as long as we agree on them for the long-term and revisit them, eventually, they're okay to include for now.

@ghys ghys merged commit 7f777cb into openhab:main Mar 22, 2021
@ghys ghys added enhancement New feature or request main ui Main UI labels Apr 1, 2021
@ghys ghys added this to the 3.1 milestone Apr 1, 2021
@crnjan crnjan deleted the feature/location_card_badge_customization branch May 4, 2021 10:37
@cweitkamp
Copy link
Contributor

@crnjan Nice work. May I ask you to add this to the documentation. That would be really much appreciated. Thanks in advance.

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 rebuild trigger a new Jenkins job
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants