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

RFC: Static templates match no entities, not all #17991

Merged
merged 2 commits into from Oct 30, 2018

Conversation

Projects
None yet
5 participants
@amelchio
Member

amelchio commented Oct 29, 2018

Description:

The below template sensor stopped updating with 0.81 because of the icon_template where no entity ids can be found. I was surprised to learn that this sensor has been updating with each state change.

I propose to have extract_entities return an empty list (i.e. no entity ids) rather than MATCH_ALL in this case where a static text is used.

For the template sensor it will be a usability improvement and for other template platforms that still accept MATCH_ALL it could be a performance improvement.

This is marked RFC because I realize that in a perfect world nobody would put static texts into the template engine.

CC @balloob @pvizeli

Related issue (if applicable):

https://community.home-assistant.io/t/solved-sensor-template-confusion/75523

https://community.home-assistant.io/t/suppress-template-sensor-warning-in-0-81-1/75658

Example entry for configuration.yaml (if applicable):

sensor:
  - platform: template
    sensors:
      desk_watt:
        value_template: '{{ states.switch.desk.attributes.current_power_w }}'
        icon_template: mdi:power-plug

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox.

If the code does not interact with devices:

  • Tests have been added to verify that the new code works.

amelchio added some commits Oct 27, 2018

@amelchio amelchio requested a review from home-assistant/core as a code owner Oct 29, 2018

@wafflebot wafflebot bot added the in progress label Oct 29, 2018

@houndci-bot

Some files could not be reviewed due to errors:

Traceback (most recent call last):
Traceback (most recent call last):
  File "/home/linters/.local/bin/flake8", line 7, in 
    from flake8.main.cli import main
ModuleNotFoundError: No module named 'flake8'
@pvizeli

This comment has been minimized.

Member

pvizeli commented Oct 29, 2018

I don't think that you should use a template for a static text. Anyway, that's not the questions but an interesting aspect of a need.

I think we should not return a []. We made this change because we don't want to have an event listener to MATCH_ALL. The icon template has no event listener, so we should be able to ignore this check for such fields? I don't think icon should create a state change without the sensor value have also changed.

@balloob what do you think?

@amelchio

This comment has been minimized.

Member

amelchio commented Oct 30, 2018

Oh, so the issue actually is that since #13041 we do listen for changes on icon etc. templates.

I also just added that to the template binary sensor but I agree with simply removing it.

@balloob

This comment has been minimized.

Member

balloob commented Oct 30, 2018

If we look at the fix in isolation (without the template entity context), if we know nothing is dynamic in the template, we should return an empty list. So I think that this change is good.

It is debatable if an icon should cause extra state change listeners. I think that it should, but we might want to move that to an architecture issue.

@balloob balloob merged commit 3de822a into home-assistant:dev Oct 30, 2018

5 checks passed

Hound No violations found. Woof!
WIP ready for review
Details
cla-bot Everyone involved has signed the CLA
continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage increased (+0.0005%) to 93.003%
Details

@wafflebot wafflebot bot removed the in progress label Oct 30, 2018

@balloob balloob referenced this pull request Nov 9, 2018

Merged

0.82 #18335

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment