Skip to content

Commit

Permalink
Add timeout to MQTT events so we do not wait forever for them to reso…
Browse files Browse the repository at this point in the history
…lve (#357)

* Add timeout to MQTT events so we do not wait forever for them to resolve
  • Loading branch information
WebSpider authored Feb 17, 2025
1 parent 1d9bff4 commit 91bfebf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions myskoda/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
MQTT_BROKER_PORT = 8883


MQTT_OPERATION_TIMEOUT = 10 * 60 # 10 minutes
MQTT_OPERATION_TOPICS = [
"air-conditioning/set-air-conditioning-at-unlock",
"air-conditioning/set-air-conditioning-seats-heating",
Expand Down
2 changes: 2 additions & 0 deletions myskoda/models/vehicle_ignition_status.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""MySkoda Vehicle ignition statuses."""

from enum import StrEnum


Expand Down
9 changes: 7 additions & 2 deletions myskoda/myskoda.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""

import logging
from asyncio import gather
from asyncio import gather, timeout
from collections.abc import Awaitable, Callable
from datetime import UTC, datetime
from ssl import SSLContext
Expand All @@ -26,6 +26,7 @@

from .__version__ import __version__ as version
from .auth.authorization import Authorization
from .const import MQTT_OPERATION_TIMEOUT
from .event import Event
from .models.air_conditioning import (
AirConditioning,
Expand Down Expand Up @@ -123,7 +124,11 @@ async def enable_mqtt(self) -> None:
async def _wait_for_operation(self, operation: OperationName) -> None:
if self.mqtt is None:
return
await self.mqtt.wait_for_operation(operation)
try:
async with timeout(MQTT_OPERATION_TIMEOUT):
await self.mqtt.wait_for_operation(operation)
except TimeoutError:
_LOGGER.warning("Timeout occurred while waiting for %s. Aborted.", operation)

async def connect(self, email: str, password: str) -> None:
"""Authenticate on the rest api and connect to the MQTT broker."""
Expand Down

0 comments on commit 91bfebf

Please sign in to comment.