diff --git a/custom_components/dataplicity/__init__.py b/custom_components/dataplicity/__init__.py index 5055061..70c3a5a 100644 --- a/custom_components/dataplicity/__init__.py +++ b/custom_components/dataplicity/__init__.py @@ -16,15 +16,17 @@ async def async_setup(hass: HomeAssistant, hass_config: dict): real_install = package.install_package def fake_install(pkg: str, *args, **kwargs): - if pkg == "dataplicity==0.4.40": + if pkg == "dataplicity==0.5.13": return utils.install_package(pkg, *args, **kwargs) return real_install(pkg, *args, **kwargs) try: package.install_package = fake_install - # latest dataplicity has bug with redirect_port - await async_process_requirements(hass, DOMAIN, ["dataplicity==0.4.40"]) + # 0.4.40 talks to the legacy api.dataplicity.com and is rejected with + # HTTP 403 for devices provisioned via the new device-gateway API; + # 0.5.13 works with the new provisioning. + await async_process_requirements(hass, DOMAIN, ["dataplicity==0.5.13"]) # fix Python 3.11 support if not hasattr(inspect, "getargspec"): diff --git a/custom_components/dataplicity/utils.py b/custom_components/dataplicity/utils.py index 0ed019d..ae2420a 100644 --- a/custom_components/dataplicity/utils.py +++ b/custom_components/dataplicity/utils.py @@ -144,14 +144,22 @@ def install_package( def import_client(): # fix: type object 'array.array' has no attribute 'tostring' - from dataplicity import iptool - - iptool.get_all_interfaces = lambda: [("lo", "127.0.0.1")] + # iptool/device_meta were dropped in newer dataplicity releases, so the + # monkey-patches are best-effort (skipped when the module is gone). + try: + from dataplicity import iptool + except ImportError: + pass + else: + iptool.get_all_interfaces = lambda: [("lo", "127.0.0.1")] # fix: module 'platform' has no attribute 'linux_distribution' - from dataplicity import device_meta - - device_meta.get_os_version = lambda: "Linux" + try: + from dataplicity import device_meta + except ImportError: + pass + else: + device_meta.get_os_version = lambda: "Linux" from dataplicity.client import Client