diff --git a/custom_components/dash_cast/__init__.py b/custom_components/dash_cast/__init__.py index 13a66c5..4b86397 100644 --- a/custom_components/dash_cast/__init__.py +++ b/custom_components/dash_cast/__init__.py @@ -1,3 +1,4 @@ +import voluptuous as vol from homeassistant.config_entries import ConfigEntry from homeassistant.const import ATTR_ENTITY_ID from homeassistant.core import ServiceCall, HomeAssistant @@ -8,19 +9,21 @@ DOMAIN = "dash_cast" -CONFIG_SCHEMA = cv.empty_config_schema(DOMAIN) +LOAD_URL_SCHEMA = cv.make_entity_service_schema( + { + vol.Required("url"): cv.string, + vol.Optional("force", default=False): cv.boolean, + vol.Optional("reload_seconds", default=0): cv.positive_int, + } +) async def async_setup(hass: HomeAssistant, config: dict) -> bool: dashs = {} async def play_media(call: ServiceCall): - entity_ids = call.data.get(ATTR_ENTITY_ID) - kwargs = { - k: v - for k, v in call.data.items() - if k in ("url", "force", "reload_seconds") - } + kwargs = dict(call.data) + entity_ids = kwargs.pop(ATTR_ENTITY_ID) for entity in hass.data[DATA_INSTANCES]["media_player"].entities: if entity.entity_id not in entity_ids: @@ -37,7 +40,7 @@ async def play_media(call: ServiceCall): dash.load_url(**kwargs) - hass.services.async_register(DOMAIN, "load_url", play_media) + hass.services.async_register(DOMAIN, "load_url", play_media, LOAD_URL_SCHEMA) return True