Skip to content

Add separate command and state topics for mqtt lock#29808

Merged
springstan merged 7 commits into
home-assistant:devfrom
tuxbox:tuxbox-mqtt-lock-improved
Dec 31, 2019
Merged

Add separate command and state topics for mqtt lock#29808
springstan merged 7 commits into
home-assistant:devfrom
tuxbox:tuxbox-mqtt-lock-improved

Conversation

@tuxbox
Copy link
Copy Markdown
Contributor

@tuxbox tuxbox commented Dec 9, 2019

Allow different command and state topic + different command and state values.

Breaking Change:

Two new properties were introduced with state_locked (default: LOCKED) and state_unlocked (default: UNLOCKED). If you were using the same topic as state_topic as for the command_topic you can reestablish the old behaviour by setting state_locked to LOCK and state_unlocked to UNLOCK.
Effectively this change allows you to distinguish commands and states in two topics with different values.

Description:

Allows to separate command and state topics effectively. The configuration.yaml below results in action payloads to be LOCK / UNLOCK and expects a JSON in the state topic that contains at least a state field, e.g.:

{
  "state": "locked"
}

Related issue (if applicable): fixes #

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

Example entry for configuration.yaml (if applicable):

lock:
  - platform: mqtt
    command_topic: "/dev/ha/lock/cmd"
    state_topic:   "/dev/ha/lock/state"
    value_template: "{{ value_json.state }}"
    state_locked: "locked"
    state_unlocked: "unlocked"

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:

  • [n/a] The manifest file has all fields filled out correctly. Update and include derived files by running python3 -m script.hassfest.
  • [n/a] New or updated dependencies have been added to requirements_all.txt by running python3 -m script.gen_requirements_all.
  • [n/a] 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.

Allow different command and state topic + different command and state values.
@tuxbox tuxbox requested a review from a team as a code owner December 9, 2019 22:16
@homeassistant
Copy link
Copy Markdown
Contributor

Hi @tuxbox,

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@probot-home-assistant
Copy link
Copy Markdown

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

@tuxbox tuxbox changed the title Update lock.py MQTT Lock to support separate command and state topics effectively Dec 10, 2019
@MartinHjelmare MartinHjelmare changed the title MQTT Lock to support separate command and state topics effectively Add separate command and state topics for mqtt lock Dec 10, 2019
@MartinHjelmare
Copy link
Copy Markdown
Member

Please write the breaking change paragraph so we can copy it directly to the release notes. Briefly describe what has changed and what the user needs to do to cope with the breaking change.

@MartinHjelmare
Copy link
Copy Markdown
Member

Tests need to be updated and the new config options tested.

@tuxbox
Copy link
Copy Markdown
Contributor Author

tuxbox commented Dec 10, 2019

I am just looking at this and hope to fix it quickly, thanks for looking at it so quickly

@tuxbox
Copy link
Copy Markdown
Contributor Author

tuxbox commented Dec 10, 2019

@MartinHjelmare I have updated the breaking change documentation and hope it works as expected, also the pipelines complete now, test cases were updated to reflect the new configuration options and abbreviations for the properties state_locked and state_unlocked were added. Anything else that needs to be done?

Copy link
Copy Markdown
Member

@MartinHjelmare MartinHjelmare 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! One comment.

Comment thread tests/components/mqtt/test_lock.py
Copy link
Copy Markdown
Member

@MartinHjelmare MartinHjelmare 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!

@springstan springstan merged commit 1c2618d into home-assistant:dev Dec 31, 2019
@lock lock Bot locked and limited conversation to collaborators Jan 1, 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