Skip to content

Add temperature support to light template#30595

Merged
balloob merged 2 commits into
home-assistant:devfrom
tetienne:add_temperature_to_light_template
Jan 23, 2020
Merged

Add temperature support to light template#30595
balloob merged 2 commits into
home-assistant:devfrom
tetienne:add_temperature_to_light_template

Conversation

@tetienne
Copy link
Copy Markdown
Contributor

@tetienne tetienne commented Jan 8, 2020

Description:

Currently light template only support brightness. This PR adds temperature support.

Pull request with documentation for home-assistant.io (if applicable): home-assistant/home-assistant.io#11678

Example entry for configuration.yaml (if applicable):

input_boolean:
  foo_bool_input:

input_number:
  brightness_input:
    min: 0
    max: 255
  temperature_input:
    min: 0
    max: 500

light:
  - platform: template
    lights:
      foo:
        turn_on:
          service: input_boolean.turn_on
          entity_id: input_boolean.brightness_input
        turn_off:
          service: input_boolean.turn_off
          entity_id: input_boolean.brightness_input
        level_template: "{{states('input_number.brightness_input') | int }}"
        value_template: "{{states('input_number.brightness_input') | int > 0}}"
        set_level:
          service: input_number.set_value
          data_template:
            value: "{{ brightness }}"
            entity_id: input_number.brightness_input
        temperature_template: "{{states('input_number.temperature_input') | int}}"
        set_temperature:
          service: input_number.set_value
          data_template:
            value: "{{ color_temp }}"
            entity_id: input_number.temperature_input

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly. Update and include derived files by running python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt by running python3 -m script.gen_requirements_all.
  • Untested files have been added to .coveragerc.

If the code does not interact with devices:

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

@probot-home-assistant
Copy link
Copy Markdown

Hey there @PhracturedBlue, mind taking a look at this pull request as its been labeled with a integration (template) you are listed as a codeowner for? Thanks!

@tetienne tetienne changed the title Add temperature support Add temperature support to light template Jan 8, 2020
@tetienne tetienne mentioned this pull request Jan 21, 2020
9 tasks
@tetienne tetienne requested a review from balloob January 21, 2020 08:29
@callback
def update_temperature(self):
"""Update the temperature from the template."""
if self._temperature_template is not None:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a guard clause: if self._temperature_template is None: return. Even better would be to not even call this function if not necessary.

Copy link
Copy Markdown
Member

@balloob balloob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking great. Ok to merge after final comment addressed.

@tetienne
Copy link
Copy Markdown
Contributor Author

Thx @balloob for your review. I've added the guard clause to other methods too.
Sadly, these methods are called directly by async_update. It will increase its complexity if we remove the guard clause from the child methods.

@balloob balloob merged commit 1a1ef76 into home-assistant:dev Jan 23, 2020
@lock lock Bot locked and limited conversation to collaborators Jan 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants