diff --git a/custom_components/dataplicity/__init__.py b/custom_components/dataplicity/__init__.py index bf3f716..5055061 100644 --- a/custom_components/dataplicity/__init__.py +++ b/custom_components/dataplicity/__init__.py @@ -43,17 +43,8 @@ def getargspec(*args): async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): - # fix: type object 'array.array' has no attribute 'tostring' - from dataplicity import iptool - - 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" - - from dataplicity.client import Client + # fix https://github.com/AlexxIT/Dataplicity/issues/29 + Client = await hass.async_add_executor_job(utils.import_client) hass.data[DOMAIN] = client = Client( serial=entry.data["serial"], auth_token=entry.data["auth"] @@ -73,9 +64,6 @@ async def hass_stop(event): async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry): - from dataplicity.client import Client - - client: Client = hass.data[DOMAIN] + client = hass.data[DOMAIN] client.exit() - return True diff --git a/custom_components/dataplicity/utils.py b/custom_components/dataplicity/utils.py index 0fbec87..862c71e 100644 --- a/custom_components/dataplicity/utils.py +++ b/custom_components/dataplicity/utils.py @@ -105,3 +105,19 @@ def install_package( return False return True + + +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")] + + # fix: module 'platform' has no attribute 'linux_distribution' + from dataplicity import device_meta + + device_meta.get_os_version = lambda: "Linux" + + from dataplicity.client import Client + + return Client