From 730f07f5d52b65afa04e0bca2454ca0a7998f2a1 Mon Sep 17 00:00:00 2001 From: lunDreame <87955512+lunDreame@users.noreply.github.com> Date: Mon, 28 Oct 2024 19:56:09 +0900 Subject: [PATCH] =?UTF-8?q?=EC=95=84=EC=9D=B4=EC=BD=98=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- custom_components/apti/__init__.py | 2 +- custom_components/apti/apti.py | 7 ++++--- custom_components/apti/const.py | 2 +- custom_components/apti/coordinator.py | 10 +++++----- custom_components/apti/helper.py | 1 + custom_components/apti/icons/icon.json | 4 +++- custom_components/apti/manifest.json | 2 +- 7 files changed, 16 insertions(+), 12 deletions(-) diff --git a/custom_components/apti/__init__.py b/custom_components/apti/__init__.py index 07bac01..2b1ba84 100644 --- a/custom_components/apti/__init__.py +++ b/custom_components/apti/__init__.py @@ -14,7 +14,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up the APT.i integration.""" coordinator = APTiDataUpdateCoordinator(hass, entry) - #await coordinator.api.login() + await coordinator.api.login() await coordinator.async_config_entry_first_refresh() async_track_time_interval( diff --git a/custom_components/apti/apti.py b/custom_components/apti/apti.py index b5d6d50..92d14c9 100644 --- a/custom_components/apti/apti.py +++ b/custom_components/apti/apti.py @@ -1,3 +1,4 @@ +import asyncio import aiohttp import re @@ -47,7 +48,7 @@ def remove_callback(self, callback: Callable): """Remove a callback""" self.callbacks.discard(callback) - async def update_callback(self): + def update_callback(self): """Updates registered callbacks.""" for callback in self.callbacks: if callable(callback): @@ -348,13 +349,13 @@ async def get_energy_type(self): try: energy_info["사용량"] = usage_down.text.split("(")[1].split(")")[0].strip() except IndexError: - LOGGER.debug(f"Could not parse usage for {energy_type}") + LOGGER.warning(f"Could not parse usage for {energy_type}") if usage_up := box.find("p", class_="eneUpTxt"): try: energy_info["평균 사용량"] = usage_up.text.split("(")[1].split(")")[0].strip() except IndexError: - LOGGER.debug(f"Could not parse average usage for {energy_type}") + LOGGER.warning(f"Could not parse average usage for {energy_type}") if details := box.find("div", class_="tbl_bill"): for row in details.find_all("tr"): diff --git a/custom_components/apti/const.py b/custom_components/apti/const.py index 4ac4eb4..5989aea 100644 --- a/custom_components/apti/const.py +++ b/custom_components/apti/const.py @@ -8,7 +8,7 @@ from homeassistant.const import Platform DOMAIN = "apti" -VERSION = "1.0.5" +VERSION = "1.0.6" PLATFORMS: list[Platform] = [ Platform.SENSOR diff --git a/custom_components/apti/coordinator.py b/custom_components/apti/coordinator.py index 4660180..e064e84 100644 --- a/custom_components/apti/coordinator.py +++ b/custom_components/apti/coordinator.py @@ -30,16 +30,16 @@ def __init__(self, hass: HomeAssistant, entry: ConfigEntry) -> None: async def _update_maint_energy(self, _=None): """Fetch maintenance/energy data from the API.""" - #if isinstance(_, datetime): - # LOGGER.info("Update maintenance/energy data.") - await self.api.login() + if isinstance(_, datetime): + LOGGER.info("Update maintenance/energy data.") + await self.api.login() await asyncio.gather( - self.api.get_maint_fee_item(), self.api.get_maint_fee_payment(), + self.api.get_maint_fee_item(), self.api.get_energy_category(), self.api.get_energy_type() ) - await self.api.data.update_callback() + self.api.data.update_callback() def data_to_entities(self) -> dict[str, dict | list]: """Convert APT.i data to entities.""" diff --git a/custom_components/apti/helper.py b/custom_components/apti/helper.py index d2d3679..d6f7113 100644 --- a/custom_components/apti/helper.py +++ b/custom_components/apti/helper.py @@ -51,6 +51,7 @@ async def get_icon( data = json.loads(content) if category in data: + key = re.sub(r"\d+동", "", key).strip() icon = data[category].get(key, None) if icon is None: LOGGER.warning(f"Icon for key '{key}' in category '{category}' not found.") diff --git a/custom_components/apti/icons/icon.json b/custom_components/apti/icons/icon.json index 1a22aaa..0422309 100644 --- a/custom_components/apti/icons/icon.json +++ b/custom_components/apti/icons/icon.json @@ -29,7 +29,9 @@ "선관위운영비": "mdi:ballot-outline", "입대의운영비": "mdi:account-group-outline", "장기수선비": "mdi:tools", - "공동난방비": "mdi:fire" + "공동난방비": "mdi:fire", + "소방유지대행료": "mdi:fire-truck", + "특별수선충당금": "mdi:cash-plus" }, "energy_detail": { "수도": "mdi:water", diff --git a/custom_components/apti/manifest.json b/custom_components/apti/manifest.json index 40b06c4..8e0b5eb 100644 --- a/custom_components/apti/manifest.json +++ b/custom_components/apti/manifest.json @@ -12,5 +12,5 @@ "aiofiles==24.1.0", "beautifulsoup4==4.12.3" ], - "version": "1.0.5" + "version": "1.0.6" } \ No newline at end of file