Skip to content

Commit 61499a5

Browse files
authored
Fix Tuya BitmapTypeInformation parsing (home-assistant#158474)
1 parent 0076aaf commit 61499a5

File tree

4 files changed

+248
-2
lines changed

4 files changed

+248
-2
lines changed

homeassistant/components/tuya/type_information.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,12 @@ class BitmapTypeInformation(TypeInformation[int]):
105105
@classmethod
106106
def _from_json(cls, dpcode: str, type_data: str) -> Self | None:
107107
"""Load JSON string and return a BitmapTypeInformation object."""
108-
if not (parsed := json_loads_object(type_data)):
108+
if not (parsed := cast(dict[str, Any] | None, json_loads_object(type_data))):
109109
return None
110110
return cls(
111111
dpcode=dpcode,
112112
type_data=type_data,
113-
**cast(dict[str, list[str]], parsed),
113+
label=parsed["label"],
114114
)
115115

116116

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"endpoint": "https://apigw.tuyaeu.com",
3+
"mqtt_connected": true,
4+
"disabled_by": null,
5+
"disabled_polling": false,
6+
"name": "Slimme kattenbak",
7+
"category": "msp",
8+
"product_id": "5t7esmqqh92ssbe5",
9+
"product_name": "Automatic Cat Litter Box",
10+
"online": false,
11+
"sub": false,
12+
"time_zone": "+02:00",
13+
"active_time": "2025-07-25T06:46:38+00:00",
14+
"create_time": "2025-07-25T06:46:38+00:00",
15+
"update_time": "2025-07-25T06:46:38+00:00",
16+
"function": {
17+
"deodorization": {
18+
"type": "Boolean",
19+
"value": "{}"
20+
}
21+
},
22+
"status_range": {
23+
"cat_weight": {
24+
"type": "Integer",
25+
"value": "{\"unit\":\"g\",\"min\":600,\"max\":10000,\"scale\":0,\"step\":1}"
26+
},
27+
"excretion_times_day": {
28+
"type": "Integer",
29+
"value": "{\"unit\":\"times\",\"min\":0,\"max\":60,\"scale\":0,\"step\":1}"
30+
},
31+
"excretion_time_day": {
32+
"type": "Integer",
33+
"value": "{\"unit\":\"s\",\"min\":0,\"max\":1800,\"scale\":0,\"step\":1}"
34+
},
35+
"deodorization": {
36+
"type": "Boolean",
37+
"value": "{}"
38+
},
39+
"fault": {
40+
"type": "Bitmap",
41+
"value": "{\"label\":[\"motor_fault\",\"program_fault\",\"g_sensor_fault\"],\"maxlen\":3}"
42+
}
43+
},
44+
"status": {
45+
"cat_weight": 4999,
46+
"excretion_times_day": 1,
47+
"excretion_time_day": 93,
48+
"deodorization": false,
49+
"fault": 0
50+
},
51+
"set_up": true,
52+
"support_local": true,
53+
"warnings": null
54+
}

tests/components/tuya/snapshots/test_init.ambr

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,37 @@
619619
'via_device_id': None,
620620
})
621621
# ---
622+
# name: test_device_registry[5ebss29hqqmse7t5psm]
623+
DeviceRegistryEntrySnapshot({
624+
'area_id': None,
625+
'config_entries': <ANY>,
626+
'config_entries_subentries': <ANY>,
627+
'configuration_url': None,
628+
'connections': set({
629+
}),
630+
'disabled_by': None,
631+
'entry_type': None,
632+
'hw_version': None,
633+
'id': <ANY>,
634+
'identifiers': set({
635+
tuple(
636+
'tuya',
637+
'5ebss29hqqmse7t5psm',
638+
),
639+
}),
640+
'labels': set({
641+
}),
642+
'manufacturer': 'Tuya',
643+
'model': 'Automatic Cat Litter Box',
644+
'model_id': '5t7esmqqh92ssbe5',
645+
'name': 'Slimme kattenbak',
646+
'name_by_user': None,
647+
'primary_config_entry': <ANY>,
648+
'serial_number': None,
649+
'sw_version': None,
650+
'via_device_id': None,
651+
})
652+
# ---
622653
# name: test_device_registry[5gfyvvg48bsxbbnjzc]
623654
DeviceRegistryEntrySnapshot({
624655
'area_id': None,

tests/components/tuya/snapshots/test_sensor.ambr

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16914,6 +16914,167 @@
1691416914
'state': '77.0',
1691516915
})
1691616916
# ---
16917+
# name: test_platform_setup_and_discovery[sensor.slimme_kattenbak_cat_weight-entry]
16918+
EntityRegistryEntrySnapshot({
16919+
'aliases': set({
16920+
}),
16921+
'area_id': None,
16922+
'capabilities': dict({
16923+
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
16924+
}),
16925+
'config_entry_id': <ANY>,
16926+
'config_subentry_id': <ANY>,
16927+
'device_class': None,
16928+
'device_id': <ANY>,
16929+
'disabled_by': None,
16930+
'domain': 'sensor',
16931+
'entity_category': None,
16932+
'entity_id': 'sensor.slimme_kattenbak_cat_weight',
16933+
'has_entity_name': True,
16934+
'hidden_by': None,
16935+
'icon': None,
16936+
'id': <ANY>,
16937+
'labels': set({
16938+
}),
16939+
'name': None,
16940+
'options': dict({
16941+
'sensor': dict({
16942+
'suggested_display_precision': 0,
16943+
}),
16944+
}),
16945+
'original_device_class': <SensorDeviceClass.WEIGHT: 'weight'>,
16946+
'original_icon': None,
16947+
'original_name': 'Cat weight',
16948+
'platform': 'tuya',
16949+
'previous_unique_id': None,
16950+
'suggested_object_id': None,
16951+
'supported_features': 0,
16952+
'translation_key': 'cat_weight',
16953+
'unique_id': 'tuya.5ebss29hqqmse7t5psmcat_weight',
16954+
'unit_of_measurement': 'g',
16955+
})
16956+
# ---
16957+
# name: test_platform_setup_and_discovery[sensor.slimme_kattenbak_cat_weight-state]
16958+
StateSnapshot({
16959+
'attributes': ReadOnlyDict({
16960+
'device_class': 'weight',
16961+
'friendly_name': 'Slimme kattenbak Cat weight',
16962+
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
16963+
'unit_of_measurement': 'g',
16964+
}),
16965+
'context': <ANY>,
16966+
'entity_id': 'sensor.slimme_kattenbak_cat_weight',
16967+
'last_changed': <ANY>,
16968+
'last_reported': <ANY>,
16969+
'last_updated': <ANY>,
16970+
'state': 'unavailable',
16971+
})
16972+
# ---
16973+
# name: test_platform_setup_and_discovery[sensor.slimme_kattenbak_excretion_duration-entry]
16974+
EntityRegistryEntrySnapshot({
16975+
'aliases': set({
16976+
}),
16977+
'area_id': None,
16978+
'capabilities': dict({
16979+
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
16980+
}),
16981+
'config_entry_id': <ANY>,
16982+
'config_subentry_id': <ANY>,
16983+
'device_class': None,
16984+
'device_id': <ANY>,
16985+
'disabled_by': None,
16986+
'domain': 'sensor',
16987+
'entity_category': None,
16988+
'entity_id': 'sensor.slimme_kattenbak_excretion_duration',
16989+
'has_entity_name': True,
16990+
'hidden_by': None,
16991+
'icon': None,
16992+
'id': <ANY>,
16993+
'labels': set({
16994+
}),
16995+
'name': None,
16996+
'options': dict({
16997+
'sensor': dict({
16998+
'suggested_display_precision': 2,
16999+
}),
17000+
}),
17001+
'original_device_class': <SensorDeviceClass.DURATION: 'duration'>,
17002+
'original_icon': None,
17003+
'original_name': 'Excretion duration',
17004+
'platform': 'tuya',
17005+
'previous_unique_id': None,
17006+
'suggested_object_id': None,
17007+
'supported_features': 0,
17008+
'translation_key': 'excretion_time_day',
17009+
'unique_id': 'tuya.5ebss29hqqmse7t5psmexcretion_time_day',
17010+
'unit_of_measurement': 's',
17011+
})
17012+
# ---
17013+
# name: test_platform_setup_and_discovery[sensor.slimme_kattenbak_excretion_duration-state]
17014+
StateSnapshot({
17015+
'attributes': ReadOnlyDict({
17016+
'device_class': 'duration',
17017+
'friendly_name': 'Slimme kattenbak Excretion duration',
17018+
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
17019+
'unit_of_measurement': 's',
17020+
}),
17021+
'context': <ANY>,
17022+
'entity_id': 'sensor.slimme_kattenbak_excretion_duration',
17023+
'last_changed': <ANY>,
17024+
'last_reported': <ANY>,
17025+
'last_updated': <ANY>,
17026+
'state': 'unavailable',
17027+
})
17028+
# ---
17029+
# name: test_platform_setup_and_discovery[sensor.slimme_kattenbak_excretion_times_day-entry]
17030+
EntityRegistryEntrySnapshot({
17031+
'aliases': set({
17032+
}),
17033+
'area_id': None,
17034+
'capabilities': None,
17035+
'config_entry_id': <ANY>,
17036+
'config_subentry_id': <ANY>,
17037+
'device_class': None,
17038+
'device_id': <ANY>,
17039+
'disabled_by': None,
17040+
'domain': 'sensor',
17041+
'entity_category': None,
17042+
'entity_id': 'sensor.slimme_kattenbak_excretion_times_day',
17043+
'has_entity_name': True,
17044+
'hidden_by': None,
17045+
'icon': None,
17046+
'id': <ANY>,
17047+
'labels': set({
17048+
}),
17049+
'name': None,
17050+
'options': dict({
17051+
}),
17052+
'original_device_class': None,
17053+
'original_icon': None,
17054+
'original_name': 'Excretion times (day)',
17055+
'platform': 'tuya',
17056+
'previous_unique_id': None,
17057+
'suggested_object_id': None,
17058+
'supported_features': 0,
17059+
'translation_key': 'excretion_times_day',
17060+
'unique_id': 'tuya.5ebss29hqqmse7t5psmexcretion_times_day',
17061+
'unit_of_measurement': 'times',
17062+
})
17063+
# ---
17064+
# name: test_platform_setup_and_discovery[sensor.slimme_kattenbak_excretion_times_day-state]
17065+
StateSnapshot({
17066+
'attributes': ReadOnlyDict({
17067+
'friendly_name': 'Slimme kattenbak Excretion times (day)',
17068+
'unit_of_measurement': 'times',
17069+
}),
17070+
'context': <ANY>,
17071+
'entity_id': 'sensor.slimme_kattenbak_excretion_times_day',
17072+
'last_changed': <ANY>,
17073+
'last_reported': <ANY>,
17074+
'last_updated': <ANY>,
17075+
'state': 'unavailable',
17076+
})
17077+
# ---
1691717078
# name: test_platform_setup_and_discovery[sensor.smart_odor_eliminator_pro_battery-entry]
1691817079
EntityRegistryEntrySnapshot({
1691917080
'aliases': set({

0 commit comments

Comments
 (0)