Skip to content

Commit

Permalink
Make getVersion async
Browse files Browse the repository at this point in the history
  • Loading branch information
mdeweerd committed Aug 7, 2024
1 parent ed25e70 commit 6994333
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 @@ -652,12 +652,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 @@ -860,7 +860,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
from homeassistant.components.zha.core.gateway import ZHAGateway
from homeassistant.util import dt as dt_util
Expand Down Expand Up @@ -54,7 +55,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 @@ -85,9 +86,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 6994333

Please sign in to comment.