Skip to content

Commit 006fc5b

Browse files
authored
Remove JSON parsing from tuya diagnostics (home-assistant#156451)
1 parent 35a4b68 commit 006fc5b

File tree

2 files changed

+7
-23
lines changed

2 files changed

+7
-23
lines changed

homeassistant/components/tuya/diagnostics.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
from __future__ import annotations
44

5-
from contextlib import suppress
6-
import json
7-
from typing import Any, cast
5+
from typing import Any
86

97
from tuya_sharing import CustomerDevice
108

@@ -101,30 +99,20 @@ def _async_device_as_dict(
10199
data["status"][dpcode] = REDACTED
102100
continue
103101

104-
with suppress(ValueError, TypeError):
105-
value = json.loads(value)
106102
data["status"][dpcode] = value
107103

108104
# Gather Tuya functions
109105
for function in device.function.values():
110-
value = function.values
111-
with suppress(ValueError, TypeError, AttributeError):
112-
value = json.loads(cast(str, function.values))
113-
114106
data["function"][function.code] = {
115107
"type": function.type,
116-
"value": value,
108+
"value": function.values,
117109
}
118110

119111
# Gather Tuya status ranges
120112
for status_range in device.status_range.values():
121-
value = status_range.values
122-
with suppress(ValueError, TypeError, AttributeError):
123-
value = json.loads(status_range.values)
124-
125113
data["status_range"][status_range.code] = {
126114
"type": status_range.type,
127-
"value": value,
115+
"value": status_range.values,
128116
}
129117

130118
# Gather information how this Tuya device is represented in Home Assistant

tests/components/tuya/snapshots/test_diagnostics.ambr

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
'function': dict({
1111
'null': dict({
1212
'type': 'Boolean',
13-
'value': dict({
14-
}),
13+
'value': '{}',
1514
}),
1615
}),
1716
'home_assistant': dict({
@@ -77,8 +76,7 @@
7776
'status_range': dict({
7877
'null': dict({
7978
'type': 'Boolean',
80-
'value': dict({
81-
}),
79+
'value': '{}',
8280
}),
8381
}),
8482
'sub': False,
@@ -98,8 +96,7 @@
9896
'function': dict({
9997
'null': dict({
10098
'type': 'Boolean',
101-
'value': dict({
102-
}),
99+
'value': '{}',
103100
}),
104101
}),
105102
'home_assistant': dict({
@@ -164,8 +161,7 @@
164161
'status_range': dict({
165162
'null': dict({
166163
'type': 'Boolean',
167-
'value': dict({
168-
}),
164+
'value': '{}',
169165
}),
170166
}),
171167
'sub': False,

0 commit comments

Comments
 (0)