2424from homeassistant .helpers .update_coordinator import CoordinatorEntity
2525
2626from .const import (
27+ CONF_SLEEP_PERIOD ,
2728 DOMAIN ,
2829 LOGGER ,
2930 MODEL_FRANKEVER_WATER_VALVE ,
3435from .entity import (
3536 RpcEntityDescription ,
3637 ShellyRpcAttributeEntity ,
38+ ShellySleepingRpcAttributeEntity ,
3739 async_setup_entry_rpc ,
3840 get_entity_block_device_info ,
3941 get_entity_rpc_device_info ,
@@ -190,9 +192,10 @@ async def async_setup_entry(
190192 if TYPE_CHECKING :
191193 assert coordinator is not None
192194
193- await er .async_migrate_entries (
194- hass , config_entry .entry_id , partial (async_migrate_unique_ids , coordinator )
195- )
195+ if coordinator .device .initialized :
196+ await er .async_migrate_entries (
197+ hass , config_entry .entry_id , partial (async_migrate_unique_ids , coordinator )
198+ )
196199
197200 entities : list [ShellyButton ] = []
198201
@@ -208,22 +211,31 @@ async def async_setup_entry(
208211 return
209212
210213 # add RPC buttons
211- async_setup_entry_rpc (
212- hass , config_entry , async_add_entities , RPC_BUTTONS , RpcVirtualButton
213- )
214+ if config_entry .data [CONF_SLEEP_PERIOD ]:
215+ async_setup_entry_rpc (
216+ hass ,
217+ config_entry ,
218+ async_add_entities ,
219+ RPC_BUTTONS ,
220+ RpcSleepingSmokeMuteButton ,
221+ )
222+ else :
223+ async_setup_entry_rpc (
224+ hass , config_entry , async_add_entities , RPC_BUTTONS , RpcVirtualButton
225+ )
214226
215- # the user can remove virtual components from the device configuration, so
216- # we need to remove orphaned entities
217- virtual_button_component_ids = get_virtual_component_ids (
218- coordinator .device .config , BUTTON_PLATFORM
219- )
220- async_remove_orphaned_entities (
221- hass ,
222- config_entry .entry_id ,
223- coordinator .mac ,
224- BUTTON_PLATFORM ,
225- virtual_button_component_ids ,
226- )
227+ # the user can remove virtual components from the device configuration, so
228+ # we need to remove orphaned entities
229+ virtual_button_component_ids = get_virtual_component_ids (
230+ coordinator .device .config , BUTTON_PLATFORM
231+ )
232+ async_remove_orphaned_entities (
233+ hass ,
234+ config_entry .entry_id ,
235+ coordinator .mac ,
236+ BUTTON_PLATFORM ,
237+ virtual_button_component_ids ,
238+ )
227239
228240
229241class ShellyBaseButton (
@@ -354,6 +366,31 @@ async def async_press(self) -> None:
354366 await self .coordinator .device .button_trigger (self ._id , "single_push" )
355367
356368
369+ class RpcSleepingSmokeMuteButton (ShellySleepingRpcAttributeEntity , ButtonEntity ):
370+ """Defines a Shelly RPC Smoke mute alarm button."""
371+
372+ entity_description : RpcButtonDescription
373+
374+ @rpc_call
375+ async def async_press (self ) -> None :
376+ """Triggers the Shelly button press service."""
377+ if TYPE_CHECKING :
378+ assert isinstance (self .coordinator , ShellyRpcCoordinator )
379+
380+ _id = int (self .key .split (":" )[- 1 ])
381+ await self .coordinator .device .smoke_mute_alarm (_id )
382+
383+ @property
384+ def available (self ) -> bool :
385+ """Available."""
386+ available = super ().available
387+
388+ if self .coordinator .device .initialized :
389+ return available and self .status ["alarm" ]
390+
391+ return False
392+
393+
357394RPC_BUTTONS = {
358395 "button_generic" : RpcButtonDescription (
359396 key = "button" ,
@@ -379,4 +416,10 @@ async def async_press(self) -> None:
379416 entity_class = ShellyBluTrvButton ,
380417 models = {MODEL_BLU_GATEWAY_G3 },
381418 ),
419+ "smoke_mute" : RpcButtonDescription (
420+ key = "smoke" ,
421+ sub_key = "mute" ,
422+ name = "Mute alarm" ,
423+ translation_key = "mute" ,
424+ ),
382425}
0 commit comments