Skip to content

Commit

Permalink
common: add json_dumps helper function
Browse files Browse the repository at this point in the history
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
  • Loading branch information
Noltari committed Sep 6, 2024
1 parent fefb62e commit 3a8f482
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 8 additions & 0 deletions aioairzone/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

from enum import Enum, IntEnum
import json
from typing import Any


Expand Down Expand Up @@ -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
5 changes: 2 additions & 3 deletions aioairzone/localapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
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

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,
Expand Down Expand Up @@ -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,
)
Expand Down

0 comments on commit 3a8f482

Please sign in to comment.