8000 Add `update` platform to MQTT integration by bieniu · Pull Request #80659 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add update pla 8000 tform to MQTT integration #80659

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

Merged
merged 9 commits into from
Oct 24, 2022
Merged

Add update platform to MQTT integration #80659

merged 9 commits into from
Oct 24, 2022

Conversation

bieniu
Copy link
Member
@bieniu bieniu commented Oct 20, 2022

Proposed change

This PR introduces update platform for MQTT integration.
Example of configuration:

mqtt:
  update:
    - state_topic: "test-update/installed"
      latest_version_topic: "test-update/latest"
      command_topic: "test-update/command"
      payload_install: "install"
      name: "Test Update 1"

    - state_topic: "test-update/topic"
      value_template: "{{ value_json.installed }}"
      latest_version_topic: "test-update/topic"
      latest_version_template: "{{ value_json.latest }}"
      name: "Test Update 2"

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)
  • Deprecation (breaking change to happen in the future)
  • 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.

To help with the load of incoming pull requests:

@home-assistant
Copy link

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!

@jbouwh jbouwh self-requested a review October 20, 2022 09:06
Copy link
Member
@thecode thecode left a comment

Choose a reason for hiding this comment

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

LGTM once coverage pass and docs added.

Copy link
Contributor
@jbouwh jbouwh left a comment

Choose a reason for hiding this comment

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

Looks good overall, you will need a doc PR as well.
@emontnemery A review from your side is highly appreciated

@thecode thecode added the noteworthy Marks a PR as noteworthy and should be in the release notes (in case it normally would not appear) label Oct 20, 2022
Copy link
10000 Contributor
@jbouwh jbouwh left a comment

Choose a reason for hiding this comment

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

Thnx @bieniu, excelent work!

@thecode
Copy link
Member
thecode commented Oct 20, 2022

Thnx @bieniu, excelent work!

Same, great work and nice addition to the MQTT support

@bieniu
Copy link
Member Author
bieniu commented Oct 20, 2022

Thank you guys!

Copy link
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.

The PR looks good as such, but it omits a lot of features which are present in UpdateEntity.

It makes sense to start small and add additional features as needed, so that's not a problem as such.

However, this PR starts out with a dedicated topic + template for the latest_version property, which means every new property we want to add in the future will also need its own topic + template, if we follow the same pattern.
Would it be better to do something like:

  • A general topic for the read only properties (installed_version, latest_version, title, etc. etc.)
  • The general property topic accepts a JSON payload, with an optional template which returns key/value pairs for the properties
    It's perfectly fine to only accept updates of the latest_version property on a general topic in this PR.

Or maybe it's wanted to separate the properties on their own topics for improved flexibility?

Is there some existing external software which supports updates over MQTT using a schema which is compatible with or at least similar to what's proposed in this PR? Zigbee2mqtt supports controlling OTA over MQTT, is its schema compatible with this PR?



class MqttUpdate(MqttEntity, UpdateEntity, RestoreEntity):
"""representation of an MQTT update."""
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"""representation of an MQTT update."""
"""Representation of an MQTT update entity."""

Copy link
Member

Choose a reason for hiding this comment

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

@emontnemery yes, Shelly should work with this PR for users which are using it via MQTT.

Copy link
Member Author

Choose a reason for hiding this comment

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

@emontnemery My goal was to be able to create update entities for Shelly devices using MQTT. Initially, I also thought that one topic and template would be the best solution. However, It turned out that for Shelly Gen2 devices it will not work because these devices send installed_version and latest_version in separate topics (progress is also sent in a separate topic).
In my opinion, separate topics and templates are definitely a more flexible solution. If we decide on one topic and a static payload scheme, we will close access to this platform to devices/services that are not DIY and whose firmware is not easy to change.

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps it is an idea to have a optional state topic that can also accept a json dict (like the siren platform has), so the state can be overrided and has the capability of providing installed and latest version.
But for this PR, may be it is a good idea to have seperate topic's as it appears this is also a pattern in real live.

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought of one more possibility. state_topic can be used for title, entity_picture, release_url, release_summary properties, and for installed_version and latest_version will be separate topics.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think optional the value_template could resolve all of them if they are supplied, May be for some other cases they are all supplies in one tipic. The state_topic accepted payload could be JSON only. The separate topics are should then be optional probably.

Copy link
Member Author

Choose a reason for hiding this comment

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

@jbouwh I'm not sure I understand you. You mean state_topic with JSON data, e.g.:
{"installed_version": "2.0", "latest_version": "2.1", "title" "Test", "release_url": "https://test.com/", "release_summary": "summary"}
and optionally installed_version_topic and/or latest_version_topic if required by the device? If installed_version_topic/latest_version_topic are present in the config we use them, otherwise we use values from state_topic JSON.

Copy link
Contributor

Choose a reason for hiding this comment

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

@jbouwh I'm not sure I understand you. You mean state_topic with JSON data, e.g.: {"installed_version": "2.0", "latest_version": "2.1", "title" "Test", "release_url": "https://test.com/", "release_summary": "summary"} and optionally installed_version_topic and/or latest_version_topic if required by the device? If installed_version_topic/latest_version_topic are present in the config we use them, otherwise we use values from state_topic JSON.

That is indeed what I mean, state_topic should be optional in that case (I would advice base the config schema on MQTT_BASE_SCHEMA). My idea is that state_topic could be used to receive all config options.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks @bieniu for explaining 👍

Copy link
Contributor
@jbouwh jbouwh left a comment

Choose a reason for hiding this comment

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

A few typing hit suggestions. I believe we can use DiscoveryInfoType for validated discovery config. If we can have both YAML or discovery config, we can use ConfigType.

@bieniu bieniu marked this pull request as draft October 23, 2022 21:37
@bieniu bieniu marked this pull request as ready for review October 24, 2022 09:37
Copy link
Contributor
@jbouwh jbouwh left a comment

Choose a reason for hiding this comment

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

It is okay to go ahead with the PR as it is now.
Thanx @bieniu!

@bieniu bieniu merged commit 1f0cb73 into home-assistant:dev Oct 24, 2022
@bieniu bieniu deleted the mqtt-update branch October 24, 2022 09:47
StevenLooman pushed a commit to StevenLooman/home-assistant that referenced this pull request Oct 24, 2022
Djelibeybi pushed a commit to Djelibeybi/home-assistant-core that referenced this pull request Oct 24, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Oct 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla-signed core Hacktoberfest has-tests integration: mqtt new-feature new-platform noteworthy Marks a PR as noteworthy and should be in the release notes (in case it normally would not appear) Quality Scale: No score
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0