diff --git a/custom_components/eskom_loadshedding/eskom_interface.py b/custom_components/eskom_loadshedding/eskom_interface.py index f0bac8b..0cb19e7 100644 --- a/custom_components/eskom_loadshedding/eskom_interface.py +++ b/custom_components/eskom_loadshedding/eskom_interface.py @@ -4,6 +4,9 @@ from aiohttp.client_exceptions import ClientConnectorError, ServerDisconnectedError from aiohttp_retry import RetryClient +import logging + +_LOGGER = logging.getLogger(__name__) class eskom_interface: @@ -73,7 +76,6 @@ async def async_get_stage(self, attempts=50): async def async_get_data(self, coct_area): """Fetches data from the loadshedding API""" stage = await self.async_get_stage() - if stage > 0: load_shedding_active = isLoadSheddingNow(stage, coct_area)["status"] next_load_shedding = getNextTimeSlot(stage, coct_area)["date"] diff --git a/custom_components/eskom_loadshedding/loadshedding_schedule.py b/custom_components/eskom_loadshedding/loadshedding_schedule.py index b9408a7..c2764e8 100644 --- a/custom_components/eskom_loadshedding/loadshedding_schedule.py +++ b/custom_components/eskom_loadshedding/loadshedding_schedule.py @@ -81,21 +81,21 @@ def getNextTimeSlotInDay(stage, day, areaCode, fromHour=-1): if fromHour == -1 or slotHour > fromHour: return slot - return 0 + return None def getNextTimeSlot(stage, areaCode): result = {"slot": None, "day": None, "date": None} if stage < 1 or stage > HIGHEST_STAGE: - logging.warning("getNextTimeSlot() stage out of bounds") + logging.error("getNextTimeSlot() stage out of bounds") return result if areaCode < 1 or areaCode > NUM_AREA_CODES: - logging.warning("getNextTimeSlot() areaCode out of bounds") + logging.error("getNextTimeSlot() areaCode out of bounds") return result - d = datetime.datetime.now() + datetime.timedelta(hours=2) + d = datetime.datetime.now() # + datetime.timedelta(hours=2) fromHour = d.hour fromDay = d.day @@ -127,7 +127,7 @@ def getNextTimeSlot(stage, areaCode): def isLoadSheddingNow(stage, areaCode): - d = datetime.datetime.now() + datetime.timedelta(hours=2) + d = datetime.datetime.now() #+ datetime.timedelta(hours=2) hour = d.hour areaCodes = getAreaCodesByTimeValue( stage, d.day, datetime.time(hour=d.hour, minute=d.minute)