From 2d29959a521684f43a6bbeeac7daf3712bc6a750 Mon Sep 17 00:00:00 2001 From: mountainsandcode Date: Mon, 17 May 2021 11:12:01 +0200 Subject: [PATCH] Add control of hardware buttons to Sonos (#49977) --- homeassistant/components/sonos/media_player.py | 6 ++++++ homeassistant/components/sonos/services.yaml | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/homeassistant/components/sonos/media_player.py b/homeassistant/components/sonos/media_player.py index 051a9e29e81..06b9c49257a 100644 --- a/homeassistant/components/sonos/media_player.py +++ b/homeassistant/components/sonos/media_player.py @@ -119,6 +119,7 @@ ATTR_ENABLED = "enabled" ATTR_INCLUDE_LINKED_ZONES = "include_linked_zones" ATTR_MASTER = "master" ATTR_WITH_GROUP = "with_group" +ATTR_BUTTONS_ENABLED = "buttons_enabled" ATTR_NIGHT_SOUND = "night_sound" ATTR_SPEECH_ENHANCE = "speech_enhance" ATTR_QUEUE_POSITION = "queue_position" @@ -229,6 +230,7 @@ async def async_setup_entry( platform.async_register_entity_service( # type: ignore SERVICE_SET_OPTION, { + vol.Optional(ATTR_BUTTONS_ENABLED): cv.boolean, vol.Optional(ATTR_NIGHT_SOUND): cv.boolean, vol.Optional(ATTR_SPEECH_ENHANCE): cv.boolean, vol.Optional(ATTR_STATUS_LIGHT): cv.boolean, @@ -605,11 +607,15 @@ class SonosMediaPlayerEntity(SonosEntity, MediaPlayerEntity): @soco_error() def set_option( self, + buttons_enabled: bool | None = None, night_sound: bool | None = None, speech_enhance: bool | None = None, status_light: bool | None = None, ) -> None: """Modify playback options.""" + if buttons_enabled is not None: + self.soco.buttons_enabled = buttons_enabled + if night_sound is not None and self.speaker.night_mode is not None: self.soco.night_mode = night_sound diff --git a/homeassistant/components/sonos/services.yaml b/homeassistant/components/sonos/services.yaml index 0fee089d114..09197fb87ae 100644 --- a/homeassistant/components/sonos/services.yaml +++ b/homeassistant/components/sonos/services.yaml @@ -103,6 +103,12 @@ set_option: device: integration: sonos fields: + buttons_enabled: + name: Buttons enabled + description: Enable control buttons on the device + example: "true" + selector: + boolean: night_sound: name: Night sound description: Enable Night Sound mode