Skip to content

Commit

Permalink
v1.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
lunDreame authored Dec 1, 2024
1 parent 42273c8 commit a0aa970
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
14 changes: 10 additions & 4 deletions custom_components/apti/apti.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion custom_components/apti/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from homeassistant.const import Platform

DOMAIN = "apti"
VERSION = "1.0.6"
VERSION = "1.0.7"

PLATFORMS: list[Platform] = [
Platform.SENSOR
Expand Down
2 changes: 1 addition & 1 deletion custom_components/apti/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
"aiofiles==24.1.0",
"beautifulsoup4==4.12.3"
],
"version": "1.0.6"
"version": "1.0.7"
}
12 changes: 6 additions & 6 deletions custom_components/apti/until.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit a0aa970

Please sign in to comment.