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

Refactor homekit_controller to be fully asynchronous #32111

Merged
merged 3 commits into from
Feb 24, 2020

Conversation

Jc2k
Copy link
Member

@Jc2k Jc2k commented Feb 23, 2020

Breaking change

Unsure whether to add anything here. homekit_controller will switch from using a synchronous and blocking implementation of the homekit protocol to using a fully asynchronous one. This should be seamless and no configuration changes are required. But it is obviously a riskier change than usual so should be highlighted?

Proposed change

homekit_controller currently using a synchronous dependency for speaking the HomeKit protocol and I want to change this:

  • So I can support (in a future PR) HomeKit events (e.g. homekit remotes will trigger automations in near real time, HA UI will update immediately to changes on your accessories themselves)
  • To support devices that send unsolicited events that the sync code can't handle (sync connection can only be in RPC mode or event mode)
  • So I can get a high integration quality score
  • So I can eventually support BLE accessories via aioble or similiar

This is a long running branch for me - the first working prototype has been running since Jul 2019. Much time has been spent testing it since then and getting it ready. And I think we might nearly be there.

Note to reviewers - I plan to do follow up PR's for things which I felt didn't belong in this PR:

  • Supporting characteristic state update events
  • Supporting homekit remotes and buttons with device triggers
  • Updating config flow tests to use hass.config_entries.flow.async_init etc which I think is best practice now?
  • Tidy up the test accessory fixtures and make them more representative of real devices

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

The integration reached or maintains the following Integration Quality Scale:

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

@codecov
Copy link

codecov bot commented Feb 23, 2020

Codecov Report

Merging #32111 into dev will increase coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##              dev   #32111      +/-   ##
==========================================
+ Coverage   94.72%   94.74%   +0.01%     
==========================================
  Files         767      767              
  Lines       55486    55495       +9     
==========================================
+ Hits        52560    52578      +18     
+ Misses       2926     2917       -9
Impacted Files Coverage Δ
...mponents/homekit_controller/alarm_control_panel.py 100% <100%> (ø) ⬆️
...stant/components/homekit_controller/config_flow.py 100% <100%> (ø) ⬆️
...ant/components/homekit_controller/binary_sensor.py 100% <100%> (ø) ⬆️
...meassistant/components/homekit_controller/cover.py 100% <100%> (ø) ⬆️
...eassistant/components/homekit_controller/sensor.py 100% <100%> (ø) ⬆️
...eassistant/components/homekit_controller/switch.py 100% <100%> (ø) ⬆️
...omeassistant/components/homekit_controller/lock.py 100% <100%> (ø) ⬆️
...istant/components/homekit_controller/connection.py 92.73% <100%> (-0.09%) ⬇️
...assistant/components/homekit_controller/climate.py 99.1% <100%> (ø) ⬆️
...stant/components/homekit_controller/air_quality.py 100% <100%> (ø) ⬆️
... and 23 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f975654...c86cd4d. Read the comment docs.

tests/components/homekit_controller/test_config_flow.py Outdated Show resolved Hide resolved
@@ -60,13 +74,21 @@
]


def _setup_flow_handler(hass):
def _setup_flow_handler(hass, pairing=None):
flow = config_flow.HomekitControllerFlowHandler()
Copy link
Member

Choose a reason for hiding this comment

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

In another PR this should preferably be made more robust by using the core interfaces to set up the tests. Ie start the config flow with hass.config_entries.flow.async_init. See the hue config flow tests for good examples.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah i think i saw your PR doing this to an integration a little while back and put it on my todo list (see PR description). Thanks for the pointer to a good example.

Dev automation moved this from By Code Owner to Review in progress Feb 23, 2020
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.

Great!

Dev automation moved this from Review in progress to Reviewer approved Feb 24, 2020
@MartinHjelmare MartinHjelmare merged commit df93636 into home-assistant:dev Feb 24, 2020
Dev automation moved this from Reviewer approved to Done Feb 24, 2020
@lock lock bot locked and limited conversation to collaborators Feb 25, 2020
@Jc2k Jc2k deleted the homekit_controller_aio branch February 25, 2020 13:20
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
No open projects
Dev
  
Done
Development

Successfully merging this pull request may close these issues.

homekit_controller: Unsolicited HAP events cause entities to do spurious things
3 participants