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

Added a prefixed class set service #235

Merged
merged 3 commits into from
Sep 14, 2022

Conversation

binginsin
Copy link
Contributor

@binginsin binginsin commented Sep 11, 2022

Based on the request in #179 added a new floorplan service called class_prefixed_set.
The way it works:
Say we have a prefix ha-light-state and the entity state is on, this will generate a class ha-light-state-on.
If the state changes to off, the service will look at current classes on the element and will try to find a class that matches the prefix (the match it will perform will be ha-light-state-).
If it finds multiple matches it will take the last one, which could be undesirable, but it's up to the user to make sure the class prefix for this element is unique.
If the class with such prefix is found, it will be changed to ha-light-state-off
If the class does not exist, the class will be added.

Added a new floorplan service set_prefixed_class which finds a class with the provided prefix and sets it's value (string after last prefix separator)
@exetico
Copy link
Member

exetico commented Sep 12, 2022

Hi there,

Thanks for the PR. Have you tested it?

@binginsin
Copy link
Contributor Author

I have tested it on my setup and it works. I didn't add too much error handling, but in the cases where I had entered something incorrectly in the yaml I did get some uncaught exceptions. I don't believe that would be a problem and could give some info to users as to what went wrong if they open console.

@exetico
Copy link
Member

exetico commented Sep 14, 2022

Thanks for the reply.

There's one thing we need to talk about:
Is there a reason why you'd like to have this kind of info in the class? I found it a bit odd, and hard to maintain, compared to a exposed state as a dataset.

@binginsin
Copy link
Contributor Author

Wasn't aware of the dataset in the element (not super familiar with HTML5 and latest CSS). Happy to adjust the code to work with datasets instead of setting it on class. Will update the PR once implemented.

@exetico
Copy link
Member

exetico commented Sep 14, 2022

Thanks! 😊

Added a new service dataset_set to floorplan.
@binginsin
Copy link
Contributor Author

@exetico dataset seemed like a much more simple solution with far less code! Have a look if you can approve these changes.

@exetico
Copy link
Member

exetico commented Sep 14, 2022

It looks great. Thank you for the fast pivot to the dataset suggestion 😊. I'll secure it work on my instance right away, and push it to the upstream.

@exetico
Copy link
Member

exetico commented Sep 14, 2022

It's getting late, and It has been a long day... But....

This is giving me the expected temperature from my entity like ``:

  - service: floorplan.dataset_set
    service_data: 'temperature:${entity.state}' 

But this always set the data-temperature to undefined:

  - service: floorplan.dataset_set
    service_data: 
      key: temperature
      state: ${entity.state}

entity.state is not defined.

Please review this part, or tell me that I'm simply too tired to review code right now 😄 ...

@exetico
Copy link
Member

exetico commented Sep 14, 2022

Oh, damn. Your docs says state, but the code says value, so maybe I'm still awake 😉 ...

@binginsin
Copy link
Contributor Author

binginsin commented Sep 14, 2022

@exetico I made a mistake in the docs! My bad...
Rushed to get the commit out - lesson learned.

docs/_docs/03-usage.md Outdated Show resolved Hide resolved
Fixing the docs mistake
@exetico
Copy link
Member

exetico commented Sep 14, 2022

No problem. Thanks for the PR and quick change to dataset. I've considered to create that part by myself, for a good period of time - but there's too much things to handle right now.

I'd also like to mention that is also closes #179 😄 !

@exetico exetico merged commit 45812c0 into ExperienceLovelace:master Sep 14, 2022
@exetico
Copy link
Member

exetico commented Sep 14, 2022

For people visiting this through the release-notes. Here's the how-to:

Short-hand:

  - service: floorplan.dataset_set
    service_data: 'temperature:${entity.state}' 

Long version:

  - service: floorplan.dataset_set
    service_data: 
      key: temperature
      value: ${entity.state}

For more information, see the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants