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

HomeKit support #501

Open
glyph opened this issue Oct 15, 2022 · 4 comments
Open

HomeKit support #501

glyph opened this issue Oct 15, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@glyph
Copy link

glyph commented Oct 15, 2022

Is your feature request related to a problem? Please describe.
Nope, just hoping to use the framework.

Describe the solution you'd like
Would it be possible to just get from HomeKit import HMHomeManager to work?

Describe alternatives you've considered
The various HomeKit libraries in Python seem to be for cutting Apple out of the loop entirely (implementing a controller on Linux or emulating an accessory), so I don't think there's something that does this.

@glyph glyph added the enhancement New feature or request label Oct 15, 2022
@ronaldoussoren
Copy link
Owner

A possible issue is that HomeKit is a catalyst framework. That said, AFAIK it is possible to mix usage of catalyst in cocoa in applications.

@ronaldoussoren
Copy link
Owner

The following has limited success:

import objc
objc.loadBundle('HomeKit', globals(), '/System/Library/PrivateFrameworks/HomeKit.framework')
manager = HMHomeManager.new()
print(manager.homes())

This works, but prints an empty set of homes even though I see a "home" in Home.app.

Loading /System/iOSSupport/System/Library/Frameworks/HomeKit.framework (which Home.app uses) doesn't work for me, I get a generic "Bundle could not be loaded" error.

Using NSBundle.bundleWithPath_ to load the latter framework gives a clearer error message:

 2022-10-15 21:56:36.971 Python[91353:14405081] Error loading /System/iOSSupport/System/Library/Frameworks/HomeKit.framework/HomeKit:  dlopen(/System/iOSSupport/System/Library/Frameworks/HomeKit.framework/HomeKit, 0x0109): tried: '/System/iOSSupport/System/Library/Frameworks/HomeKit.framework/Versions/A/HomeKit' (wrong platform to load into process), '/System/Library/Frameworks/HomeKit.framework/Versions/A/HomeKit' (no such file)

Some very short research seems to indicate that it is possible to load an AppKit extension into a Catalyst app, but that it is at best a lot harder to do it the other way around (https://indiedevmonday.com/issue-18, https://github.com/steventroughtonsmith/airqualitymonitor, https://twitter.com/stroughtonsmith/status/1313474865467453441).

More importantly: https://developer.apple.com/forums/thread/692356, which contains a definitive statement from an Apple engineer that says loading Catalyst frameworks into an AppKit app is not possible.

That sadly means that using the HomeKit framework requires either using the private HomeKit framework (assuming that can be made to work), or creating a Catalyst version of Python + PyObjC. That's something I'd like to look into, but I have no idea when.

@ronaldoussoren
Copy link
Owner

A Catalyst version of Python would be an interesting proposition, but is something that will require coordinating with at least the PyPA and PyPI maintainers, as well as with CPython to upstream relevant patches (including CI support).

A major disadvantage of a Catalyst Python is that it likely cannot use existing binary wheels.

@ronaldoussoren
Copy link
Owner

I've added an issue about a Catalyst build to the CPython project: python/cpython#98297

To be honest I expect little progress on that until I get around to work on this myself (assuming I do get around to that).

@ronaldoussoren ronaldoussoren added this to the Catalyst Support milestone Oct 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants