Skip to content

Commit

Permalink
🔖 v2.0.3 (#69)
Browse files Browse the repository at this point in the history
Signed-off-by: Ludy87 <[email protected]>
  • Loading branch information
Ludy87 authored Jun 20, 2023
1 parent 93303d0 commit c271aa2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
30 changes: 25 additions & 5 deletions custom_components/ecotrend_ista/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import datetime
import json
import logging
import os
from datetime import timedelta

from pyecotrend_ista.helper_object import CustomRaw
Expand All @@ -20,6 +21,28 @@
_LOGGER = logging.getLogger(__name__)


async def create_directory_file(hass: HomeAssistant, consum_raw: CustomRaw, support_code: str):
paths = [
hass.config.path("www"),
]

def mkdir() -> None:
for path in paths:
if not os.path.exists(path):
_LOGGER.debug("Creating directory: %s", path)
os.makedirs(path, exist_ok=True)

def make_file() -> None:
file_name = f"{DOMAIN}_{support_code}.json"
media_path = hass.config.path("www")
json_object = json.dumps(consum_raw.to_dict(), indent=4)
with open(f"{media_path}/{file_name}", mode="w", encoding="utf-8") as f_lie:
f_lie.write(json_object)

await hass.async_add_executor_job(mkdir)
await hass.async_add_executor_job(make_file)


class IstaDataUpdateCoordinator(DataUpdateCoordinator):
"""Coordinator for ista EcoTrend Version 2."""

Expand Down Expand Up @@ -58,11 +81,8 @@ async def _async_update_data(self):
consum_raw: CustomRaw = CustomRaw.from_dict(
await self.controller.consum_raw(select_year=[datetime.datetime.now().year])
)
file_name = f"{DOMAIN}.json"
media_path = self.hass.config.path("www")
json_object = json.dumps(consum_raw.to_dict(), indent=4)
with open(f"{media_path}/{file_name}", mode="w", encoding="utf-8") as f_lie:
f_lie.write(json_object)

await create_directory_file(self.hass, consum_raw, self.controller.getSupportCode())
self.data = consum_raw
self.async_set_updated_data(self.data)
return self.data
Expand Down
2 changes: 1 addition & 1 deletion custom_components/ecotrend_ista/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
"pyecotrend_ista==2.0.14",
"marshmallow-enum"
],
"version": "v2.0.2"
"version": "v2.0.3"
}

0 comments on commit c271aa2

Please sign in to comment.