Skip to content

Commit

Permalink
Config flow blocking calls fix (#58)
Browse files Browse the repository at this point in the history
* fix blocking calls on config flow
  • Loading branch information
LoSk-p authored Jun 14, 2024
1 parent 3c64b6b commit 0723400
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
14 changes: 7 additions & 7 deletions custom_components/robonomics/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def _is_ipfs_local_connected() -> bool:
return False


def _has_sub_owner_subscription(sub_owner_address: str) -> bool:
async def _has_sub_owner_subscription(hass: HomeAssistant, sub_owner_address: str) -> bool:
"""Check if controller account is in subscription devices
:param sub_owner_address: Subscription owner address
Expand All @@ -87,14 +87,14 @@ def _has_sub_owner_subscription(sub_owner_address: str) -> bool:
"""

rws = RWS(Account())
res = rws.get_ledger(sub_owner_address)
res = await hass.async_add_executor_job(rws.get_ledger, sub_owner_address)
if res is None:
return False
else:
return True


def _is_sub_admin_in_subscription(sub_admin_seed: str, sub_owner_address: str) -> bool:
async def _is_sub_admin_in_subscription(hass: HomeAssistant, sub_admin_seed: str, sub_owner_address: str) -> bool:
"""Check if controller account is in subscription devices
:param sub_admin_seed: Controller's seed
Expand All @@ -104,7 +104,7 @@ def _is_sub_admin_in_subscription(sub_admin_seed: str, sub_owner_address: str) -
"""

rws = RWS(Account(sub_admin_seed, crypto_type=KeypairType.ED25519))
res = rws.is_in_sub(sub_owner_address)
res = await hass.async_add_executor_job(rws.is_in_sub, sub_owner_address)
return res


Expand Down Expand Up @@ -144,10 +144,10 @@ async def _validate_input(hass: HomeAssistant, data: dict[str, Any]) -> dict[str
raise InvalidSubAdminSeed
if not _is_valid_sub_owner_address(data[CONF_SUB_OWNER_ADDRESS]):
raise InvalidSubOwnerAddress
if not _has_sub_owner_subscription(data[CONF_SUB_OWNER_ADDRESS]):
if not await _has_sub_owner_subscription(hass, data[CONF_SUB_OWNER_ADDRESS]):
raise NoSubscription
if not _is_sub_admin_in_subscription(
data[CONF_ADMIN_SEED], data[CONF_SUB_OWNER_ADDRESS]
if not await _is_sub_admin_in_subscription(
hass, data[CONF_ADMIN_SEED], data[CONF_SUB_OWNER_ADDRESS]
):
raise ControllerNotInDevices
if not await _is_ipfs_local_connected():
Expand Down
2 changes: 1 addition & 1 deletion custom_components/robonomics/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"iot_class": "cloud_push",
"issue_tracker": "https://github.com/airalab/homeassistant-robonomics-integration/issues",
"requirements": ["pycryptodome==3.15.0", "wheel", "IPFS-Toolkit==0.4.0", "robonomics-interface==1.6.2", "pinatapy-vourhey==0.1.9", "aenum==3.1.11", "ipfs-api==0.2.3", "crust-interface-patara==0.1.1", "tenacity==8.2.2", "py-ws-libp2p-proxy==0.1.4"],
"version": "1.8.5"
"version": "1.8.6"
}
5 changes: 3 additions & 2 deletions custom_components/robonomics/robonomics.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,8 +693,9 @@ async def _monitore_subscription(self) -> None:
if DOMAIN not in self.hass.data:
return
await asyncio.sleep(15)
self._change_current_wss()
await self.resubscribe()
if DOMAIN in self.hass.data:
self._change_current_wss()
await self.resubscribe()

async def subscribe(self) -> None:
"""Subscribe to NewDevices, NewRecord, TopicChanged and NewLaunch events"""
Expand Down

0 comments on commit 0723400

Please sign in to comment.