Skip to content

Commit 83d6a30

Browse files
authored
Add Child Lock Switch to Vesync (home-assistant#155643)
1 parent 19dee6d commit 83d6a30

File tree

4 files changed

+219
-0
lines changed

4 files changed

+219
-0
lines changed

homeassistant/components/vesync/strings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@
9292
}
9393
},
9494
"switch": {
95+
"child_lock": {
96+
"name": "Child lock"
97+
},
9598
"display": {
9699
"name": "Display"
97100
}

homeassistant/components/vesync/switch.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ class VeSyncSwitchEntityDescription(SwitchEntityDescription):
5656
on_fn=lambda device: device.toggle_display(True),
5757
off_fn=lambda device: device.toggle_display(False),
5858
),
59+
VeSyncSwitchEntityDescription(
60+
key="child_lock",
61+
is_on=lambda device: device.state.child_lock,
62+
exists_fn=(lambda device: rgetattr(device, "state.child_lock") is not None),
63+
translation_key="child_lock",
64+
on_fn=lambda device: device.toggle_child_lock(True),
65+
off_fn=lambda device: device.toggle_child_lock(False),
66+
),
5967
)
6068

6169

tests/components/vesync/snapshots/test_diagnostics.ambr

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,30 @@
337337
}),
338338
'unit_of_measurement': 'μg/m³',
339339
}),
340+
dict({
341+
'device_class': None,
342+
'disabled': False,
343+
'disabled_by': None,
344+
'domain': 'switch',
345+
'entity_category': None,
346+
'entity_id': 'switch.test_fan_child_lock',
347+
'icon': None,
348+
'name': None,
349+
'original_device_class': None,
350+
'original_icon': None,
351+
'original_name': 'Child lock',
352+
'state': dict({
353+
'attributes': dict({
354+
'friendly_name': 'Test Fan Child lock',
355+
}),
356+
'entity_id': 'switch.test_fan_child_lock',
357+
'last_changed': str,
358+
'last_reported': str,
359+
'last_updated': str,
360+
'state': 'unavailable',
361+
}),
362+
'unit_of_measurement': None,
363+
}),
340364
dict({
341365
'device_class': None,
342366
'disabled': False,

tests/components/vesync/snapshots/test_switch.ambr

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,54 @@
6767
'unique_id': 'air-purifier-display',
6868
'unit_of_measurement': None,
6969
}),
70+
EntityRegistryEntrySnapshot({
71+
'aliases': set({
72+
}),
73+
'area_id': None,
74+
'capabilities': None,
75+
'config_entry_id': <ANY>,
76+
'config_subentry_id': <ANY>,
77+
'device_class': None,
78+
'device_id': <ANY>,
79+
'disabled_by': None,
80+
'domain': 'switch',
81+
'entity_category': None,
82+
'entity_id': 'switch.air_purifier_131s_child_lock',
83+
'has_entity_name': True,
84+
'hidden_by': None,
85+
'icon': None,
86+
'id': <ANY>,
87+
'labels': set({
88+
}),
89+
'name': None,
90+
'options': dict({
91+
}),
92+
'original_device_class': None,
93+
'original_icon': None,
94+
'original_name': 'Child lock',
95+
'platform': 'vesync',
96+
'previous_unique_id': None,
97+
'suggested_object_id': None,
98+
'supported_features': 0,
99+
'translation_key': 'child_lock',
100+
'unique_id': 'air-purifier-child_lock',
101+
'unit_of_measurement': None,
102+
}),
70103
])
71104
# ---
105+
# name: test_switch_state[Air Purifier 131s][switch.air_purifier_131s_child_lock]
106+
StateSnapshot({
107+
'attributes': ReadOnlyDict({
108+
'friendly_name': 'Air Purifier 131s Child lock',
109+
}),
110+
'context': <ANY>,
111+
'entity_id': 'switch.air_purifier_131s_child_lock',
112+
'last_changed': <ANY>,
113+
'last_reported': <ANY>,
114+
'last_updated': <ANY>,
115+
'state': 'off',
116+
})
117+
# ---
72118
# name: test_switch_state[Air Purifier 131s][switch.air_purifier_131s_display]
73119
StateSnapshot({
74120
'attributes': ReadOnlyDict({
@@ -150,8 +196,54 @@
150196
'unique_id': 'asd_sdfKIHG7IJHGwJGJ7GJ_ag5h3G55-display',
151197
'unit_of_measurement': None,
152198
}),
199+
EntityRegistryEntrySnapshot({
200+
'aliases': set({
201+
}),
202+
'area_id': None,
203+
'capabilities': None,
204+
'config_entry_id': <ANY>,
205+
'config_subentry_id': <ANY>,
206+
'device_class': None,
207+
'device_id': <ANY>,
208+
'disabled_by': None,
209+
'domain': 'switch',
210+
'entity_category': None,
211+
'entity_id': 'switch.air_purifier_200s_child_lock',
212+
'has_entity_name': True,
213+
'hidden_by': None,
214+
'icon': None,
215+
'id': <ANY>,
216+
'labels': set({
217+
}),
218+
'name': None,
219+
'options': dict({
220+
}),
221+
'original_device_class': None,
222+
'original_icon': None,
223+
'original_name': 'Child lock',
224+
'platform': 'vesync',
225+
'previous_unique_id': None,
226+
'suggested_object_id': None,
227+
'supported_features': 0,
228+
'translation_key': 'child_lock',
229+
'unique_id': 'asd_sdfKIHG7IJHGwJGJ7GJ_ag5h3G55-child_lock',
230+
'unit_of_measurement': None,
231+
}),
153232
])
154233
# ---
234+
# name: test_switch_state[Air Purifier 200s][switch.air_purifier_200s_child_lock]
235+
StateSnapshot({
236+
'attributes': ReadOnlyDict({
237+
'friendly_name': 'Air Purifier 200s Child lock',
238+
}),
239+
'context': <ANY>,
240+
'entity_id': 'switch.air_purifier_200s_child_lock',
241+
'last_changed': <ANY>,
242+
'last_reported': <ANY>,
243+
'last_updated': <ANY>,
244+
'state': 'off',
245+
})
246+
# ---
155247
# name: test_switch_state[Air Purifier 200s][switch.air_purifier_200s_display]
156248
StateSnapshot({
157249
'attributes': ReadOnlyDict({
@@ -233,8 +325,54 @@
233325
'unique_id': '400s-purifier-display',
234326
'unit_of_measurement': None,
235327
}),
328+
EntityRegistryEntrySnapshot({
329+
'aliases': set({
330+
}),
331+
'area_id': None,
332+
'capabilities': None,
333+
'config_entry_id': <ANY>,
334+
'config_subentry_id': <ANY>,
335+
'device_class': None,
336+
'device_id': <ANY>,
337+
'disabled_by': None,
338+
'domain': 'switch',
339+
'entity_category': None,
340+
'entity_id': 'switch.air_purifier_400s_child_lock',
341+
'has_entity_name': True,
342+
'hidden_by': None,
343+
'icon': None,
344+
'id': <ANY>,
345+
'labels': set({
346+
}),
347+
'name': None,
348+
'options': dict({
349+
}),
350+
'original_device_class': None,
351+
'original_icon': None,
352+
'original_name': 'Child lock',
353+
'platform': 'vesync',
354+
'previous_unique_id': None,
355+
'suggested_object_id': None,
356+
'supported_features': 0,
357+
'translation_key': 'child_lock',
358+
'unique_id': '400s-purifier-child_lock',
359+
'unit_of_measurement': None,
360+
}),
236361
])
237362
# ---
363+
# name: test_switch_state[Air Purifier 400s][switch.air_purifier_400s_child_lock]
364+
StateSnapshot({
365+
'attributes': ReadOnlyDict({
366+
'friendly_name': 'Air Purifier 400s Child lock',
367+
}),
368+
'context': <ANY>,
369+
'entity_id': 'switch.air_purifier_400s_child_lock',
370+
'last_changed': <ANY>,
371+
'last_reported': <ANY>,
372+
'last_updated': <ANY>,
373+
'state': 'off',
374+
})
375+
# ---
238376
# name: test_switch_state[Air Purifier 400s][switch.air_purifier_400s_display]
239377
StateSnapshot({
240378
'attributes': ReadOnlyDict({
@@ -316,8 +454,54 @@
316454
'unique_id': '600s-purifier-display',
317455
'unit_of_measurement': None,
318456
}),
457+
EntityRegistryEntrySnapshot({
458+
'aliases': set({
459+
}),
460+
'area_id': None,
461+
'capabilities': None,
462+
'config_entry_id': <ANY>,
463+
'config_subentry_id': <ANY>,
464+
'device_class': None,
465+
'device_id': <ANY>,
466+
'disabled_by': None,
467+
'domain': 'switch',
468+
'entity_category': None,
469+
'entity_id': 'switch.air_purifier_600s_child_lock',
470+
'has_entity_name': True,
471+
'hidden_by': None,
472+
'icon': None,
473+
'id': <ANY>,
474+
'labels': set({
475+
}),
476+
'name': None,
477+
'options': dict({
478+
}),
479+
'original_device_class': None,
480+
'original_icon': None,
481+
'original_name': 'Child lock',
482+
'platform': 'vesync',
483+
'previous_unique_id': None,
484+
'suggested_object_id': None,
485+
'supported_features': 0,
486+
'translation_key': 'child_lock',
487+
'unique_id': '600s-purifier-child_lock',
488+
'unit_of_measurement': None,
489+
}),
319490
])
320491
# ---
492+
# name: test_switch_state[Air Purifier 600s][switch.air_purifier_600s_child_lock]
493+
StateSnapshot({
494+
'attributes': ReadOnlyDict({
495+
'friendly_name': 'Air Purifier 600s Child lock',
496+
}),
497+
'context': <ANY>,
498+
'entity_id': 'switch.air_purifier_600s_child_lock',
499+
'last_changed': <ANY>,
500+
'last_reported': <ANY>,
501+
'last_updated': <ANY>,
502+
'state': 'off',
503+
})
504+
# ---
321505
# name: test_switch_state[Air Purifier 600s][switch.air_purifier_600s_display]
322506
StateSnapshot({
323507
'attributes': ReadOnlyDict({

0 commit comments

Comments
 (0)