Skip to content

Commit 7517569

Browse files
authored
Add Shelly button translation (home-assistant#156153)
Signed-off-by: David Rapan <[email protected]>
1 parent cd86c78 commit 7517569

File tree

5 files changed

+71
-18
lines changed

5 files changed

+71
-18
lines changed

homeassistant/components/shelly/button.py

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from homeassistant.exceptions import HomeAssistantError
2222
from homeassistant.helpers import entity_registry as er
2323
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
24+
from homeassistant.helpers.entity_registry import RegistryEntry
2425
from homeassistant.helpers.update_coordinator import CoordinatorEntity
2526

2627
from .const import (
@@ -76,45 +77,41 @@ class RpcButtonDescription(RpcEntityDescription, ButtonEntityDescription):
7677
BUTTONS: Final[list[ShellyButtonDescription[Any]]] = [
7778
ShellyButtonDescription[ShellyBlockCoordinator | ShellyRpcCoordinator](
7879
key="reboot",
79-
name="Restart",
8080
device_class=ButtonDeviceClass.RESTART,
8181
entity_category=EntityCategory.CONFIG,
8282
press_action="trigger_reboot",
8383
),
8484
ShellyButtonDescription[ShellyBlockCoordinator](
8585
key="self_test",
86-
name="Self test",
8786
translation_key="self_test",
8887
entity_category=EntityCategory.DIAGNOSTIC,
8988
press_action="trigger_shelly_gas_self_test",
9089
supported=lambda coordinator: coordinator.model in SHELLY_GAS_MODELS,
9190
),
9291
ShellyButtonDescription[ShellyBlockCoordinator](
9392
key="mute",
94-
name="Mute",
95-
translation_key="mute",
93+
translation_key="mute_alarm",
9694
entity_category=EntityCategory.CONFIG,
9795
press_action="trigger_shelly_gas_mute",
9896
supported=lambda coordinator: coordinator.model in SHELLY_GAS_MODELS,
9997
),
10098
ShellyButtonDescription[ShellyBlockCoordinator](
10199
key="unmute",
102-
name="Unmute",
103-
translation_key="unmute",
100+
translation_key="unmute_alarm",
104101
entity_category=EntityCategory.CONFIG,
105102
press_action="trigger_shelly_gas_unmute",
106103
supported=lambda coordinator: coordinator.model in SHELLY_GAS_MODELS,
107104
),
108105
ShellyButtonDescription[ShellyRpcCoordinator](
109106
key="turn_on_screen",
110-
name="Turn on the screen",
107+
translation_key="turn_on_the_screen",
111108
press_action="wall_display_set_screen",
112109
params={"value": True},
113110
supported=lambda coordinator: coordinator.model in SHELLY_WALL_DISPLAY_MODELS,
114111
),
115112
ShellyButtonDescription[ShellyRpcCoordinator](
116113
key="turn_off_screen",
117-
name="Turn off the screen",
114+
translation_key="turn_off_the_screen",
118115
press_action="wall_display_set_screen",
119116
params={"value": False},
120117
supported=lambda coordinator: coordinator.model in SHELLY_WALL_DISPLAY_MODELS,
@@ -347,7 +344,7 @@ def __init__(
347344
coordinator: ShellyRpcCoordinator,
348345
key: str,
349346
attribute: str,
350-
description: RpcEntityDescription,
347+
description: RpcButtonDescription,
351348
) -> None:
352349
"""Initialize button."""
353350
super().__init__(coordinator, key, attribute, description)
@@ -361,6 +358,9 @@ def __init__(
361358
config, ble_addr, coordinator.mac, fw_ver
362359
)
363360

361+
if hasattr(self, "_attr_name") and description.role != ROLE_GENERIC:
362+
delattr(self, "_attr_name")
363+
364364
@rpc_call
365365
async def async_press(self) -> None:
366366
"""Triggers the Shelly button press service."""
@@ -373,6 +373,19 @@ class RpcVirtualButton(ShellyRpcAttributeEntity, ButtonEntity):
373373
entity_description: RpcButtonDescription
374374
_id: int
375375

376+
def __init__(
377+
self,
378+
coordinator: ShellyRpcCoordinator,
379+
key: str,
380+
attribute: str,
381+
description: RpcButtonDescription,
382+
) -> None:
383+
"""Initialize select."""
384+
super().__init__(coordinator, key, attribute, description)
385+
386+
if hasattr(self, "_attr_name") and description.role != ROLE_GENERIC:
387+
delattr(self, "_attr_name")
388+
376389
@rpc_call
377390
async def async_press(self) -> None:
378391
"""Triggers the Shelly button press service."""
@@ -387,6 +400,20 @@ class RpcSleepingSmokeMuteButton(ShellySleepingRpcAttributeEntity, ButtonEntity)
387400

388401
entity_description: RpcButtonDescription
389402

403+
def __init__(
404+
self,
405+
coordinator: ShellyRpcCoordinator,
406+
key: str,
407+
attribute: str,
408+
description: RpcButtonDescription,
409+
entry: RegistryEntry | None = None,
410+
) -> None:
411+
"""Initialize the sleeping sensor."""
412+
super().__init__(coordinator, key, attribute, description, entry)
413+
414+
if hasattr(self, "_attr_name"):
415+
delattr(self, "_attr_name")
416+
390417
@rpc_call
391418
async def async_press(self) -> None:
392419
"""Triggers the Shelly button press service."""
@@ -414,19 +441,20 @@ def available(self) -> bool:
414441
),
415442
"button_open": RpcButtonDescription(
416443
key="button",
444+
translation_key="open",
417445
entity_registry_enabled_default=False,
418446
role="open",
419447
models={MODEL_FRANKEVER_WATER_VALVE},
420448
),
421449
"button_close": RpcButtonDescription(
422450
key="button",
451+
translation_key="close",
423452
entity_registry_enabled_default=False,
424453
role="close",
425454
models={MODEL_FRANKEVER_WATER_VALVE},
426455
),
427456
"calibrate": RpcButtonDescription(
428457
key="blutrv",
429-
name="Calibrate",
430458
translation_key="calibrate",
431459
entity_category=EntityCategory.CONFIG,
432460
entity_class=ShellyBluTrvButton,
@@ -435,7 +463,6 @@ def available(self) -> bool:
435463
"smoke_mute": RpcButtonDescription(
436464
key="smoke",
437465
sub_key="mute",
438-
name="Mute alarm",
439-
translation_key="mute",
466+
translation_key="mute_alarm",
440467
),
441468
}

homeassistant/components/shelly/icons.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"entity": {
33
"button": {
4-
"mute": {
4+
"mute_alarm": {
55
"default": "mdi:volume-mute"
66
},
77
"self_test": {
88
"default": "mdi:progress-wrench"
99
},
10-
"unmute": {
10+
"unmute_alarm": {
1111
"default": "mdi:volume-high"
1212
}
1313
},

homeassistant/components/shelly/strings.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,32 @@
129129
}
130130
},
131131
"entity": {
132+
"button": {
133+
"calibrate": {
134+
"name": "Calibrate"
135+
},
136+
"close": {
137+
"name": "Close"
138+
},
139+
"mute_alarm": {
140+
"name": "Mute alarm"
141+
},
142+
"open": {
143+
"name": "Open"
144+
},
145+
"self_test": {
146+
"name": "Self-test"
147+
},
148+
"turn_off_the_screen": {
149+
"name": "Turn off the screen"
150+
},
151+
"turn_on_the_screen": {
152+
"name": "Turn on the screen"
153+
},
154+
"unmute_alarm": {
155+
"name": "Unmute alarm"
156+
}
157+
},
132158
"climate": {
133159
"thermostat": {
134160
"state_attributes": {

tests/components/shelly/snapshots/test_button.ambr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@
174174
'previous_unique_id': None,
175175
'suggested_object_id': None,
176176
'supported_features': 0,
177-
'translation_key': None,
177+
'translation_key': 'turn_off_the_screen',
178178
'unique_id': '123456789ABC-turn_off_screen',
179179
'unit_of_measurement': None,
180180
})
@@ -222,7 +222,7 @@
222222
'previous_unique_id': None,
223223
'suggested_object_id': None,
224224
'supported_features': 0,
225-
'translation_key': None,
225+
'translation_key': 'turn_on_the_screen',
226226
'unique_id': '123456789ABC-turn_on_screen',
227227
'unit_of_measurement': None,
228228
})

tests/components/shelly/snapshots/test_devices.ambr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5519,7 +5519,7 @@
55195519
'previous_unique_id': None,
55205520
'suggested_object_id': None,
55215521
'supported_features': 0,
5522-
'translation_key': None,
5522+
'translation_key': 'turn_off_the_screen',
55235523
'unique_id': '123456789ABC-turn_off_screen',
55245524
'unit_of_measurement': None,
55255525
})
@@ -5567,7 +5567,7 @@
55675567
'previous_unique_id': None,
55685568
'suggested_object_id': None,
55695569
'supported_features': 0,
5570-
'translation_key': None,
5570+
'translation_key': 'turn_on_the_screen',
55715571
'unique_id': '123456789ABC-turn_on_screen',
55725572
'unit_of_measurement': None,
55735573
})

0 commit comments

Comments
 (0)