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

Clean up frontend services and events #31654

Merged
merged 3 commits into from
Feb 10, 2020
Merged

Conversation

balloob
Copy link
Member

@balloob balloob commented Feb 9, 2020

Breaking change

  • frontend.set_theme and frontend.reload_themes now require admin access. This will not break automations that set themes because those are run with admin access.
  • themes_updated event no longer contains all theme data

Proposed change

Cleans up the services and events fired by frontend.

Require admin access for theme-related services that change defaults/reload themes from YAML.

The themes_updated event used to contain all the theme data, which could break the recorder because some themes contain base64 images (#31651)

While implementing this, I ran into a really nasty bug. If you use the @functools.wraps decorator, it copies all info over from the wrapped function, including if it's a callback! If a wrapped function is then passed to async_add_job, we can end up calling sync methods in the event loop or never awaiting async functions. This happens because async_add_job will use loop.call_soon to call them, but not await them. To avoid this, I have introduced a new callback-aware wraps decorator that won't copy it to async functions. We should go through our codebase and verify all wraps invocations. core will now always first check if it's a coroutine function before checking if it's a callback. This solves the problem.

Frontend change: home-assistant/frontend#4812

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example entry for configuration.yaml:

# Example configuration.yaml

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

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.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

@probot-home-assistant
Copy link

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

@recklessnl
Copy link

Require admin access for theme-related services that change defaults/reload themes from YAML.

Does this disable Home Assistant users to choose their front-end theme from an input_select box, like shown here? That would be a major bummer if it were the case, as it's a really cool feature.

@balloob
Copy link
Member Author

balloob commented Feb 9, 2020

frontend.set_theme is changing the default theme for all users, not just the current user. I don't know how the dropdown in your screen recording is implemented.

@recklessnl
Copy link

@balloob this is the automation handling it:

- alias: "Frontend: change theme"
  trigger:
    - platform: state
      entity_id: input_select.theme
    - platform: state
      entity_id: input_boolean.dark_mode
    - platform: state
      entity_id: input_boolean.theme_alternative
    - platform: homeassistant
      event: start
  action:
    service: frontend.set_theme
    data_template:
      name: >
        {% set which = "dark" if is_state("input_boolean.dark_mode", "on") else "light" -%}
        {% set name = states("input_select.theme") -%}
        {% set suffix = "-alternative" if is_state("input_boolean.theme_alternative", "on") else "" -%}
        ios-{{ which }}-mode-{{ name }}{{ suffix }}

@balloob
Copy link
Member Author

balloob commented Feb 9, 2020

Yeah, that won't be supported for non-admin users anymore. Instead, this should be implemented home-assistant/frontend#4813

@codecov
Copy link

codecov bot commented Feb 9, 2020

Codecov Report

Merging #31654 into dev will decrease coverage by 0.00%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##              dev   #31654      +/-   ##
==========================================
- Coverage   94.65%   94.65%   -0.01%     
==========================================
  Files         754      756       +2     
  Lines       54577    54810     +233     
==========================================
+ Hits        51660    51879     +219     
- Misses       2917     2931      +14     
Impacted Files Coverage Δ
homeassistant/__init__.py 88.46% <0.00%> (-7.38%) ⬇️
homeassistant/components/hue/bridge.py 72.07% <0.00%> (-3.42%) ⬇️
homeassistant/components/derivative/sensor.py 88.63% <0.00%> (ø) ⬆️
homeassistant/components/unifi/controller.py 94.88% <0.00%> (-0.03%) ⬇️
homeassistant/components/alexa/entities.py 98.50% <0.00%> (ø) ⬆️
homeassistant/auth/models.py 100.00% <0.00%> (ø) ⬆️
homeassistant/components/axis/device.py 100.00% <0.00%> (ø) ⬆️
homeassistant/components/dsmr/sensor.py 100.00% <0.00%> (ø) ⬆️
homeassistant/components/deconz/sensor.py 96.03% <0.00%> (ø) ⬆️
homeassistant/components/deconz/climate.py 100.00% <0.00%> (ø) ⬆️
... and 23 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5483de7...3507f2a. Read the comment docs.

@recklessnl
Copy link

Good to know. Paging @basnijholt since he wrote the automation.

@balloob balloob merged commit 12de3f1 into dev Feb 10, 2020
@delete-merged-branch delete-merged-branch bot deleted the cleanup-frontend-services-events branch February 10, 2020 03:47
@lock lock bot locked and limited conversation to collaborators Feb 12, 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.

4 participants