Skip to content

Commit

Permalink
Merge pull request #246 from mdeweerd/dev
Browse files Browse the repository at this point in the history
Fix Async initialisation issues by making getVersion async
  • Loading branch information
mdeweerd authored Aug 7, 2024
2 parents 2fe9507 + 6994333 commit 639e3ff
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
6 changes: 3 additions & 3 deletions custom_components/zha_toolkit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,12 +657,12 @@ async def async_setup(hass, config):
return True

LOGGER.debug("Setup services from async_setup")
await hass.async_add_executor_job(register_services, hass)
register_services(hass)

return True


def register_services(hass): # noqa: C901
async def register_services(hass): # noqa: C901
global LOADED_VERSION # pylint: disable=global-statement
hass_ref = hass

Expand Down Expand Up @@ -865,7 +865,7 @@ async def toolkit_service(service):
schema=value,
)

LOADED_VERSION = u.getVersion()
LOADED_VERSION = await u.getVersion()


async def command_handler_default(
Expand Down
2 changes: 1 addition & 1 deletion custom_components/zha_toolkit/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
"documentation": "https://github.com/mdeweerd/zha-toolkit",
"iot_class": "local_polling",
"issue_tracker": "https://github.com/mdeweerd/zha-toolkit/issues",
"requirements": ["pytz"],
"requirements": ["aiofiles>=0.4.0", "pytz>=>2016.10"],
"version": "1.0.0"
}
9 changes: 5 additions & 4 deletions custom_components/zha_toolkit/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import typing
from enum import Enum

import aiofiles
import zigpy

try:
Expand Down Expand Up @@ -59,7 +60,7 @@ def getZigpyVersion() -> str:
return ZIGPY_VERSION


def getVersion() -> str:
async def getVersion() -> str:
# pylint: disable=global-variable-undefined,used-before-assignment
# pylint: disable=global-statement
global VERSION_TIME
Expand Down Expand Up @@ -90,9 +91,9 @@ def getVersion() -> str:
# No version, or file change -> get version again
LOGGER.debug(f"Read version from {fname} {ftime}<>{VERSION_TIME}")

with open(fname, encoding="utf_8") as infile:
VERSION_TIME = ftime
MANIFEST = json.load(infile)
async with aiofiles.open(fname, mode="r", encoding="utf_8") as infile:
json_raw = await infile.read()
MANIFEST = json.loads(json_raw)

if MANIFEST is not None:
if "version" in MANIFEST.keys():
Expand Down

0 comments on commit 639e3ff

Please sign in to comment.