-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
32 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
|
||
__pycache__/ | ||
.idea/ | ||
|
||
.homeassistant/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,46 @@ | ||
from homeassistant.components.media_player import DOMAIN as MP_DOMAIN | ||
from homeassistant.config_entries import ConfigEntry | ||
from homeassistant.const import ATTR_ENTITY_ID | ||
from homeassistant.core import ServiceCall | ||
from homeassistant.core import ServiceCall, HomeAssistant | ||
from homeassistant.helpers import config_validation as cv | ||
from homeassistant.helpers.entity_component import DATA_INSTANCES | ||
|
||
from pychromecast import Chromecast | ||
from pychromecast.controllers.dashcast import DashCastController | ||
|
||
DOMAIN = 'dash_cast' | ||
DOMAIN = "dash_cast" | ||
|
||
CONFIG_SCHEMA = cv.empty_config_schema(DOMAIN) | ||
|
||
|
||
async def async_setup(hass, hass_config): | ||
async def async_setup(hass: HomeAssistant, config: dict) -> bool: | ||
dashs = {} | ||
|
||
async def play_media(call: ServiceCall): | ||
entity_ids = call.data.get(ATTR_ENTITY_ID) | ||
url = call.data.get('url') | ||
force = call.data.get('force', False) | ||
|
||
for entity in hass.data[DATA_INSTANCES][MP_DOMAIN].entities: | ||
if entity.entity_id in entity_ids: | ||
dash = dashs.get(entity.entity_id) | ||
if not dash: | ||
kwargs = { | ||
k: v | ||
for k, v in call.data.items() | ||
if k in ("url", "force", "reload_seconds") | ||
} | ||
|
||
for entity in hass.data[DATA_INSTANCES]["media_player"].entities: | ||
if entity.entity_id not in entity_ids: | ||
continue | ||
|
||
dash: DashCastController = dashs.get(entity.entity_id) | ||
if not dash: | ||
chromecast: Chromecast = getattr(entity, "_chromecast") | ||
if chromecast: | ||
dashs[entity.entity_id] = dash = DashCastController() | ||
entity._chromecast.register_handler(dash) | ||
dash.load_url(url, force=force) | ||
chromecast.register_handler(dash) | ||
else: | ||
return | ||
|
||
dash.load_url(**kwargs) | ||
|
||
hass.services.async_register(DOMAIN, 'load_url', play_media) | ||
hass.services.async_register(DOMAIN, "load_url", play_media) | ||
|
||
return True | ||
|
||
|
||
async def async_setup_entry(hass, entry): | ||
async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool: | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters