Skip to content

Fix rotationPercent settings from entity config#319

Open
HeavenFox wants to merge 1 commit into
cgiesche:masterfrom
HeavenFox:fix_rotation_percent
Open

Fix rotationPercent settings from entity config#319
HeavenFox wants to merge 1 commit into
cgiesche:masterfrom
HeavenFox:fix_rotation_percent

Conversation

@HeavenFox
Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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