From 1e5cfddf83eedf6baba3850b438e8118bb8cd9d5 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Wed, 12 Nov 2025 19:34:17 +0100 Subject: [PATCH] Use json_loads_object in Tuya light (#156452) --- homeassistant/components/tuya/light.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/tuya/light.py b/homeassistant/components/tuya/light.py index 0f508e01302..485468bda6a 100644 --- a/homeassistant/components/tuya/light.py +++ b/homeassistant/components/tuya/light.py @@ -24,6 +24,7 @@ from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback from homeassistant.util import color as color_util +from homeassistant.util.json import json_loads_object from . import TuyaConfigEntry from .const import TUYA_DISCOVERY_NEW, DeviceCategory, DPCode, DPType, WorkMode @@ -499,11 +500,11 @@ class TuyaLightEntity(TuyaEntity, LightEntity): values = self.device.status_range[dpcode].values # Fetch color data type information - if function_data := json.loads(values): + if function_data := json_loads_object(values): self._color_data_type = ColorTypeData( - h_type=IntegerTypeData(dpcode, **function_data["h"]), - s_type=IntegerTypeData(dpcode, **function_data["s"]), - v_type=IntegerTypeData(dpcode, **function_data["v"]), + h_type=IntegerTypeData(dpcode, **cast(dict, function_data["h"])), + s_type=IntegerTypeData(dpcode, **cast(dict, function_data["s"])), + v_type=IntegerTypeData(dpcode, **cast(dict, function_data["v"])), ) else: # If no type is found, use a default one @@ -770,12 +771,12 @@ class TuyaLightEntity(TuyaEntity, LightEntity): if not (status_data := self.device.status[self._color_data_dpcode]): return None - if not (status := json.loads(status_data)): + if not (status := json_loads_object(status_data)): return None return ColorData( type_data=self._color_data_type, - h_value=status["h"], - s_value=status["s"], - v_value=status["v"], + h_value=cast(int, status["h"]), + s_value=cast(int, status["s"]), + v_value=cast(int, status["v"]), )