mirror of
https://github.com/home-assistant/core
synced 2024-08-06 09:34:49 +02:00
Add option to set fixed hosts for chromecasts instead of discovery
This commit is contained in:
parent
f4c77c85bd
commit
3757ddf9df
@ -20,6 +20,8 @@ username=admin
|
|||||||
password=PASSWORD
|
password=PASSWORD
|
||||||
|
|
||||||
[chromecast]
|
[chromecast]
|
||||||
|
# Optional: hard code the hosts to find chromecasts instead of scanning the network
|
||||||
|
# hosts=192.168.1.9,192.168.1.12
|
||||||
|
|
||||||
[wemo]
|
[wemo]
|
||||||
|
|
||||||
|
@ -54,6 +54,13 @@ def from_config_file(config_path):
|
|||||||
except (configparser.NoSectionError, configparser.NoOptionError):
|
except (configparser.NoSectionError, configparser.NoOptionError):
|
||||||
return default
|
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
|
# Device scanner
|
||||||
dev_scan = None
|
dev_scan = None
|
||||||
|
|
||||||
@ -122,7 +129,9 @@ def from_config_file(config_path):
|
|||||||
if has_section("chromecast"):
|
if has_section("chromecast"):
|
||||||
chromecast = load_module('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)
|
add_status("Chromecast", chromecast_started)
|
||||||
else:
|
else:
|
||||||
|
@ -88,7 +88,7 @@ def media_prev_track(bus, entity_id=None):
|
|||||||
|
|
||||||
|
|
||||||
# pylint: disable=too-many-locals, too-many-branches
|
# pylint: disable=too-many-locals, too-many-branches
|
||||||
def setup(bus, statemachine):
|
def setup(bus, statemachine, hosts=None):
|
||||||
""" Listen for chromecast events. """
|
""" Listen for chromecast events. """
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -101,8 +101,10 @@ def setup(bus, statemachine):
|
|||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
logger.info("Scanning for Chromecasts")
|
# If no hosts given, scan for chromecasts
|
||||||
hosts = pychromecast.discover_chromecasts()
|
if not hosts:
|
||||||
|
logger.info("Scanning for Chromecasts")
|
||||||
|
hosts = pychromecast.discover_chromecasts()
|
||||||
|
|
||||||
casts = {}
|
casts = {}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user