Upgrade Russound integration to v0.1.7 (#5756)

* Bumped up version to use 0.1.7 of Russound integration module.
Fixed bug arising from not supporting TURN_ON state (fixes issue https://github.com/home-assistant/home-assistant/issues/5012)
Implemented state support in 0.1.7 such that component state is returned from the actual AMP. (Still uses polling model though).
Tested it with home-assitant users @laf (original developer of the module) and @hofsta.  Works fine with their Russounds.

* Made styling / compliance changes and updated correct version of russound module on requirements_all.txt.

* Changed handling of properties to be compliant with https://github.com/home-assistant/home-assistant/issues/4210
(Specifcailly added member variables for state, volume and source to cache these values, and introduced Update() method to set their values).

Now returns None if the selected source index that is returned from russound is greater than the length of the specified source list in the yaml config.
Removed unnecesary comment.

* Removed blank line after docstring.

* Removed updated() in class init and added True paramter to add_devices in setup_platform.

* Dropped the no longer needed self.update()
This commit is contained in:
Andreas Cambitsis 2017-02-08 22:53:59 +02:00 committed by Adam Mills
parent 061985bc65
commit 4f20a2d3ea
2 changed files with 51 additions and 19 deletions

View File

@ -4,20 +4,20 @@ Support for interfacing with Russound via RNET Protocol.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/media_player.russound_rnet/
"""
import logging
import logging
import voluptuous as vol
from homeassistant.components.media_player import (
SUPPORT_TURN_OFF, SUPPORT_VOLUME_MUTE, SUPPORT_VOLUME_SET,
SUPPORT_SELECT_SOURCE, SUPPORT_PLAY, MediaPlayerDevice, PLATFORM_SCHEMA)
SUPPORT_TURN_ON, SUPPORT_TURN_OFF, SUPPORT_VOLUME_MUTE, SUPPORT_VOLUME_SET,
SUPPORT_SELECT_SOURCE, MediaPlayerDevice, PLATFORM_SCHEMA)
from homeassistant.const import (
CONF_HOST, CONF_PORT, STATE_OFF, STATE_ON, CONF_NAME)
import homeassistant.helpers.config_validation as cv
REQUIREMENTS = [
'https://github.com/laf/russound/archive/0.1.6.zip'
'#russound==0.1.6']
'https://github.com/laf/russound/archive/0.1.7.zip'
'#russound==0.1.7']
_LOGGER = logging.getLogger(__name__)
@ -25,7 +25,7 @@ CONF_ZONES = 'zones'
CONF_SOURCES = 'sources'
SUPPORT_RUSSOUND = SUPPORT_VOLUME_MUTE | SUPPORT_VOLUME_SET | \
SUPPORT_TURN_OFF | SUPPORT_SELECT_SOURCE | SUPPORT_PLAY
SUPPORT_TURN_ON | SUPPORT_TURN_OFF | SUPPORT_SELECT_SOURCE
ZONE_SCHEMA = vol.Schema({
vol.Required(CONF_NAME): cv.string,
@ -48,7 +48,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the Russound RNET platform."""
host = config.get(CONF_HOST)
port = config.get(CONF_PORT)
keypad = config.get('keypad', '70')
if host is None or port is None:
_LOGGER.error("Invalid config. Expected %s and %s",
@ -58,7 +57,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
from russound import russound
russ = russound.Russound(host, port)
russ.connect(keypad)
russ.connect()
sources = []
for source in config[CONF_SOURCES]:
@ -67,7 +66,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
if russ.is_connected():
for zone_id, extra in config[CONF_ZONES].items():
add_devices([RussoundRNETDevice(
hass, russ, sources, zone_id, extra)])
hass, russ, sources, zone_id, extra)], True)
else:
_LOGGER.error('Not connected to %s:%s', host, port)
@ -79,10 +78,32 @@ class RussoundRNETDevice(MediaPlayerDevice):
"""Initialise the Russound RNET device."""
self._name = extra['name']
self._russ = russ
self._state = STATE_OFF
self._sources = sources
self._zone_id = zone_id
self._volume = 0
self._state = None
self._volume = None
self._source = None
def update(self):
"""Retrieve latest state."""
if self._russ.get_power('1', self._zone_id) == 0:
self._state = STATE_OFF
else:
self._state = STATE_ON
self._volume = self._russ.get_volume('1', self._zone_id) / 100.0
# Returns 0 based index for source.
index = self._russ.get_source('1', self._zone_id)
# Possibility exists that user has defined list of all sources.
# If a source is set externally that is beyond the defined list then
# an exception will be thrown.
# In this case return and unknown source (None)
try:
self._source = self._sources[index]
except IndexError:
self._source = None
@property
def name(self):
@ -99,25 +120,35 @@ class RussoundRNETDevice(MediaPlayerDevice):
"""Flag media player features that are supported."""
return SUPPORT_RUSSOUND
@property
def source(self):
"""Get the currently selected source."""
return self._source
@property
def volume_level(self):
"""Volume level of the media player (0..1)."""
"""Volume level of the media player (0..1).
Value is returned based on a range (0..100).
Therefore float divide by 100 to get to the required range.
"""
return self._volume
def set_volume_level(self, volume):
"""Set volume level, range 0..1."""
self._volume = volume * 100
self._russ.set_volume('1', self._zone_id, self._volume)
"""Set volume level. Volume has a range (0..1).
Translate this to a range of (0..100) as expected expected
by _russ.set_volume()
"""
self._russ.set_volume('1', self._zone_id, volume * 100)
def turn_on(self):
"""Turn the media player on."""
self._russ.set_power('1', self._zone_id, '1')
self._state = STATE_ON
def turn_off(self):
"""Turn off media player."""
self._russ.set_power('1', self._zone_id, '0')
self._state = STATE_OFF
def mute_volume(self, mute):
"""Send mute command."""
@ -126,7 +157,8 @@ class RussoundRNETDevice(MediaPlayerDevice):
def select_source(self, source):
"""Set the input source."""
if source in self._sources:
index = self._sources.index(source)+1
index = self._sources.index(source)
# 0 based value for source
self._russ.set_source('1', self._zone_id, index)
@property

View File

@ -236,7 +236,7 @@ https://github.com/jamespcole/home-assistant-nzb-clients/archive/616cad591540925
https://github.com/joopert/nad_receiver/archive/0.0.3.zip#nad_receiver==0.0.3
# homeassistant.components.media_player.russound_rnet
https://github.com/laf/russound/archive/0.1.6.zip#russound==0.1.6
https://github.com/laf/russound/archive/0.1.7.zip#russound==0.1.7
# homeassistant.components.switch.anel_pwrctrl
https://github.com/mweinelt/anel-pwrctrl/archive/ed26e8830e28a2bfa4260a9002db23ce3e7e63d7.zip#anel_pwrctrl==0.0.1