Skip to content

Commit

Permalink
Fix "Detected blocking call" #29
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Dec 6, 2024
1 parent 164c8d6 commit eb457d7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
18 changes: 3 additions & 15 deletions custom_components/dataplicity/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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
16 changes: 16 additions & 0 deletions custom_components/dataplicity/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit eb457d7

Please sign in to comment.