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

Add Scenes option to oh-repeater component #1721

Closed
hmerk opened this issue Feb 17, 2023 · 6 comments · Fixed by #1724
Closed

Add Scenes option to oh-repeater component #1721

hmerk opened this issue Feb 17, 2023 · 6 comments · Fixed by #1724
Labels
enhancement New feature or request main ui Main UI

Comments

@hmerk
Copy link

hmerk commented Feb 17, 2023

The problem

The newly introduced scenes via scenes editor are only available within actions when creating custom widgets.

Your suggestion

It would be great to have the scenes available within the oh-repeater component, to create widgets with automatically generated scene lists.

@hmerk hmerk added enhancement New feature or request main ui Main UI labels Feb 17, 2023
@stefan-hoehn
Copy link
Contributor

I looked a bit into the topic because I found it tempting to have a list of scenes that could be switched on and off.
However, from what I understood so far the repeater is all about items and all its components you iterate over are also item-components. The catch is that scenes are specific kind of rules and not items.

What would be possible of course to a new source named "rules" that loads these rules (and I did a proof of concept on that and that works) but they would be processed as items which, I think, is not a clean approach even if added a new component for example "oh-list-rule", for example.

maybe @ghys could give some hints in what direction this could be developed in a clean way.

@hmerk
Copy link
Author

hmerk commented Feb 18, 2023

Thanks for looking into this @stefan-hoehn 👍
From what I understood from the oh-repeater code, we would need to add a new sorce type „rules“ which should issue a REST call against the rules endpoint. The result should then give the rule/scene UID and name (probably the descripton too). The UID could then be used in actions within the widgets to run the rule/scene. As both are stateless, there is no switching on or off….

@stefan-hoehn
Copy link
Contributor

This is exactly what I implemented in my POC but as I mentioned the whole concept is around managing items in widgets or repeaters and not something else like things or rules.

@hmerk
Copy link
Author

hmerk commented Feb 19, 2023

Don't understand your comment.
Actually, you can already run rules within widgets and this is what I want to achieve :

    - component: oh-repeater
      config:
        for: scene
        sourceType: rulesWithTags
        ruleTags: Scene
      slots:
        default:
          - component: oh-button
            config:
              action: rule
              actionRule: =loop.scene.UID
              text: =loop.scene.description

@stefan-hoehn
Copy link
Contributor

Yes, similar to the above code is what I wanted to achieve:

- component: oh-repeater
            config:
              for: rule
              sourceType: rules
            slots:
              default:
                - component: oh-list-item
                  config:
                    icon: oh:window
                    iconColor: red
                    title: =loop.rule.label
                    item: =loop.rule.name
                    badge: =loop.rule.state
                    badgeColor: red

Thanks for insisting on it 😄

This is now what I did: I extended the repeater code to add a new source

else if (this.config.sourceType === 'rules') {
        return this.$oh.api.get('/rest/rules?summary=true').then((d) => d)
      } 

And it does create a list which is based on the rules that have been loaded. I debugged and I could see within the repeater that each element is a rule and you have directed my into the right direction. I was looking for a component that would allow me to access the properties and I tried the oh-list-item (obviously incorrectly - see below) which didn't work and I could't find something suitable but the oh-button did then work with the following widget code based on your idea:

uid: list_of_rules
component: f7-card
config:
  title: Liste von Regeln
slots:
  default:
    - component: oh-list
      slots:
        default:
          - component: oh-repeater
            config:
              for: scene
              sourceType: rules
            slots:
              default:
                - component: oh-button
                  config:
                    action: rule
                    actionRule: =loop.scene.UID
                    text: =loop.scene.description

which in fact produces the following

image

So, I went along, added the ruleTags property

slots:
  default:
    - component: oh-list
      slots:
        default:
          - component: oh-repeater
            config:
              for: scene
              sourceType: rulesWithTags
              ruleTags: Scene
            slots:
              default:
                - component: oh-button
                  config:
                    action: rule
                    actionRule: =loop.scene.uid
                    text: =loop.scene.name

and voila, we get

image

and >drum role< it even works when you click on the entry.

and I tried an oh-list-item and it works as well

- component: oh-list-item
                  config:
                    icon: f7:wand_stars
                    title: =loop.scene.name
                    action: rule
                    actionRule: =loop.scene.uid
                    text: =loop.scene.name

and produces

image

So, I think we can call this "success". Let's say what the maintainers say when I finally do a PR.

@hmerk
Copy link
Author

hmerk commented Feb 19, 2023

Great you did not give up and found a solution 👍
Thanks for looking into this !!!!!!

ghys pushed a commit that referenced this issue Feb 21, 2023
fixes #1721 Add Scenes option to oh-repeater component

This PR adds the possibility to iterate over a list of rules queried via
a tag.

For example it allows to create a list of Scenes via the oh-repeater by
using the rulesTag = Scene and trigger the rule via a oh-button.

Example

```
slots:
  default:
    - component: oh-list
      slots:
        default:
          - component: oh-repeater
            config:
              for: scene
              sourceType: rulesWithTags
              ruleTags: Scene
            slots:
              default:
                - component: oh-button
                  config:
                    action: rule
                    actionRule: =loop.scene.uid
                    text: =loop.scene.name
```

--
Signed-off-by: Stefan Höhn <mail@stefanhoehn.com>
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 a pull request may close this issue.

2 participants