Add option to set fixed hosts for chromecasts instead of discovery
parent
f4c77c85bd
commit
3757ddf9df
|
@ -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]
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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 = {}
|
||||
|
||||
|
|
Loading…
Reference in New Issue