Skip to content

Fix provisioning for modern Dataplicity API, Python 3.14, reverse-proxy hack#51

Open
alex-mextner wants to merge 2 commits into
AlexxIT:masterfrom
alex-mextner:fix/dataplicity-modern-api
Open

Fix provisioning for modern Dataplicity API, Python 3.14, reverse-proxy hack#51
alex-mextner wants to merge 2 commits into
AlexxIT:masterfrom
alex-mextner:fix/dataplicity-modern-api

Conversation

@alex-mextner

@alex-mextner alex-mextner commented May 18, 2026

Copy link
Copy Markdown

Summary

This PR supersedes #50 by fixing the Dataplicity integration for modern infrastructure without breaking the existing silent reverse-proxy hack.

Background

PR #50 (petrouv) correctly updated the provisioning logic for the new Dataplicity API (.sh URLs, device_class_hash, new response fields). However, it introduced several regressions that break the integration on current Home Assistant / Python 3.14:

  1. Broken fix_middlewareFix provisioning for new Dataplicity device-gateway API #50 replaced the working closure-cell hack with a co_freevars assignment that crashes on Python 3.14 (tuple is immutable). This silently disables the reverse-proxy auto-configuration, causing the wormhole to return 400 Bad Request unless the user manually edits configuration.yaml.
  2. Missing utils.install_packageFix provisioning for new Dataplicity device-gateway API #50 deleted the install_package helper but __init__.py still calls it inside fake_install, leading to an unlogged AttributeError / recursion crash during setup.
  3. No exception logging — the bare except: in async_setup swallows all errors, making failures invisible.
  4. Missing hass.data cleanupasync_unload_entry kept a reference to the dead client.

What this PR does differently

  • Provisioning: same modern API fix as Fix provisioning for new Dataplicity device-gateway API #50 (new endpoint, .sh support, device_class_hash, hash_id/device_secret fallbacks, serial:auth recovery mode).
  • fix_middleware: restores the original cell-contents hack that worked for years, plus getattr(f, "__name__", None) safety. No co_freevars mutation.
  • install_package: kept and documented with --no-deps reasoning.
  • Error handling: async_setup and async_setup_entry now log full tracebacks.
  • Cleanup: async_unload_entry pops hass.data[DOMAIN].
  • Agent: bumped to dataplicity==0.5.13 (verified end-to-end; the redirect_port bug that pinned 0.4.40 is gone).

Tested on

  • Home Assistant Container 2026.5.2
  • Python 3.14
  • Dataplicity agent 0.5.13

Closes

- Update provisioning to new dataplicity device-gateway API
  - Endpoint: app-api.dataplicity.com/device-gateway/provision/
  - Install URL: .sh instead of .py
  - Requires device_class_hash parsed from .sh wrapper
  - Response fields renamed: hash_id / device_secret (with fallbacks)
- Add recovery input mode (serial:auth) for already-provisioned devices
- Fix config_flow regex to accept .sh and .py URLs
- Fix Python 3.14 compatibility:
  - Remove broken co_freevars assignment (immutable tuple)
  - Restore original forwarded_middleware cell-contents hack
  - Add logging to async_setup exception handler
  - Clean up hass.data in async_unload_entry
- Bump dataplicity agent to 0.5.13 (verified working with wormhole)
- Bump integration version to 1.3.0
- Update translations (en/ru) for .sh URL and recovery mode

Closes AlexxIT#49, closes AlexxIT#47, closes AlexxIT#48
- Update provisioning to new dataplicity device-gateway API
  - Endpoint: app-api.dataplicity.com/device-gateway/provision/
  - Install URL: .sh instead of .py
  - Requires device_class_hash parsed from .sh wrapper
  - Response fields renamed: hash_id / device_secret (with fallbacks)
- Add recovery input mode (serial:auth) for already-provisioned devices
- Fix config_flow regex to accept .sh and .py URLs
- Fix Python 3.14 compatibility:
  - Remove broken co_freevars assignment (immutable tuple)
  - Restore original forwarded_middleware cell-contents hack
  - Add logging to async_setup exception handler
  - Clean up hass.data in async_unload_entry
- Bump dataplicity agent to 0.5.13 (verified working with wormhole)
- Bump integration version to 1.3.0
- Update translations (en/ru) for .sh URL and recovery mode
- Restore deleted inline comments (posix_spawn, closure hack, monkey-patches)

Closes AlexxIT#49, closes AlexxIT#47, closes AlexxIT#48
@alex-mextner alex-mextner force-pushed the fix/dataplicity-modern-api branch from e55895f to 982b5a6 Compare May 18, 2026 13:00
@AlexxIT

AlexxIT commented May 20, 2026

Copy link
Copy Markdown
Owner

I don't really understand your changes. The changes in #50 are minimal. And they don't affect the hack at all.
And your changes touched a lot of code, and it’s not clear why.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants