diff --git a/aioairzone/common.py b/aioairzone/common.py index ca6581a..5069273 100644 --- a/aioairzone/common.py +++ b/aioairzone/common.py @@ -3,6 +3,7 @@ from __future__ import annotations from enum import Enum, IntEnum +import json from typing import Any @@ -234,3 +235,10 @@ def __str__(self) -> str: def get_system_zone_id(system_id: int, zone_id: int) -> str: """Combine system and zone IDs.""" return f"{system_id}:{zone_id}" + + +def json_dumps(data: Any) -> Any: + """Convert data to JSON.""" + if data is not None: + return json.dumps(data) + return None diff --git a/aioairzone/localapi.py b/aioairzone/localapi.py index 9b79036..2f7f9b2 100644 --- a/aioairzone/localapi.py +++ b/aioairzone/localapi.py @@ -6,7 +6,6 @@ from asyncio import Lock, Semaphore from dataclasses import dataclass from enum import IntEnum -import json from json import JSONDecodeError import logging from typing import Any, cast @@ -14,7 +13,7 @@ from aiohttp import ClientConnectorError, ClientSession, ClientTimeout from aiohttp.client_reqrep import ClientResponse -from .common import OperationMode, get_system_zone_id +from .common import OperationMode, get_system_zone_id, json_dumps from .const import ( API_ACS_MAX_TEMP, API_ACS_MIN_TEMP, @@ -183,7 +182,7 @@ async def http_request( resp: ClientResponse = await self.aiohttp_session.request( method, f"http://{self.options.host}:{self.options.port}/{path}", - data=json.dumps(data), + data=json_dumps(data), headers={"Content-Type": "text/json"}, timeout=self._api_timeout, )