Add tests for sonos switch platform (#51142)
* add tests * refactor async_added_to_hass * fix tests and race condition * use async_get * typo
This commit is contained in:
parent
7dff4d6ad7
commit
f7f8672eea
4 changed files with 84 additions and 19 deletions
|
@ -43,11 +43,6 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||
entity = SonosAlarmEntity(alarm_id, speaker)
|
||||
async_add_entities([entity])
|
||||
configured_alarms.add(alarm_id)
|
||||
config_entry.async_on_unload(
|
||||
async_dispatcher_connect(
|
||||
hass, SONOS_ALARM_UPDATE, entity.async_update
|
||||
)
|
||||
)
|
||||
|
||||
config_entry.async_on_unload(
|
||||
async_dispatcher_connect(hass, SONOS_CREATE_ALARM, _async_create_entity)
|
||||
|
@ -64,9 +59,20 @@ class SonosAlarmEntity(SonosEntity, SwitchEntity):
|
|||
self._alarm_id = alarm_id
|
||||
self.entity_id = ENTITY_ID_FORMAT.format(f"sonos_alarm_{self.alarm_id}")
|
||||
|
||||
async def async_added_to_hass(self) -> None:
|
||||
"""Handle switch setup when added to hass."""
|
||||
await super().async_added_to_hass()
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass,
|
||||
SONOS_ALARM_UPDATE,
|
||||
self.async_update,
|
||||
)
|
||||
)
|
||||
|
||||
@property
|
||||
def alarm(self):
|
||||
"""Return the ID of the alarm."""
|
||||
"""Return the alarm instance."""
|
||||
return self.hass.data[DATA_SONOS].alarms[self.alarm_id]
|
||||
|
||||
@property
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue