Skip to content

Commit 02e0564

Browse files
authored
Add boost switches for Shelly cury component (home-assistant#154387)
1 parent 5f9b098 commit 02e0564

File tree

4 files changed

+149
-1
lines changed

4 files changed

+149
-1
lines changed

homeassistant/components/shelly/icons.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@
6868
"on": "mdi:valve-open"
6969
}
7070
},
71+
"cury_boost": {
72+
"default": "mdi:rocket-launch"
73+
},
7174
"cury_slot": {
7275
"default": "mdi:scent",
7376
"state": {

homeassistant/components/shelly/switch.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,19 @@ class RpcSwitchDescription(RpcEntityDescription, SwitchEntityDescription):
243243
available=lambda status: (left := status["left"]) is not None
244244
and left.get("vial", {}).get("level", -1) != -1,
245245
),
246+
"cury_left_boost": RpcSwitchDescription(
247+
key="cury",
248+
sub_key="slots",
249+
name="Left slot boost",
250+
translation_key="cury_boost",
251+
is_on=lambda status: status["slots"]["left"]["boost"] is not None,
252+
method_on="cury_boost",
253+
method_off="cury_stop_boost",
254+
method_params_fn=lambda id, _: (id, "left"),
255+
entity_registry_enabled_default=True,
256+
available=lambda status: (left := status["left"]) is not None
257+
and left.get("vial", {}).get("level", -1) != -1,
258+
),
246259
"cury_right": RpcSwitchDescription(
247260
key="cury",
248261
sub_key="slots",
@@ -256,6 +269,19 @@ class RpcSwitchDescription(RpcEntityDescription, SwitchEntityDescription):
256269
available=lambda status: (right := status["right"]) is not None
257270
and right.get("vial", {}).get("level", -1) != -1,
258271
),
272+
"cury_right_boost": RpcSwitchDescription(
273+
key="cury",
274+
sub_key="slots",
275+
name="Right slot boost",
276+
translation_key="cury_boost",
277+
is_on=lambda status: status["slots"]["right"]["boost"] is not None,
278+
method_on="cury_boost",
279+
method_off="cury_stop_boost",
280+
method_params_fn=lambda id, _: (id, "right"),
281+
entity_registry_enabled_default=True,
282+
available=lambda status: (right := status["right"]) is not None
283+
and right.get("vial", {}).get("level", -1) != -1,
284+
),
259285
}
260286

261287

tests/components/shelly/snapshots/test_switch.ambr

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,54 @@
4747
'state': 'on',
4848
})
4949
# ---
50+
# name: test_cury_switch_entity[switch.test_name_left_slot_boost-entry]
51+
EntityRegistryEntrySnapshot({
52+
'aliases': set({
53+
}),
54+
'area_id': None,
55+
'capabilities': None,
56+
'config_entry_id': <ANY>,
57+
'config_subentry_id': <ANY>,
58+
'device_class': None,
59+
'device_id': <ANY>,
60+
'disabled_by': None,
61+
'domain': 'switch',
62+
'entity_category': None,
63+
'entity_id': 'switch.test_name_left_slot_boost',
64+
'has_entity_name': True,
65+
'hidden_by': None,
66+
'icon': None,
67+
'id': <ANY>,
68+
'labels': set({
69+
}),
70+
'name': None,
71+
'options': dict({
72+
}),
73+
'original_device_class': None,
74+
'original_icon': None,
75+
'original_name': 'Left slot boost',
76+
'platform': 'shelly',
77+
'previous_unique_id': None,
78+
'suggested_object_id': None,
79+
'supported_features': 0,
80+
'translation_key': 'cury_boost',
81+
'unique_id': '123456789ABC-cury:0-cury_left_boost',
82+
'unit_of_measurement': None,
83+
})
84+
# ---
85+
# name: test_cury_switch_entity[switch.test_name_left_slot_boost-state]
86+
StateSnapshot({
87+
'attributes': ReadOnlyDict({
88+
'friendly_name': 'Test name Left slot boost',
89+
}),
90+
'context': <ANY>,
91+
'entity_id': 'switch.test_name_left_slot_boost',
92+
'last_changed': <ANY>,
93+
'last_reported': <ANY>,
94+
'last_updated': <ANY>,
95+
'state': 'on',
96+
})
97+
# ---
5098
# name: test_cury_switch_entity[switch.test_name_right_slot-entry]
5199
EntityRegistryEntrySnapshot({
52100
'aliases': set({
@@ -95,3 +143,51 @@
95143
'state': 'off',
96144
})
97145
# ---
146+
# name: test_cury_switch_entity[switch.test_name_right_slot_boost-entry]
147+
EntityRegistryEntrySnapshot({
148+
'aliases': set({
149+
}),
150+
'area_id': None,
151+
'capabilities': None,
152+
'config_entry_id': <ANY>,
153+
'config_subentry_id': <ANY>,
154+
'device_class': None,
155+
'device_id': <ANY>,
156+
'disabled_by': None,
157+
'domain': 'switch',
158+
'entity_category': None,
159+
'entity_id': 'switch.test_name_right_slot_boost',
160+
'has_entity_name': True,
161+
'hidden_by': None,
162+
'icon': None,
163+
'id': <ANY>,
164+
'labels': set({
165+
}),
166+
'name': None,
167+
'options': dict({
168+
}),
169+
'original_device_class': None,
170+
'original_icon': None,
171+
'original_name': 'Right slot boost',
172+
'platform': 'shelly',
173+
'previous_unique_id': None,
174+
'suggested_object_id': None,
175+
'supported_features': 0,
176+
'translation_key': 'cury_boost',
177+
'unique_id': '123456789ABC-cury:0-cury_right_boost',
178+
'unit_of_measurement': None,
179+
})
180+
# ---
181+
# name: test_cury_switch_entity[switch.test_name_right_slot_boost-state]
182+
StateSnapshot({
183+
'attributes': ReadOnlyDict({
184+
'friendly_name': 'Test name Right slot boost',
185+
}),
186+
'context': <ANY>,
187+
'entity_id': 'switch.test_name_right_slot_boost',
188+
'last_changed': <ANY>,
189+
'last_reported': <ANY>,
190+
'last_updated': <ANY>,
191+
'state': 'off',
192+
})
193+
# ---

tests/components/shelly/test_switch.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -832,11 +832,13 @@ async def test_cury_switch_entity(
832832
"left": {
833833
"intensity": 70,
834834
"on": True,
835+
"boost": {"started_at": 1760365354, "duration": 1800},
835836
"vial": {"level": 27, "name": "Forest Dream"},
836837
},
837838
"right": {
838839
"intensity": 70,
839840
"on": False,
841+
"boost": None,
840842
"vial": {"level": 84, "name": "Velvet Rose"},
841843
},
842844
},
@@ -845,7 +847,7 @@ async def test_cury_switch_entity(
845847
monkeypatch.setattr(mock_rpc_device, "status", status)
846848
await init_integration(hass, 3)
847849

848-
for entity in ("left_slot", "right_slot"):
850+
for entity in ("left_slot", "left_slot_boost", "right_slot", "right_slot_boost"):
849851
entity_id = f"{SWITCH_DOMAIN}.test_name_{entity}"
850852

851853
state = hass.states.get(entity_id)
@@ -872,6 +874,24 @@ async def test_cury_switch_entity(
872874
mock_rpc_device.mock_update()
873875
mock_rpc_device.cury_set.assert_called_with(0, "right", True)
874876

877+
await hass.services.async_call(
878+
SWITCH_DOMAIN,
879+
SERVICE_TURN_OFF,
880+
{ATTR_ENTITY_ID: "switch.test_name_left_slot_boost"},
881+
blocking=True,
882+
)
883+
mock_rpc_device.mock_update()
884+
mock_rpc_device.cury_stop_boost.assert_called_with(0, "left")
885+
886+
await hass.services.async_call(
887+
SWITCH_DOMAIN,
888+
SERVICE_TURN_ON,
889+
{ATTR_ENTITY_ID: "switch.test_name_right_slot_boost"},
890+
blocking=True,
891+
)
892+
mock_rpc_device.mock_update()
893+
mock_rpc_device.cury_boost.assert_called_with(0, "right")
894+
875895

876896
async def test_cury_switch_availability(
877897
hass: HomeAssistant,
@@ -883,11 +903,13 @@ async def test_cury_switch_availability(
883903
"left": {
884904
"intensity": 70,
885905
"on": True,
906+
"boost": None,
886907
"vial": {"level": 27, "name": "Forest Dream"},
887908
},
888909
"right": {
889910
"intensity": 70,
890911
"on": False,
912+
"boost": None,
891913
"vial": {"level": 84, "name": "Velvet Rose"},
892914
},
893915
}
@@ -924,6 +946,7 @@ async def test_cury_switch_availability(
924946
slots["left"] = {
925947
"intensity": 70,
926948
"on": True,
949+
"boost": None,
927950
"vial": {"level": 27, "name": "Forest Dream"},
928951
}
929952
mutate_rpc_device_status(monkeypatch, mock_rpc_device, "cury:0", "slots", slots)

0 commit comments

Comments
 (0)