|
24 | 24 | from homeassistant.helpers.dispatcher import async_dispatcher_connect |
25 | 25 | from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback |
26 | 26 | from homeassistant.util import color as color_util |
| 27 | +from homeassistant.util.json import json_loads_object |
27 | 28 |
|
28 | 29 | from . import TuyaConfigEntry |
29 | 30 | from .const import TUYA_DISCOVERY_NEW, DeviceCategory, DPCode, DPType, WorkMode |
@@ -499,11 +500,11 @@ def __init__( |
499 | 500 | values = self.device.status_range[dpcode].values |
500 | 501 |
|
501 | 502 | # Fetch color data type information |
502 | | - if function_data := json.loads(values): |
| 503 | + if function_data := json_loads_object(values): |
503 | 504 | 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"])), |
507 | 508 | ) |
508 | 509 | else: |
509 | 510 | # If no type is found, use a default one |
@@ -770,12 +771,12 @@ def _get_color_data(self) -> ColorData | None: |
770 | 771 | if not (status_data := self.device.status[self._color_data_dpcode]): |
771 | 772 | return None |
772 | 773 |
|
773 | | - if not (status := json.loads(status_data)): |
| 774 | + if not (status := json_loads_object(status_data)): |
774 | 775 | return None |
775 | 776 |
|
776 | 777 | return ColorData( |
777 | 778 | 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"]), |
781 | 782 | ) |
0 commit comments