From a0aa970fba04291455b27b87c239f208f82e0f9a Mon Sep 17 00:00:00 2001 From: lunDreame <87955512+lunDreame@users.noreply.github.com> Date: Sun, 1 Dec 2024 20:56:39 +0900 Subject: [PATCH] v1.0.7 --- custom_components/apti/apti.py | 14 ++++++++++---- custom_components/apti/const.py | 2 +- custom_components/apti/manifest.json | 2 +- custom_components/apti/until.py | 12 ++++++------ 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/custom_components/apti/apti.py b/custom_components/apti/apti.py index 92d14c9..7901597 100644 --- a/custom_components/apti/apti.py +++ b/custom_components/apti/apti.py @@ -11,7 +11,7 @@ from homeassistant.config_entries import ConfigEntry from .helper import get_text_or_log, is_phone_number -from .until import format_date_two_months_ago, get_target_month +from .until import format_date_target_months_ago, get_target_month from .const import LOGGER @@ -75,6 +75,7 @@ def __init__( self.se_token: str | None = None self.apti_codesave: str | None = None self.dong_ho: str | None = None + self.target_month: int = 2 self.data = APTiData() async def login(self): @@ -178,10 +179,10 @@ async def get_maint_fee_item(self): "manageDataTot": "22", "code": self.apti_codesave, "dongho": self.dong_ho, - "billym": format_date_two_months_ago(), + "billym": format_date_target_months_ago(target=self.target_month), "fix_code": self.apti_codesave, } - + try: async with self.session.post(url, headers=headers, data=data, timeout=5) as response: if response.status != 200: @@ -228,8 +229,13 @@ async def get_maint_fee_payment(self): raw_data = await response.content.read() resp = raw_data.decode("EUC-KR") soup = BeautifulSoup(resp, "html.parser") + + target_month = get_target_month(target=self.target_month) + monthly_cost_element = soup.find("dt", text=f"{target_month}월분 부과 금액") - target_month = get_target_month() + if monthly_cost_element is None: + self.target_month = 1 + target_month = get_target_month(target=self.target_month) cost_info = { "납부 마감일": get_text_or_log( diff --git a/custom_components/apti/const.py b/custom_components/apti/const.py index 5989aea..9144411 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.6" +VERSION = "1.0.7" PLATFORMS: list[Platform] = [ Platform.SENSOR diff --git a/custom_components/apti/manifest.json b/custom_components/apti/manifest.json index 8e0b5eb..0c5b9b4 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.6" + "version": "1.0.7" } \ No newline at end of file diff --git a/custom_components/apti/until.py b/custom_components/apti/until.py index dc80a84..60bdce3 100644 --- a/custom_components/apti/until.py +++ b/custom_components/apti/until.py @@ -3,16 +3,16 @@ from datetime import datetime from dateutil.relativedelta import relativedelta -def format_date_two_months_ago() -> str: - """After calculating the date two months ago, format it in the format 'YYYYMM'.""" +def format_date_target_months_ago(target: int) -> str: + """After calculating the date target months ago, format it in the format 'YYYYMM'.""" current_date = datetime.now() - previous_date = current_date - relativedelta(months=1) + previous_date = current_date - relativedelta(months=target) formatted_date = previous_date.strftime('%Y%m') return formatted_date -def get_target_month() -> str: - """Returns months before the current month to 2 months in numeric form.""" +def get_target_month(target: int) -> str: + """Returns months before the current month to target months in numeric form.""" current_date = datetime.now() - target_month = (current_date.month - 1) % 12 or 12 + target_month = (current_date.month - target) % 12 or 12 return str(target_month)