Skip to content

Commit 1e5cfdd

Browse files
authored
Use json_loads_object in Tuya light (home-assistant#156452)
1 parent 006fc5b commit 1e5cfdd

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

homeassistant/components/tuya/light.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from homeassistant.helpers.dispatcher import async_dispatcher_connect
2525
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
2626
from homeassistant.util import color as color_util
27+
from homeassistant.util.json import json_loads_object
2728

2829
from . import TuyaConfigEntry
2930
from .const import TUYA_DISCOVERY_NEW, DeviceCategory, DPCode, DPType, WorkMode
@@ -499,11 +500,11 @@ def __init__(
499500
values = self.device.status_range[dpcode].values
500501

501502
# Fetch color data type information
502-
if function_data := json.loads(values):
503+
if function_data := json_loads_object(values):
503504
self._color_data_type = ColorTypeData(
504-
h_type=IntegerTypeData(dpcode, **function_data["h"]),
505-
s_type=IntegerTypeData(dpcode, **function_data["s"]),
506-
v_type=IntegerTypeData(dpcode, **function_data["v"]),
505+
h_type=IntegerTypeData(dpcode, **cast(dict, function_data["h"])),
506+
s_type=IntegerTypeData(dpcode, **cast(dict, function_data["s"])),
507+
v_type=IntegerTypeData(dpcode, **cast(dict, function_data["v"])),
507508
)
508509
else:
509510
# If no type is found, use a default one
@@ -770,12 +771,12 @@ def _get_color_data(self) -> ColorData | None:
770771
if not (status_data := self.device.status[self._color_data_dpcode]):
771772
return None
772773

773-
if not (status := json.loads(status_data)):
774+
if not (status := json_loads_object(status_data)):
774775
return None
775776

776777
return ColorData(
777778
type_data=self._color_data_type,
778-
h_value=status["h"],
779-
s_value=status["s"],
780-
v_value=status["v"],
779+
h_value=cast(int, status["h"]),
780+
s_value=cast(int, status["s"]),
781+
v_value=cast(int, status["v"]),
781782
)

0 commit comments

Comments
 (0)