Skip to content

Commit 37040f5

Browse files
davidrapanthecodeCopilot
authored
Add Shelly switch translation (home-assistant#156146)
Signed-off-by: David Rapan <[email protected]> Co-authored-by: Shay Levy <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent 531397e commit 37040f5

File tree

5 files changed

+99
-23
lines changed

5 files changed

+99
-23
lines changed

homeassistant/components/shelly/icons.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,26 @@
7777
"on": "mdi:home-export-outline"
7878
}
7979
},
80-
"cury_boost": {
80+
"left_slot": {
81+
"default": "mdi:scent",
82+
"state": {
83+
"off": "mdi:scent-off",
84+
"on": "mdi:scent"
85+
}
86+
},
87+
"left_slot_boost": {
8188
"default": "mdi:rocket-launch"
8289
},
83-
"cury_slot": {
90+
"right_slot": {
8491
"default": "mdi:scent",
8592
"state": {
8693
"off": "mdi:scent-off",
8794
"on": "mdi:scent"
8895
}
8996
},
97+
"right_slot_boost": {
98+
"default": "mdi:rocket-launch"
99+
},
90100
"valve_switch": {
91101
"default": "mdi:valve",
92102
"state": {

homeassistant/components/shelly/strings.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,41 @@
463463
"name": "Water temperature"
464464
}
465465
},
466+
"switch": {
467+
"charging": {
468+
"name": "Charging"
469+
},
470+
"child_lock": {
471+
"name": "Child lock"
472+
},
473+
"frost_protection": {
474+
"name": "[%key:component::shelly::entity::climate::thermostat::state_attributes::preset_mode::state::frost_protection%]"
475+
},
476+
"left_slot": {
477+
"name": "Left slot"
478+
},
479+
"left_slot_boost": {
480+
"name": "Left slot boost"
481+
},
482+
"motion_detection": {
483+
"name": "Motion detection"
484+
},
485+
"right_slot": {
486+
"name": "Right slot"
487+
},
488+
"right_slot_boost": {
489+
"name": "Right slot boost"
490+
},
491+
"thermostat_enabled": {
492+
"name": "Thermostat enabled"
493+
},
494+
"valve_opened": {
495+
"name": "Valve opened"
496+
},
497+
"zone_with_number": {
498+
"name": "Zone {zone_number}"
499+
}
500+
},
466501
"update": {
467502
"beta_firmware": {
468503
"name": "Beta firmware"

homeassistant/components/shelly/switch.py

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class BlockSwitchDescription(BlockEntityDescription, SwitchEntityDescription):
6767
BLOCK_SLEEPING_MOTION_SWITCH = {
6868
("sensor", "motionActive"): BlockSwitchDescription(
6969
key="sensor|motionActive",
70-
name="Motion detection",
70+
translation_key="motion_detection",
7171
entity_category=EntityCategory.CONFIG,
7272
)
7373
}
@@ -99,7 +99,7 @@ class RpcSwitchDescription(RpcEntityDescription, SwitchEntityDescription):
9999
"boolean_generic": RpcSwitchDescription(
100100
key="boolean",
101101
sub_key="value",
102-
removal_condition=lambda config, _status, key: not is_view_for_platform(
102+
removal_condition=lambda config, _, key: not is_view_for_platform(
103103
config, key, SWITCH_PLATFORM
104104
),
105105
is_on=lambda status: bool(status["value"]),
@@ -111,6 +111,7 @@ class RpcSwitchDescription(RpcEntityDescription, SwitchEntityDescription):
111111
"boolean_anti_freeze": RpcSwitchDescription(
112112
key="boolean",
113113
sub_key="value",
114+
translation_key="frost_protection",
114115
entity_registry_enabled_default=False,
115116
is_on=lambda status: bool(status["value"]),
116117
method_on="boolean_set",
@@ -122,6 +123,7 @@ class RpcSwitchDescription(RpcEntityDescription, SwitchEntityDescription):
122123
"boolean_child_lock": RpcSwitchDescription(
123124
key="boolean",
124125
sub_key="value",
126+
translation_key="child_lock",
125127
is_on=lambda status: bool(status["value"]),
126128
method_on="boolean_set",
127129
method_off="boolean_set",
@@ -132,6 +134,7 @@ class RpcSwitchDescription(RpcEntityDescription, SwitchEntityDescription):
132134
"boolean_enable": RpcSwitchDescription(
133135
key="boolean",
134136
sub_key="value",
137+
translation_key="thermostat_enabled",
135138
entity_registry_enabled_default=False,
136139
is_on=lambda status: bool(status["value"]),
137140
method_on="boolean_set",
@@ -143,7 +146,7 @@ class RpcSwitchDescription(RpcEntityDescription, SwitchEntityDescription):
143146
"boolean_start_charging": RpcSwitchDescription(
144147
key="boolean",
145148
sub_key="value",
146-
name="Charging",
149+
translation_key="charging",
147150
is_on=lambda status: bool(status["value"]),
148151
method_on="boolean_set",
149152
method_off="boolean_set",
@@ -154,6 +157,7 @@ class RpcSwitchDescription(RpcEntityDescription, SwitchEntityDescription):
154157
"boolean_state": RpcSwitchDescription(
155158
key="boolean",
156159
sub_key="value",
160+
translation_key="valve_opened",
157161
entity_registry_enabled_default=False,
158162
is_on=lambda status: bool(status["value"]),
159163
method_on="boolean_set",
@@ -165,6 +169,8 @@ class RpcSwitchDescription(RpcEntityDescription, SwitchEntityDescription):
165169
"boolean_zone0": RpcSwitchDescription(
166170
key="boolean",
167171
sub_key="value",
172+
translation_key="zone_with_number",
173+
translation_placeholders={"zone_number": "1"},
168174
entity_registry_enabled_default=False,
169175
is_on=lambda status: bool(status["value"]),
170176
method_on="boolean_set",
@@ -176,6 +182,8 @@ class RpcSwitchDescription(RpcEntityDescription, SwitchEntityDescription):
176182
"boolean_zone1": RpcSwitchDescription(
177183
key="boolean",
178184
sub_key="value",
185+
translation_key="zone_with_number",
186+
translation_placeholders={"zone_number": "2"},
179187
entity_registry_enabled_default=False,
180188
is_on=lambda status: bool(status["value"]),
181189
method_on="boolean_set",
@@ -187,6 +195,8 @@ class RpcSwitchDescription(RpcEntityDescription, SwitchEntityDescription):
187195
"boolean_zone2": RpcSwitchDescription(
188196
key="boolean",
189197
sub_key="value",
198+
translation_key="zone_with_number",
199+
translation_placeholders={"zone_number": "3"},
190200
entity_registry_enabled_default=False,
191201
is_on=lambda status: bool(status["value"]),
192202
method_on="boolean_set",
@@ -198,6 +208,8 @@ class RpcSwitchDescription(RpcEntityDescription, SwitchEntityDescription):
198208
"boolean_zone3": RpcSwitchDescription(
199209
key="boolean",
200210
sub_key="value",
211+
translation_key="zone_with_number",
212+
translation_placeholders={"zone_number": "4"},
201213
entity_registry_enabled_default=False,
202214
is_on=lambda status: bool(status["value"]),
203215
method_on="boolean_set",
@@ -209,6 +221,8 @@ class RpcSwitchDescription(RpcEntityDescription, SwitchEntityDescription):
209221
"boolean_zone4": RpcSwitchDescription(
210222
key="boolean",
211223
sub_key="value",
224+
translation_key="zone_with_number",
225+
translation_placeholders={"zone_number": "5"},
212226
entity_registry_enabled_default=False,
213227
is_on=lambda status: bool(status["value"]),
214228
method_on="boolean_set",
@@ -220,6 +234,8 @@ class RpcSwitchDescription(RpcEntityDescription, SwitchEntityDescription):
220234
"boolean_zone5": RpcSwitchDescription(
221235
key="boolean",
222236
sub_key="value",
237+
translation_key="zone_with_number",
238+
translation_placeholders={"zone_number": "6"},
223239
entity_registry_enabled_default=False,
224240
is_on=lambda status: bool(status["value"]),
225241
method_on="boolean_set",
@@ -241,8 +257,7 @@ class RpcSwitchDescription(RpcEntityDescription, SwitchEntityDescription):
241257
"cury_left": RpcSwitchDescription(
242258
key="cury",
243259
sub_key="slots",
244-
name="Left slot",
245-
translation_key="cury_slot",
260+
translation_key="left_slot",
246261
is_on=lambda status: bool(status["slots"]["left"]["on"]),
247262
method_on="cury_set",
248263
method_off="cury_set",
@@ -254,8 +269,7 @@ class RpcSwitchDescription(RpcEntityDescription, SwitchEntityDescription):
254269
"cury_left_boost": RpcSwitchDescription(
255270
key="cury",
256271
sub_key="slots",
257-
name="Left slot boost",
258-
translation_key="cury_boost",
272+
translation_key="left_slot_boost",
259273
is_on=lambda status: status["slots"]["left"]["boost"] is not None,
260274
method_on="cury_boost",
261275
method_off="cury_stop_boost",
@@ -267,8 +281,7 @@ class RpcSwitchDescription(RpcEntityDescription, SwitchEntityDescription):
267281
"cury_right": RpcSwitchDescription(
268282
key="cury",
269283
sub_key="slots",
270-
name="Right slot",
271-
translation_key="cury_slot",
284+
translation_key="right_slot",
272285
is_on=lambda status: bool(status["slots"]["right"]["on"]),
273286
method_on="cury_set",
274287
method_off="cury_set",
@@ -280,8 +293,7 @@ class RpcSwitchDescription(RpcEntityDescription, SwitchEntityDescription):
280293
"cury_right_boost": RpcSwitchDescription(
281294
key="cury",
282295
sub_key="slots",
283-
name="Right slot boost",
284-
translation_key="cury_boost",
296+
translation_key="right_slot_boost",
285297
is_on=lambda status: status["slots"]["right"]["boost"] is not None,
286298
method_on="cury_boost",
287299
method_off="cury_stop_boost",
@@ -399,7 +411,6 @@ class BlockSleepingMotionSwitch(
399411
"""Entity that controls Motion Sensor on Block based Shelly devices."""
400412

401413
entity_description: BlockSwitchDescription
402-
_attr_translation_key = "motion_switch"
403414

404415
def __init__(
405416
self,
@@ -413,6 +424,9 @@ def __init__(
413424
super().__init__(coordinator, block, attribute, description, entry)
414425
self.last_state: State | None = None
415426

427+
if hasattr(self, "_attr_name"):
428+
delattr(self, "_attr_name")
429+
416430
@property
417431
def is_on(self) -> bool | None:
418432
"""If motion is active."""
@@ -488,6 +502,23 @@ class RpcSwitch(ShellyRpcAttributeEntity, SwitchEntity):
488502

489503
entity_description: RpcSwitchDescription
490504

505+
def __init__(
506+
self,
507+
coordinator: ShellyRpcCoordinator,
508+
key: str,
509+
attribute: str,
510+
description: RpcSwitchDescription,
511+
) -> None:
512+
"""Initialize select."""
513+
super().__init__(coordinator, key, attribute, description)
514+
515+
if (
516+
hasattr(self, "_attr_name")
517+
and description.role != ROLE_GENERIC
518+
and description.key not in ("switch", "script")
519+
):
520+
delattr(self, "_attr_name")
521+
491522
@property
492523
def is_on(self) -> bool:
493524
"""If switch is on."""
@@ -524,7 +555,7 @@ def __init__(
524555
coordinator: ShellyRpcCoordinator,
525556
key: str,
526557
attribute: str,
527-
description: RpcEntityDescription,
558+
description: RpcSwitchDescription,
528559
) -> None:
529560
"""Initialize the switch."""
530561
super().__init__(coordinator, key, attribute, description)

tests/components/shelly/snapshots/test_devices.ambr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@
709709
'previous_unique_id': None,
710710
'suggested_object_id': None,
711711
'supported_features': 0,
712-
'translation_key': 'cury_slot',
712+
'translation_key': 'left_slot',
713713
'unique_id': '123456789ABC-cury:0-cury_left',
714714
'unit_of_measurement': None,
715715
})
@@ -757,7 +757,7 @@
757757
'previous_unique_id': None,
758758
'suggested_object_id': None,
759759
'supported_features': 0,
760-
'translation_key': 'cury_boost',
760+
'translation_key': 'left_slot_boost',
761761
'unique_id': '123456789ABC-cury:0-cury_left_boost',
762762
'unit_of_measurement': None,
763763
})
@@ -805,7 +805,7 @@
805805
'previous_unique_id': None,
806806
'suggested_object_id': None,
807807
'supported_features': 0,
808-
'translation_key': 'cury_slot',
808+
'translation_key': 'right_slot',
809809
'unique_id': '123456789ABC-cury:0-cury_right',
810810
'unit_of_measurement': None,
811811
})
@@ -853,7 +853,7 @@
853853
'previous_unique_id': None,
854854
'suggested_object_id': None,
855855
'supported_features': 0,
856-
'translation_key': 'cury_boost',
856+
'translation_key': 'right_slot_boost',
857857
'unique_id': '123456789ABC-cury:0-cury_right_boost',
858858
'unit_of_measurement': None,
859859
})

tests/components/shelly/snapshots/test_switch.ambr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
'previous_unique_id': None,
7878
'suggested_object_id': None,
7979
'supported_features': 0,
80-
'translation_key': 'cury_slot',
80+
'translation_key': 'left_slot',
8181
'unique_id': '123456789ABC-cury:0-cury_left',
8282
'unit_of_measurement': None,
8383
})
@@ -125,7 +125,7 @@
125125
'previous_unique_id': None,
126126
'suggested_object_id': None,
127127
'supported_features': 0,
128-
'translation_key': 'cury_boost',
128+
'translation_key': 'left_slot_boost',
129129
'unique_id': '123456789ABC-cury:0-cury_left_boost',
130130
'unit_of_measurement': None,
131131
})
@@ -173,7 +173,7 @@
173173
'previous_unique_id': None,
174174
'suggested_object_id': None,
175175
'supported_features': 0,
176-
'translation_key': 'cury_slot',
176+
'translation_key': 'right_slot',
177177
'unique_id': '123456789ABC-cury:0-cury_right',
178178
'unit_of_measurement': None,
179179
})
@@ -221,7 +221,7 @@
221221
'previous_unique_id': None,
222222
'suggested_object_id': None,
223223
'supported_features': 0,
224-
'translation_key': 'cury_boost',
224+
'translation_key': 'right_slot_boost',
225225
'unique_id': '123456789ABC-cury:0-cury_right_boost',
226226
'unit_of_measurement': None,
227227
})

0 commit comments

Comments
 (0)