Skip to content

Commit a7d01b0

Browse files
authored
Use json_loads_object in tuya models (home-assistant#156455)
1 parent 1e5cfdd commit a7d01b0

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

homeassistant/components/tuya/models.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55
from abc import ABC, abstractmethod
66
import base64
77
from dataclasses import dataclass
8-
import json
9-
from typing import Any, Literal, Self, overload
8+
from typing import Any, Literal, Self, cast, overload
109

1110
from tuya_sharing import CustomerDevice
1211

13-
from homeassistant.util.json import json_loads
12+
from homeassistant.util.json import json_loads, json_loads_object
1413

1514
from .const import DPCode, DPType
1615
from .util import parse_dptype, remap_value
@@ -88,7 +87,7 @@ def remap_value_from(
8887
@classmethod
8988
def from_json(cls, dpcode: DPCode, data: str) -> Self | None:
9089
"""Load JSON string and return a IntegerTypeData object."""
91-
if not (parsed := json.loads(data)):
90+
if not (parsed := cast(dict[str, Any] | None, json_loads_object(data))):
9291
return None
9392

9493
return cls(
@@ -111,9 +110,9 @@ class BitmapTypeInformation(TypeInformation):
111110
@classmethod
112111
def from_json(cls, dpcode: DPCode, data: str) -> Self | None:
113112
"""Load JSON string and return a BitmapTypeInformation object."""
114-
if not (parsed := json.loads(data)):
113+
if not (parsed := json_loads_object(data)):
115114
return None
116-
return cls(dpcode, **parsed)
115+
return cls(dpcode, **cast(dict[str, list[str]], parsed))
117116

118117

119118
@dataclass
@@ -125,9 +124,9 @@ class EnumTypeData(TypeInformation):
125124
@classmethod
126125
def from_json(cls, dpcode: DPCode, data: str) -> Self | None:
127126
"""Load JSON string and return a EnumTypeData object."""
128-
if not (parsed := json.loads(data)):
127+
if not (parsed := json_loads_object(data)):
129128
return None
130-
return cls(dpcode, **parsed)
129+
return cls(dpcode, **cast(dict[str, list[str]], parsed))
131130

132131

133132
_TYPE_INFORMATION_MAPPINGS: dict[DPType, type[TypeInformation]] = {

0 commit comments

Comments
 (0)