mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +00:00
More robust Chromecast observer code
This commit is contained in:
parent
bbe8f898dc
commit
0449022441
@ -159,10 +159,9 @@ def setup_chromecast(bus, statemachine, host):
|
|||||||
""" Listen for chromecast events. """
|
""" Listen for chromecast events. """
|
||||||
from homeassistant.packages import pychromecast
|
from homeassistant.packages import pychromecast
|
||||||
|
|
||||||
try:
|
device = pychromecast.get_device_status(host)
|
||||||
device = pychromecast.get_device_status(host)
|
|
||||||
except (requests.exceptions.RequestException,
|
if not device:
|
||||||
pychromecast.PyChromecastException):
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
category = STATE_CATEGORY_CHROMECAST_FORMAT.format(util.slugify(
|
category = STATE_CATEGORY_CHROMECAST_FORMAT.format(util.slugify(
|
||||||
@ -185,9 +184,12 @@ def setup_chromecast(bus, statemachine, host):
|
|||||||
""" Retrieve state of Chromecast and update statemachine. """
|
""" Retrieve state of Chromecast and update statemachine. """
|
||||||
status = pychromecast.get_app_status(host)
|
status = pychromecast.get_app_status(host)
|
||||||
|
|
||||||
statemachine.set_state(category, status.name,
|
if status:
|
||||||
{"state": status.state,
|
statemachine.set_state(category, status.name,
|
||||||
"options": status.options})
|
{"state": status.state,
|
||||||
|
"options": status.options})
|
||||||
|
else:
|
||||||
|
statemachine.set_state(category, "none")
|
||||||
|
|
||||||
ha.track_time_change(bus, update_chromecast_state)
|
ha.track_time_change(bus, update_chromecast_state)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user