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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use asyncio in XiaomiAqara instead of threading #74979

Merged
merged 7 commits into from
Sep 15, 2022

Conversation

starkillerOG
Copy link
Contributor

@starkillerOG starkillerOG commented Jul 11, 2022

Breaking change

Proposed change

Use async instead of a infinite while loop in a thread for listening to multicast messages in the Xiaomi Aqara integration.
Bump PyXiaomiGateway to 0.14.1:
Danielhiversen/PyXiaomiGateway@0.13.4...0.14.1

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.

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

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

@starkillerOG
Copy link
Contributor Author

Test failure is unrelated

@starkillerOG
Copy link
Contributor Author

@Danielhiversen would you mind revieuwing and approving this PR?

@frenck frenck added the smash Indicator this PR is close to finish for merging or closing label Jul 25, 2022
@starkillerOG
Copy link
Contributor Author

@frenck do you have time to review/merge this?

Dev automation moved this from Needs review to Review in progress Sep 4, 2022
@starkillerOG
Copy link
Contributor Author

@MartinHjelmare I prossed all your feedback, thanks a lot, I keep learing.
I also removed the add_job and changed bus.fire() to bus.async_fire() since those are all callbacks from the datagram_protocol so within the event loop (I think).

Do you have any more feedback or can this be merged?

@@ -293,7 +293,7 @@ def parse_data(self, data, raw_data):
)

if self.entity_id is not None:
self._hass.bus.fire(
self._hass.bus.async_fire(
Copy link
Member

@MartinHjelmare MartinHjelmare Sep 13, 2022

Choose a reason for hiding this comment

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

Side note for the future: All of these events should be moved out of the binary sensor platform. Entities shouldn't fire custom events.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I know (from the Xiaomi Miio PR) but that is out of scope for this PR.
The rest of that part of the code is untouched, I only use the appropriate async_fire instead of just fire.

homeassistant/components/xiaomi_aqara/__init__.py Outdated Show resolved Hide resolved
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
@starkillerOG
Copy link
Contributor Author

@MartinHjelmare can you merge this?

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

Thanks!

Dev automation moved this from Review in progress to Reviewer approved Sep 15, 2022
@MartinHjelmare MartinHjelmare changed the title XiaomiAqara use async instead of threading Use asyncio in XiaomiAqara instead of threading Sep 15, 2022
@MartinHjelmare MartinHjelmare merged commit ade4fca into home-assistant:dev Sep 15, 2022
Dev automation moved this from Reviewer approved to Done Sep 15, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Sep 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla-signed code-quality dependency integration: xiaomi_aqara smash Indicator this PR is close to finish for merging or closing
Projects
Dev
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

6 participants