Merge pull request #212 from rmkraus/dev

IGNORE_CEC Parameter for Cast device
This commit is contained in:
Paulus Schoutsen 2015-07-10 21:16:36 -07:00
commit 8363757f1c
2 changed files with 17 additions and 3 deletions

View File

@ -25,10 +25,12 @@ from homeassistant.components.media_player import (
SUPPORT_PREVIOUS_TRACK, SUPPORT_NEXT_TRACK, SUPPORT_PREVIOUS_TRACK, SUPPORT_NEXT_TRACK,
MEDIA_TYPE_MUSIC, MEDIA_TYPE_TVSHOW, MEDIA_TYPE_VIDEO) MEDIA_TYPE_MUSIC, MEDIA_TYPE_TVSHOW, MEDIA_TYPE_VIDEO)
CONF_IGNORE_CEC = 'ignore_cec'
CAST_SPLASH = 'https://home-assistant.io/images/cast/splash.png' CAST_SPLASH = 'https://home-assistant.io/images/cast/splash.png'
SUPPORT_CAST = SUPPORT_PAUSE | SUPPORT_VOLUME_SET | SUPPORT_VOLUME_MUTE | \ SUPPORT_CAST = SUPPORT_PAUSE | SUPPORT_VOLUME_SET | SUPPORT_VOLUME_MUTE | \
SUPPORT_TURN_ON | SUPPORT_TURN_OFF | SUPPORT_PREVIOUS_TRACK | \ SUPPORT_TURN_ON | SUPPORT_TURN_OFF | SUPPORT_PREVIOUS_TRACK | \
SUPPORT_NEXT_TRACK | SUPPORT_YOUTUBE SUPPORT_NEXT_TRACK | SUPPORT_YOUTUBE
KNOWN_HOSTS = []
# pylint: disable=unused-argument # pylint: disable=unused-argument
@ -43,12 +45,22 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
return False return False
if discovery_info: # import CEC IGNORE attributes
ignore_cec = config.get(CONF_IGNORE_CEC, [])
if isinstance(ignore_cec, list):
pychromecast.IGNORE_CEC += ignore_cec
else:
logger.error('Chromecast conig, %s must be a list.', CONF_IGNORE_CEC)
hosts = []
if discovery_info and discovery_info[0] not in KNOWN_HOSTS:
hosts = [discovery_info[0]] hosts = [discovery_info[0]]
else: else:
hosts = (host_port[0] for host_port hosts = (host_port[0] for host_port
in pychromecast.discover_chromecasts()) in pychromecast.discover_chromecasts()
if host_port[0] not in KNOWN_HOSTS)
casts = [] casts = []
@ -57,6 +69,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
casts.append(CastDevice(host)) casts.append(CastDevice(host))
except pychromecast.ChromecastConnectionError: except pychromecast.ChromecastConnectionError:
pass pass
else:
KNOWN_HOSTS.append(host)
add_devices(casts) add_devices(casts)

View File

@ -18,7 +18,7 @@ phue>=0.8
ledcontroller>=1.0.7 ledcontroller>=1.0.7
# Chromecast bindings (media_player.cast) # Chromecast bindings (media_player.cast)
pychromecast>=0.6.6 pychromecast>=0.6.9
# Keyboard (keyboard) # Keyboard (keyboard)
pyuserinput>=0.1.9 pyuserinput>=0.1.9