Skip to content

Commit

Permalink
fixed json formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
johnneerdael committed Jan 10, 2025
1 parent bd85e61 commit 506fb07
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 11 deletions.
2 changes: 1 addition & 1 deletion custom_components/hyperhdr_control/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
manufacturer="HyperHDR",
name=f"HyperHDR ({entry.data[CONF_HOST]})",
model="HyperHDR LED Controller",
sw_version="1.3.0",
sw_version="1.3.1",
)

await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
Expand Down
9 changes: 7 additions & 2 deletions custom_components/hyperhdr_control/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def device_info(self) -> DeviceInfo:
manufacturer="HyperHDR",
name=f"HyperHDR ({self._host})",
model="HyperHDR LED Controller",
sw_version="1.3.0",
sw_version="1.3.1",
)

async def async_press(self) -> None:
Expand All @@ -71,9 +71,14 @@ async def async_press(self) -> None:
try:
async with aiohttp.ClientSession() as session:
url = f"http://{self._host}:{self._port}/json-rpc"
params = {"request": json.dumps(request_data, separators=(',', ':'))}
_LOGGER.debug("Sending request to %s with params: %s", url, params)

async with async_timeout.timeout(10):
async with session.get(url, params={"request": json.dumps(request_data)}) as response:
async with session.get(url, params=params) as response:
if response.status != 200:
_LOGGER.error("Failed to activate effect: %s", response.status)
response_text = await response.text()
_LOGGER.error("Response: %s", response_text)
except (aiohttp.ClientError, TimeoutError) as error:
_LOGGER.error("Error activating effect: %s", error)
2 changes: 1 addition & 1 deletion custom_components/hyperhdr_control/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"codeowners": [],
"requirements": ["aiohttp", "zeroconf"],
"iot_class": "local_polling",
"version": "1.3.0",
"version": "1.3.1",
"config_flow": true,
"zeroconf": ["_hyperhdr-http._tcp.local."],
"logo": "https://raw.githubusercontent.com/johnneerdael/hyperhdr_control/main/hyperhdr_control-logo.png"
Expand Down
13 changes: 10 additions & 3 deletions custom_components/hyperhdr_control/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def device_info(self) -> DeviceInfo:
manufacturer="HyperHDR",
name=f"HyperHDR ({self._host})",
model="HyperHDR LED Controller",
sw_version="1.3.0",
sw_version="1.3.1",
)

async def _delayed_update(self) -> None:
Expand Down Expand Up @@ -106,10 +106,15 @@ async def _set_brightness(self, value: float) -> None:
try:
async with aiohttp.ClientSession() as session:
url = f"http://{self._host}:{self._port}/json-rpc"
params = {"request": json.dumps(request_data, separators=(',', ':'))}
_LOGGER.debug("Sending brightness request to %s with params: %s", url, params)

async with async_timeout.timeout(10):
async with session.get(url, params={"request": json.dumps(request_data)}) as response:
async with session.get(url, params=params) as response:
if response.status != 200:
_LOGGER.error("Failed to set brightness: %s", response.status)
response_text = await response.text()
_LOGGER.error("Response: %s", response_text)
except (aiohttp.ClientError, TimeoutError) as error:
_LOGGER.error("Error setting brightness: %s", error)

Expand All @@ -122,8 +127,10 @@ async def async_update(self) -> None:
try:
async with aiohttp.ClientSession() as session:
url = f"http://{self._host}:{self._port}/json-rpc"
params = {"request": json.dumps(request_data, separators=(',', ':'))}

async with async_timeout.timeout(10):
async with session.get(url, params={"request": json.dumps(request_data)}) as response:
async with session.get(url, params=params) as response:
if response.status == 200:
data = await response.json()
adjustment = data.get("info", {}).get("adjustment", {})
Expand Down
13 changes: 9 additions & 4 deletions custom_components/hyperhdr_control/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import json
import logging
from typing import Any
from urllib.parse import urlencode

import aiohttp
import async_timeout
Expand Down Expand Up @@ -57,7 +58,7 @@ def device_info(self) -> DeviceInfo:
manufacturer="HyperHDR",
name=f"HyperHDR ({self._host})",
model="HyperHDR LED Controller",
sw_version="1.3.0",
sw_version="1.3.1",
)

async def async_turn_on(self, **kwargs: Any) -> None:
Expand All @@ -81,9 +82,11 @@ async def _set_state(self, state: bool) -> None:
try:
async with aiohttp.ClientSession() as session:
url = f"http://{self._host}:{self._port}/json-rpc"
_LOGGER.debug("Sending request to %s: %s", url, json.dumps(request_data))
params = {"request": json.dumps(request_data, separators=(',', ':'))}
_LOGGER.debug("Sending request to %s with params: %s", url, params)

async with async_timeout.timeout(10):
async with session.get(url, params={"request": json.dumps(request_data)}) as response:
async with session.get(url, params=params) as response:
if response.status == 200:
self._attr_is_on = state
_LOGGER.debug("Successfully set %s state to %s", self._component, state)
Expand All @@ -103,8 +106,10 @@ async def async_update(self) -> None:
try:
async with aiohttp.ClientSession() as session:
url = f"http://{self._host}:{self._port}/json-rpc"
params = {"request": json.dumps(request_data, separators=(',', ':'))}

async with async_timeout.timeout(10):
async with session.get(url, params={"request": json.dumps(request_data)}) as response:
async with session.get(url, params=params) as response:
if response.status == 200:
data = await response.json()
components = data.get("info", {}).get("components", [])
Expand Down

0 comments on commit 506fb07

Please sign in to comment.