Skip to content

Correct MQTT device trigger reconfiguration with same topic#36234

Merged
balloob merged 1 commit intohome-assistant:devfrom
emontnemery:fix_mqtt_trigger_reconfigure
May 28, 2020
Merged

Correct MQTT device trigger reconfiguration with same topic#36234
balloob merged 1 commit intohome-assistant:devfrom
emontnemery:fix_mqtt_trigger_reconfigure

Conversation

@emontnemery
Copy link
Copy Markdown
Contributor

Proposed change

Correct MQTT device trigger reconfiguration with same topic:

  • If the reconfiguration does not change the topic, do not resubscribe+subscribe because it will happen in the wrong order.

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.
  • 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
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!
(message by CodeOwnersMention)

@emontnemery
Copy link
Copy Markdown
Contributor Author

emontnemery commented May 28, 2020

The unsubscribe is scheduled as a task:

if self.connected:
self.hass.async_create_task(self._async_unsubscribe(topic))

But the subscribe is not:

if self.connected:
await self._async_perform_subscription(topic, qos)

This asymmetry is not very intuitive.

Making the async_remove() a coroutine would break custom components, I'm not sure if that's OK.

If async_remove() is changed to return the task, it's not a breaking change, maybe that's better?
Edit: Making async_remove() return the task doesn't solve the asymmetry but at least makes it possible to have a predictable execution of the unsubscribe.

@MartinHjelmare, @balloob what do you think?

@balloob
Copy link
Copy Markdown
Member

balloob commented May 28, 2020

I think that returning the task is good improvement to make it work better.

Somehow back in the days I wanted all functions that integrations exposed never wait for the work to be done, instead of allowing the caller to decide to wait or not.

@balloob balloob merged commit f1af5b7 into home-assistant:dev May 28, 2020
@balloob balloob mentioned this pull request May 28, 2020
CoMPaTech pushed a commit to plugwise/home-assistant.core that referenced this pull request May 30, 2020
@emontnemery emontnemery deleted the fix_mqtt_trigger_reconfigure branch June 10, 2020 18:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Automation trigger based on MQTT dicovery device works only once

3 participants