1
mirror of https://github.com/home-assistant/core synced 2024-07-12 07:21:24 +02:00

Add option to set fixed hosts for chromecasts instead of discovery

This commit is contained in:
Paulus Schoutsen 2014-04-21 17:58:58 -07:00
parent f4c77c85bd
commit 3757ddf9df
3 changed files with 17 additions and 4 deletions

View File

@ -20,6 +20,8 @@ username=admin
password=PASSWORD
[chromecast]
# Optional: hard code the hosts to find chromecasts instead of scanning the network
# hosts=192.168.1.9,192.168.1.12
[wemo]

View File

@ -54,6 +54,13 @@ def from_config_file(config_path):
except (configparser.NoSectionError, configparser.NoOptionError):
return default
def get_hosts(section):
""" Helper method to retrieve hosts from config. """
if has_opt(section, "hosts"):
return get_opt(section, "hosts").split(",")
else:
return None
# Device scanner
dev_scan = None
@ -122,7 +129,9 @@ def from_config_file(config_path):
if has_section("chromecast"):
chromecast = load_module('chromecast')
chromecast_started = chromecast.setup(bus, statemachine)
hosts = get_hosts("chromecast")
chromecast_started = chromecast.setup(bus, statemachine, hosts)
add_status("Chromecast", chromecast_started)
else:

View File

@ -88,7 +88,7 @@ def media_prev_track(bus, entity_id=None):
# pylint: disable=too-many-locals, too-many-branches
def setup(bus, statemachine):
def setup(bus, statemachine, hosts=None):
""" Listen for chromecast events. """
logger = logging.getLogger(__name__)
@ -101,8 +101,10 @@ def setup(bus, statemachine):
return False
logger.info("Scanning for Chromecasts")
hosts = pychromecast.discover_chromecasts()
# If no hosts given, scan for chromecasts
if not hosts:
logger.info("Scanning for Chromecasts")
hosts = pychromecast.discover_chromecasts()
casts = {}