Backport #66399 to rc (#66625)

pull/66624/head
jjlawren 2022-02-15 20:02:45 -06:00 committed by GitHub
parent 6aa99d1063
commit 7d2e42d026
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 7 deletions

View File

@ -23,7 +23,7 @@ UID_POSTFIX = "01400"
_LOGGER = logging.getLogger(__name__)
_T = TypeVar("_T", "SonosSpeaker", "SonosEntity")
_T = TypeVar("_T", bound="SonosSpeaker | SonosEntity")
_R = TypeVar("_R")
_P = ParamSpec("_P")

View File

@ -3,6 +3,7 @@ from __future__ import annotations
import datetime
import logging
from typing import Any
from soco.exceptions import SoCoException, SoCoSlaveException, SoCoUPnPException
@ -342,20 +343,20 @@ class SonosAlarmEntity(SonosEntity, SwitchEntity):
ATTR_INCLUDE_LINKED_ZONES: self.alarm.include_linked_zones,
}
async def async_turn_on(self, **kwargs) -> None:
def turn_on(self, **kwargs: Any) -> None:
"""Turn alarm switch on."""
await self.async_handle_switch_on_off(turn_on=True)
self._handle_switch_on_off(turn_on=True)
async def async_turn_off(self, **kwargs) -> None:
def turn_off(self, **kwargs: Any) -> None:
"""Turn alarm switch off."""
await self.async_handle_switch_on_off(turn_on=False)
self._handle_switch_on_off(turn_on=False)
async def async_handle_switch_on_off(self, turn_on: bool) -> None:
def _handle_switch_on_off(self, turn_on: bool) -> None:
"""Handle turn on/off of alarm switch."""
try:
_LOGGER.debug("Toggling the state of %s", self.entity_id)
self.alarm.enabled = turn_on
await self.hass.async_add_executor_job(self.alarm.save)
self.alarm.save()
except (OSError, SoCoException, SoCoUPnPException) as exc:
_LOGGER.error("Could not update %s: %s", self.entity_id, exc)