Skip to content

Commit

Permalink
get_version_from_manifest() is now async
Browse files Browse the repository at this point in the history
  • Loading branch information
gndean committed Jul 5, 2024
1 parent d9778a6 commit a3e6138
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
3 changes: 2 additions & 1 deletion custom_components/hypervolt_charger/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ async def async_setup_entry(hass: HomeAssistant, config: ConfigEntry) -> bool:

coordinator = await HypervoltUpdateCoordinator.create_hypervolt_coordinator(
hass,
get_version_from_manifest(),
await get_version_from_manifest(),
config.data.get(CONF_USERNAME),
config.data.get(CONF_PASSWORD),
config.data.get(CONF_CHARGER_ID),
Expand All @@ -77,6 +77,7 @@ async def async_setup_entry(hass: HomeAssistant, config: ConfigEntry) -> bool:

raise ConfigEntryNotReady from exc


async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
_LOGGER.debug("Async_unload_entry enter")
Expand Down
3 changes: 2 additions & 1 deletion custom_components/hypervolt_charger/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Config flow for Hypervolt EV charger integration."""

from __future__ import annotations

import logging
Expand Down Expand Up @@ -31,7 +32,7 @@ async def login_and_get_charger_ids(
) -> list[str]:
"""Log into the HV API and return a list of charger ID strings found within the account"""
api = HypervoltApiClient(
get_version_from_manifest(), data[CONF_USERNAME], data[CONF_PASSWORD]
await get_version_from_manifest(), data[CONF_USERNAME], data[CONF_PASSWORD]
)
async with aiohttp.ClientSession() as session:
await api.login(session)
Expand Down
10 changes: 3 additions & 7 deletions custom_components/hypervolt_charger/manifest.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
{
"domain": "hypervolt_charger",
"name": "Hypervolt Charger",
"codeowners": [
"@gndean"
],
"codeowners": ["@gndean"],
"config_flow": true,
"documentation": "https://github.com/gndean/home-assistant-hypervolt-charger",
"integration_type": "device",
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/gndean/home-assistant-hypervolt-charger/issues",
"requirements": [
"websockets==11.0.3"
],
"requirements": ["websockets==11.0.3", "aiofiles==24.1.0"],
"version": "2.3.0"
}
}
8 changes: 5 additions & 3 deletions custom_components/hypervolt_charger/utils.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import logging
import json
import os
import aiofiles

from .hypervolt_device_state import HypervoltDayOfWeek

_LOGGER = logging.getLogger(__name__)


def get_version_from_manifest() -> str:
async def get_version_from_manifest() -> str:
"""Attempt to read the manifest.json file and extract the version number. Returns 0.0.0 on failure"""
try:
manifest_filename = os.path.join(os.path.dirname(__file__), "manifest.json")
_LOGGER.debug(
f"get_version_from_manifest loading manifest: {manifest_filename}"
)
with open(manifest_filename, encoding="utf-8") as manifest_file:
manifest = json.load(manifest_file)
async with aiofiles.open(manifest_filename, encoding="utf-8") as manifest_file:
contents = await manifest_file.read()
manifest = json.loads(contents)
version = manifest["version"]
_LOGGER.debug(f"get_version_from_manifest returning version: {version}")

Expand Down

0 comments on commit a3e6138

Please sign in to comment.