mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Added a volume set option and autodiscovery functions to Denon AVR rece… (#4845)
* Added Volume Set option and autodiscovery functions to Denon AVR receivers * Corrected issues in SSDP discovery and in case no host could be discovered * Corrected discovery handling / added denonavr to discovery platform * No needless discoveries anymore / add_devices() with list instead of loop
This commit is contained in:
parent
6da3e23436
commit
dc551b825f
@ -14,7 +14,7 @@ import voluptuous as vol
|
||||
from homeassistant.const import EVENT_HOMEASSISTANT_START
|
||||
from homeassistant.helpers.discovery import load_platform, discover
|
||||
|
||||
REQUIREMENTS = ['netdisco==0.8.0']
|
||||
REQUIREMENTS = ['netdisco==0.8.1']
|
||||
|
||||
DOMAIN = 'discovery'
|
||||
|
||||
@ -36,6 +36,7 @@ SERVICE_HANDLERS = {
|
||||
'yamaha': ('media_player', 'yamaha'),
|
||||
'logitech_mediaserver': ('media_player', 'squeezebox'),
|
||||
'directv': ('media_player', 'directv'),
|
||||
'denonavr': ('media_player', 'denonavr'),
|
||||
}
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema({
|
||||
|
@ -13,26 +13,27 @@ from homeassistant.components.media_player import (
|
||||
SUPPORT_TURN_OFF, SUPPORT_VOLUME_MUTE, SUPPORT_VOLUME_STEP,
|
||||
SUPPORT_SELECT_SOURCE, SUPPORT_PLAY_MEDIA, MEDIA_TYPE_CHANNEL,
|
||||
MediaPlayerDevice, PLATFORM_SCHEMA, SUPPORT_TURN_ON,
|
||||
MEDIA_TYPE_MUSIC)
|
||||
MEDIA_TYPE_MUSIC, SUPPORT_VOLUME_SET)
|
||||
from homeassistant.const import (
|
||||
CONF_HOST, STATE_OFF, STATE_PLAYING, STATE_PAUSED,
|
||||
CONF_NAME, STATE_ON)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
||||
REQUIREMENTS = ['denonavr==0.1.6']
|
||||
REQUIREMENTS = ['denonavr==0.2.2']
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DEFAULT_NAME = None
|
||||
KEY_DENON_CACHE = 'denonavr_hosts'
|
||||
|
||||
SUPPORT_DENON = SUPPORT_VOLUME_STEP | SUPPORT_VOLUME_MUTE | \
|
||||
SUPPORT_TURN_ON | SUPPORT_TURN_OFF | \
|
||||
SUPPORT_SELECT_SOURCE | SUPPORT_PLAY_MEDIA | \
|
||||
SUPPORT_PAUSE | SUPPORT_PREVIOUS_TRACK | \
|
||||
SUPPORT_NEXT_TRACK
|
||||
SUPPORT_NEXT_TRACK | SUPPORT_VOLUME_SET
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
vol.Required(CONF_HOST): cv.string,
|
||||
vol.Optional(CONF_HOST): cv.string,
|
||||
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
||||
})
|
||||
|
||||
@ -41,11 +42,53 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Setup the Denon platform."""
|
||||
import denonavr
|
||||
|
||||
receiver = denonavr.DenonAVR(config.get(CONF_HOST), config.get(CONF_NAME))
|
||||
# Initialize list with receivers to be started
|
||||
receivers = []
|
||||
|
||||
add_devices([DenonDevice(receiver)])
|
||||
_LOGGER.info("Denon receiver at host %s initialized",
|
||||
config.get(CONF_HOST))
|
||||
cache = hass.data.get(KEY_DENON_CACHE)
|
||||
if cache is None:
|
||||
cache = hass.data[KEY_DENON_CACHE] = set()
|
||||
|
||||
# Start assignment of host and name
|
||||
# 1. option: manual setting
|
||||
if config.get(CONF_HOST) is not None:
|
||||
host = config.get(CONF_HOST)
|
||||
name = config.get(CONF_NAME)
|
||||
# Check if host not in cache, append it and save for later starting
|
||||
if host not in cache:
|
||||
cache.add(host)
|
||||
receivers.append(
|
||||
DenonDevice(denonavr.DenonAVR(host, name)))
|
||||
_LOGGER.info("Denon receiver at host %s initialized", host)
|
||||
# 2. option: discovery using netdisco
|
||||
if discovery_info is not None:
|
||||
host = discovery_info[0]
|
||||
name = discovery_info[1]
|
||||
# Check if host not in cache, append it and save for later starting
|
||||
if host not in cache:
|
||||
cache.add(host)
|
||||
receivers.append(
|
||||
DenonDevice(denonavr.DenonAVR(host, name)))
|
||||
_LOGGER.info("Denon receiver at host %s initialized", host)
|
||||
# 3. option: discovery using denonavr library
|
||||
if config.get(CONF_HOST) is None and discovery_info is None:
|
||||
d_receivers = denonavr.discover()
|
||||
# More than one receiver could be discovered by that method
|
||||
if d_receivers is not None:
|
||||
for d_receiver in d_receivers:
|
||||
host = d_receiver["host"]
|
||||
name = d_receiver["friendlyName"]
|
||||
# Check if host not in cache, append it and save for later
|
||||
# starting
|
||||
if host not in cache:
|
||||
cache.add(host)
|
||||
receivers.append(
|
||||
DenonDevice(denonavr.DenonAVR(host, name)))
|
||||
_LOGGER.info("Denon receiver at host %s initialized", host)
|
||||
|
||||
# Add all freshly discovered receivers
|
||||
if receivers:
|
||||
add_devices(receivers)
|
||||
|
||||
|
||||
class DenonDevice(MediaPlayerDevice):
|
||||
@ -107,7 +150,8 @@ class DenonDevice(MediaPlayerDevice):
|
||||
@property
|
||||
def volume_level(self):
|
||||
"""Volume level of the media player (0..1)."""
|
||||
# Volume is send in a format like -50.0. Minimum is around -80.0
|
||||
# Volume is sent in a format like -50.0. Minimum is -80.0,
|
||||
# maximum is 18.0
|
||||
return (float(self._volume) + 80) / 100
|
||||
|
||||
@property
|
||||
@ -240,6 +284,22 @@ class DenonDevice(MediaPlayerDevice):
|
||||
"""Volume down media player."""
|
||||
return self._receiver.volume_down()
|
||||
|
||||
def set_volume_level(self, volume):
|
||||
"""Set volume level, range 0..1."""
|
||||
# Volume has to be sent in a format like -50.0. Minimum is -80.0,
|
||||
# maximum is 18.0
|
||||
volume_denon = float((volume * 100) - 80)
|
||||
if volume_denon > 18:
|
||||
volume_denon = float(18)
|
||||
try:
|
||||
if self._receiver.set_volume(volume_denon):
|
||||
self._volume = volume_denon
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
except ValueError:
|
||||
return False
|
||||
|
||||
def mute_volume(self, mute):
|
||||
"""Send mute command."""
|
||||
return self._receiver.mute(mute)
|
||||
|
@ -76,7 +76,7 @@ colorlog>2.1,<3
|
||||
concord232==0.14
|
||||
|
||||
# homeassistant.components.media_player.denonavr
|
||||
denonavr==0.1.6
|
||||
denonavr==0.2.2
|
||||
|
||||
# homeassistant.components.media_player.directv
|
||||
directpy==0.1
|
||||
@ -302,7 +302,7 @@ mficlient==0.3.0
|
||||
miflora==0.1.13
|
||||
|
||||
# homeassistant.components.discovery
|
||||
netdisco==0.8.0
|
||||
netdisco==0.8.1
|
||||
|
||||
# homeassistant.components.sensor.neurio_energy
|
||||
neurio==0.2.10
|
||||
|
Loading…
x
Reference in New Issue
Block a user