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

Fix rotationPercent settings from entity config #319

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

HeavenFox
Copy link

The plugin code supports updating rotation percentage using value calculated from the entity config yaml, but the config factory does not pass this field along, so it does not work. This PR fixes the issue.

@cgiesche
Copy link
Owner

Hi and thank you very much for your contribution!

I am completely confused by my own code (maybe because it is ugly, but i failed to refactor it to a more readable form more than once ;)).

What exactly is this doing? I see that after the property has been set in the renderingConfig that the following (before your change 'dead') code will be executed:

if (renderingConfig.rotationPercent !== undefined) {
    rotationPercent[currentContext] = renderingConfig.rotationPercent
  }

This updates the current rotationPercent value for a knob. But why? Can you describe your use-case? (I know, I added the code somewhen but I am not sure what the intention was)?

@HeavenFox
Copy link
Author

Hi and thank you very much for your contribution!

I am completely confused by my own code (maybe because it is ugly, but i failed to refactor it to a more readable form more than once ;)).

What exactly is this doing? I see that after the property has been set in the renderingConfig that the following (before your change 'dead') code will be executed:

if (renderingConfig.rotationPercent !== undefined) {
    rotationPercent[currentContext] = renderingConfig.rotationPercent
  }

This updates the current rotationPercent value for a knob. But why? Can you describe your use-case? (I know, I added the code somewhen but I am not sure what the intention was)?

Hello! I am trying to control a motorized shade. I can call set_position with JSON

{
  "position": <some percentage>
}

Therefore I would need to know the percentage.

Initially I wanted to read from the state, but the code is really ugly:

{
  "position": "{% raw %}{{{% endraw %} state_attr('<some entity>', 'current_position') +  ({{ticks}}) {%raw%}}}{%endraw%}"
}

So I thought if I can keep the rotationPercent in sync with Home Assistant's state, the code can be simplified

{
  "position": "{{ rotationPercent }}"
}

I am also exploring an "optimistic update" feature, where if you rotate the knob, the percentage is immediately reflected on the screen, until overridden by Home Assistant's state. This is also for the motorized shades, since those things are slow, and if you rotate the knob, you have no idea what value you set it to.

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