Skip to content

Commit

Permalink
Event fetch and process loop should never return
Browse files Browse the repository at this point in the history
  • Loading branch information
mnordseth committed Jun 25, 2024
1 parent a631ac0 commit 8a38af7
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions custom_components/enet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

from datetime import timedelta
import logging
from typing import Any, Dict
from typing import Any, Dict, NoReturn

import async_timeout

from custom_components.enet.enet_data.enums import ChannelTypeFunctionName
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator

from .aioenet import EnetClient, ActuatorChannel, SensorChannel
from .const import DOMAIN, ATTR_ENET_EVENT, EVENT_TYPE_INITIAL_PRESS, EVENT_TYPE_SHORT_RELEASE
Expand Down Expand Up @@ -103,11 +103,16 @@ async def setup_event_listeners(self) -> None:
self.function_uid_map.update(func_uids)
await device.register_events()

async def _async_update_data(self) -> None:
"""Fetch data from API endpoint.
async def _async_update_data(self) -> NoReturn:
"""Fetch events from Enet server
This endpoint blocks for 30s if no events are available
or returns immediatly when events are there. Loop forever
to get next events.
This function and event processing should be moved to aioenet
at some point.
This is the place to pre-process the data to lookup tables
so entities can quickly look up their data.
"""
# _LOGGER.debug("_async_update_data()")
while True:
Expand All @@ -117,7 +122,6 @@ async def _async_update_data(self) -> None:
self.handle_event(event)
except Exception as e:
_LOGGER.exception("Failed to handle event: %s (%s)", event, e)
raise UpdateFailed from e

def handle_event(self, event_data: Dict[str, Any]) -> None:
"""Handle events from Enet Server. Either update value of actuator or
Expand Down

0 comments on commit 8a38af7

Please sign in to comment.