Add kef supports_on option (#30937)
* add supports_on_off option * modify support_kef inplace * all speakers support turning off remotely
This commit is contained in:
parent
a634e62dfc
commit
a010577d6e
3 changed files with 23 additions and 13 deletions
|
@ -4,5 +4,5 @@
|
|||
"documentation": "https://www.home-assistant.io/integrations/kef",
|
||||
"dependencies": [],
|
||||
"codeowners": ["@basnijholt"],
|
||||
"requirements": ["aiokef==0.2.5", "getmac==0.8.1"]
|
||||
"requirements": ["aiokef==0.2.6", "getmac==0.8.1"]
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ from functools import partial
|
|||
import ipaddress
|
||||
import logging
|
||||
|
||||
from aiokef.aiokef import AsyncKefSpeaker
|
||||
from aiokef import AsyncKefSpeaker
|
||||
from getmac import get_mac_address
|
||||
import voluptuous as vol
|
||||
|
||||
|
@ -36,6 +36,7 @@ DEFAULT_PORT = 50001
|
|||
DEFAULT_MAX_VOLUME = 0.5
|
||||
DEFAULT_VOLUME_STEP = 0.05
|
||||
DEFAULT_INVERSE_SPEAKER_MODE = False
|
||||
DEFAULT_SUPPORTS_ON = True
|
||||
|
||||
DOMAIN = "kef"
|
||||
|
||||
|
@ -44,18 +45,10 @@ SCAN_INTERVAL = timedelta(seconds=30)
|
|||
SOURCES = {"LSX": ["Wifi", "Bluetooth", "Aux", "Opt"]}
|
||||
SOURCES["LS50"] = SOURCES["LSX"] + ["Usb"]
|
||||
|
||||
SUPPORT_KEF = (
|
||||
SUPPORT_VOLUME_SET
|
||||
| SUPPORT_VOLUME_STEP
|
||||
| SUPPORT_VOLUME_MUTE
|
||||
| SUPPORT_SELECT_SOURCE
|
||||
| SUPPORT_TURN_OFF
|
||||
| SUPPORT_TURN_ON
|
||||
)
|
||||
|
||||
CONF_MAX_VOLUME = "maximum_volume"
|
||||
CONF_VOLUME_STEP = "volume_step"
|
||||
CONF_INVERSE_SPEAKER_MODE = "inverse_speaker_mode"
|
||||
CONF_SUPPORTS_ON = "supports_on"
|
||||
CONF_STANDBY_TIME = "standby_time"
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
|
@ -69,6 +62,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|||
vol.Optional(
|
||||
CONF_INVERSE_SPEAKER_MODE, default=DEFAULT_INVERSE_SPEAKER_MODE
|
||||
): cv.boolean,
|
||||
vol.Optional(CONF_SUPPORTS_ON, default=DEFAULT_SUPPORTS_ON): cv.boolean,
|
||||
vol.Optional(CONF_STANDBY_TIME): vol.In([20, 60]),
|
||||
}
|
||||
)
|
||||
|
@ -86,6 +80,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
|||
maximum_volume = config[CONF_MAX_VOLUME]
|
||||
volume_step = config[CONF_VOLUME_STEP]
|
||||
inverse_speaker_mode = config[CONF_INVERSE_SPEAKER_MODE]
|
||||
supports_on = config[CONF_SUPPORTS_ON]
|
||||
standby_time = config.get(CONF_STANDBY_TIME)
|
||||
|
||||
sources = SOURCES[speaker_type]
|
||||
|
@ -117,6 +112,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
|||
volume_step,
|
||||
standby_time,
|
||||
inverse_speaker_mode,
|
||||
supports_on,
|
||||
sources,
|
||||
ioloop=hass.loop,
|
||||
unique_id=unique_id,
|
||||
|
@ -141,6 +137,7 @@ class KefMediaPlayer(MediaPlayerDevice):
|
|||
volume_step,
|
||||
standby_time,
|
||||
inverse_speaker_mode,
|
||||
supports_on,
|
||||
sources,
|
||||
ioloop,
|
||||
unique_id,
|
||||
|
@ -158,6 +155,7 @@ class KefMediaPlayer(MediaPlayerDevice):
|
|||
ioloop=ioloop,
|
||||
)
|
||||
self._unique_id = unique_id
|
||||
self._supports_on = supports_on
|
||||
|
||||
self._state = None
|
||||
self._muted = None
|
||||
|
@ -210,7 +208,17 @@ class KefMediaPlayer(MediaPlayerDevice):
|
|||
@property
|
||||
def supported_features(self):
|
||||
"""Flag media player features that are supported."""
|
||||
return SUPPORT_KEF
|
||||
support_kef = (
|
||||
SUPPORT_VOLUME_SET
|
||||
| SUPPORT_VOLUME_STEP
|
||||
| SUPPORT_VOLUME_MUTE
|
||||
| SUPPORT_SELECT_SOURCE
|
||||
| SUPPORT_TURN_OFF
|
||||
)
|
||||
if self._supports_on:
|
||||
support_kef |= SUPPORT_TURN_ON
|
||||
|
||||
return support_kef
|
||||
|
||||
@property
|
||||
def source(self):
|
||||
|
@ -243,6 +251,8 @@ class KefMediaPlayer(MediaPlayerDevice):
|
|||
|
||||
async def async_turn_on(self):
|
||||
"""Turn the media player on."""
|
||||
if not self._supports_on:
|
||||
raise NotImplementedError()
|
||||
await self._speaker.turn_on()
|
||||
|
||||
async def async_volume_up(self):
|
||||
|
|
|
@ -172,7 +172,7 @@ aioimaplib==0.7.15
|
|||
aiokafka==0.5.1
|
||||
|
||||
# homeassistant.components.kef
|
||||
aiokef==0.2.5
|
||||
aiokef==0.2.6
|
||||
|
||||
# homeassistant.components.lifx
|
||||
aiolifx==0.6.7
|
||||
|
|
Loading…
Add table
Reference in a new issue