Skip to content

Move manual configuration of MQTT fan and light to the integration key#71676

Merged
emontnemery merged 31 commits into
home-assistant:devfrom
jbouwh:mqtt-config_entry-setup-for-configuration.yaml
May 19, 2022
Merged

Move manual configuration of MQTT fan and light to the integration key#71676
emontnemery merged 31 commits into
home-assistant:devfrom
jbouwh:mqtt-config_entry-setup-for-configuration.yaml

Conversation

@jbouwh
Copy link
Copy Markdown
Contributor

@jbouwh jbouwh commented May 11, 2022

Breaking change

Defining manually configured MQTT entities directly under the respective platform keys (e.g. fan, light) is deprecated and support will be removed in Home Assistant Core 2022.9.
Manually configured MQTT entities should now be defined under the mqtt key in configuration.yaml instead of under the platform key.

As an example, this is now deprecated:

sensor:
  - platform: "mqtt"
    name: "My sensor"
    state_topic: "some-state-topic"

The configuration needs to updated to this format:

mqtt:
  sensor:
   - name: "My sensor"
     state_topic: "some-state-topic"

Proposed change

Setup MQTT yaml configured entities through config entry setup.
The PR will deprecate setting up MQTT entities using the following form:

sensor:
  - platform: "mqtt"
    name: "My sensor"
    state_topic: "some-state-topic"

New manual configured MQTT entities need to be setup in the following form:

mqtt:
  sensor:
   - name: "My sensor"
     state_topic: "some-state-topic"

The platform schema will stay the same, but the platform configuration item should not be configured.

The current PR (PoC) implements the platforms:

  • light
  • fan

A single test test_setup_manual_entity_from_yaml is added for each platform. A helper help_test_setup_manual_entity_from_yaml is added to make it easy to add a tests for the additional platform.

TODO (in follow-up PRs):

  • Convert all tests to mainly test manual added MQTT items using the integration key.
  • Implement the other platforms (will be done with different PR's).

The background for this PR is that the MQTT integration itself is setup via a config entry, with entities setup via discovery.
MQTT entities can also be setup through configuration.yaml though, and those entities are not aware of the MQTT config entry and thus are not removed if the MQTT config entry is disabled or removed.

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

Additional information

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.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

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

To help with the load of incoming pull requests:

@probot-home-assistant
Copy link
Copy Markdown

Hey there @emontnemery, mind taking a look at this pull request as it has been labeled with an integration (mqtt) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

@emontnemery emontnemery marked this pull request as draft May 11, 2022 09:56
@emontnemery emontnemery changed the title MQTT PoC for processing from yaml through entry setup MQTT PoC for configuring yaml entities through entry setup May 11, 2022
Comment thread homeassistant/components/mqtt/__init__.py
Comment thread homeassistant/components/mqtt/fan.py Outdated
Comment thread homeassistant/components/mqtt/__init__.py Outdated
@jbouwh jbouwh force-pushed the mqtt-config_entry-setup-for-configuration.yaml branch from 386bf37 to 41963ef Compare May 11, 2022 14:14
Comment thread homeassistant/components/mqtt/discovery.py Outdated
Comment thread homeassistant/components/mqtt/__init__.py Outdated
Comment thread homeassistant/components/mqtt/mixins.py Outdated
Comment thread homeassistant/components/mqtt/fan.py Outdated
Comment thread homeassistant/components/mqtt/mixins.py Outdated
Comment thread homeassistant/components/mqtt/__init__.py Outdated
@jbouwh jbouwh marked this pull request as ready for review May 18, 2022 07:17
Copy link
Copy Markdown
Contributor

@emontnemery emontnemery left a comment

Choose a reason for hiding this comment

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

I think this is a good change, I'd like a 2nd opinion though just in case I miss something.

Comment thread homeassistant/components/mqtt/fan.py Outdated
Comment thread homeassistant/components/mqtt/__init__.py
Comment thread homeassistant/components/mqtt/mixins.py Outdated
Comment thread tests/components/mqtt/test_common.py Outdated
Comment thread tests/components/mqtt/test_common.py Outdated
Comment thread tests/components/mqtt/test_common.py Outdated
Comment thread tests/components/mqtt/test_common.py Outdated
Comment thread homeassistant/components/mqtt/mixins.py Outdated
Comment thread homeassistant/components/mqtt/mixins.py Outdated
Comment thread tests/components/mqtt/test_init.py Outdated
Comment thread tests/components/mqtt/test_init.py Outdated
jbouwh and others added 4 commits May 19, 2022 10:18
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
@MartinHjelmare
Copy link
Copy Markdown
Member

We'll have time to move all platforms before beta cut next week?

@MartinHjelmare MartinHjelmare removed the second-opinion-wanted Add this label when a reviewer needs a second opinion from another member. label May 19, 2022
@jbouwh
Copy link
Copy Markdown
Contributor Author

jbouwh commented May 19, 2022

We'll have time to move all platforms before beta cut next week?

Sure. As soon as this is merged i'll submit PR's for all remaining platforms. There are already prepared :-)

@emontnemery emontnemery reopened this May 19, 2022
@emontnemery emontnemery changed the title MQTT PoC for configuring yaml entities through entry setup Move manually configured MQTT fan and light to the mqtt integration key May 19, 2022
@emontnemery emontnemery changed the title Move manually configured MQTT fan and light to the mqtt integration key Move manual configuration on MQTT fan and light to the integration key May 19, 2022
@emontnemery emontnemery changed the title Move manual configuration on MQTT fan and light to the integration key Move manual configuration of MQTT fan and light to the integration key May 19, 2022
@emontnemery emontnemery merged commit ed1c2ea into home-assistant:dev May 19, 2022
Copy link
Copy Markdown
Member

@frenck frenck left a comment

Choose a reason for hiding this comment

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

Nice work @jbouwh 👍 Tested locally and works as expected.
I'm not sure about the documentation URL yet to be honest, but we can change that later if needed 👍

@frenck
Copy link
Copy Markdown
Member

frenck commented May 19, 2022

Oh, merged. Alright that's good too I guess 😞

0bmay pushed a commit to 0bmay/home-assistant-core that referenced this pull request May 19, 2022
home-assistant#71676)

* Processing yaml config through entry setup

* Setup all platforms

* Update homeassistant/components/mqtt/__init__.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* adjust mock_mqtt - reference config from cache

* Fix test config entry override

* Add tests yaml setup

* additional tests

* Introduce PLATFORM_SCHEMA_MODERN

* recover temporary MQTT_BASE_PLATFORM_SCHEMA

* Allow extra key in light base schema, restore test

* Fix test for exception on platform key

* One deprecation message per platform

* Remove deprecation checks from modern schema

* Update homeassistant/components/mqtt/fan.py

Co-authored-by: Erik Montnemery <erik@montnemery.com>

* Update homeassistant/components/mqtt/fan.py

Co-authored-by: Erik Montnemery <erik@montnemery.com>

* Update homeassistant/components/mqtt/light/__init__.py

Co-authored-by: Erik Montnemery <erik@montnemery.com>

* Update homeassistant/components/mqtt/light/__init__.py

Co-authored-by: Erik Montnemery <erik@montnemery.com>

* Update homeassistant/components/mqtt/light/schema_json.py

Co-authored-by: Erik Montnemery <erik@montnemery.com>

* Update homeassistant/components/mqtt/light/schema_template.py

Co-authored-by: Erik Montnemery <erik@montnemery.com>

* Update homeassistant/components/mqtt/mixins.py

Co-authored-by: Erik Montnemery <erik@montnemery.com>

* rename validate_modern_schema

* Do not fail platform if a single config is broken

* Update homeassistant/components/mqtt/__init__.py

Co-authored-by: Erik Montnemery <erik@montnemery.com>

* Fix tests on asserting log

* Update log. Make helper transparant, remove patch

* Perform parallel processing

* Update tests/components/mqtt/test_init.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Apply suggestions from code review

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/components/mqtt/mixins.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* black

* Fix tests and add #new_format anchor

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
Co-authored-by: Erik Montnemery <erik@montnemery.com>
@github-actions github-actions Bot locked and limited conversation to collaborators May 20, 2022
@jbouwh jbouwh deleted the mqtt-config_entry-setup-for-configuration.yaml branch May 21, 2022 18:52
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.

5 participants