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鈥檒l 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 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
@balloob balloob requested a review from home-assistant/core as a code owner Feb 9, 2020
@probot-home-assistant

This comment has been minimized.

Copy link

probot-home-assistant bot commented Feb 9, 2020

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!

@project-bot project-bot bot added this to Needs review in Dev Feb 9, 2020
@recklessnl

This comment has been minimized.

Copy link

recklessnl commented Feb 9, 2020

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

This comment has been minimized.

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

This comment has been minimized.

Copy link

recklessnl commented Feb 9, 2020

@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

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

Copy link

recklessnl commented Feb 9, 2020

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

Dev automation moved this from Needs review to Reviewer approved Feb 9, 2020
@balloob balloob merged commit 12de3f1 into dev Feb 10, 2020
10 checks passed
10 checks passed
CI Build #20200209.11 succeeded
Details
CI (FullCheck Mypy) FullCheck Mypy succeeded
Details
CI (FullCheck Pylint) FullCheck Pylint succeeded
Details
CI (Overview CheckFormat) Overview CheckFormat succeeded
Details
CI (Overview Lint) Overview Lint succeeded
Details
CI (Overview Validate) Overview Validate succeeded
Details
CI (Tests PyTest Python37) Tests PyTest Python37 succeeded
Details
cla-bot Everyone involved has signed the CLA
codecov/patch 97.82% of diff hit (target 94.65%)
Details
codecov/project 94.65% (target 90.00%)
Details
Dev automation moved this from Reviewer approved to Done Feb 10, 2020
@delete-merged-branch delete-merged-branch bot deleted the cleanup-frontend-services-events branch Feb 10, 2020
@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
Dev
  
Done
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants
You can鈥檛 perform that action at this time.