Skip to content

Instantly share code, notes, and snippets.

@raspberrypisig
Created September 4, 2020 02:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raspberrypisig/da9f88874734cb081334fae8fdee0a28 to your computer and use it in GitHub Desktop.
Save raspberrypisig/da9f88874734cb081334fae8fdee0a28 to your computer and use it in GitHub Desktop.
customcomponent-explorer_media
"""Example of a custom component exposing a service."""
import asyncio
import logging
from homeassistant.core import callback
# The domain of your component. Should be equal to the name of your component.
DOMAIN = "explorer_media"
_LOGGER = logging.getLogger(__name__)
@asyncio.coroutine
def async_setup(hass, config):
async def my_service(call):
"""My first service."""
_LOGGER.debug('Boo')
await hass.services.async_call('media_player','play_media', {'entity_id': 'media_player.rumpus_room_speaker','media_content_id': 'http://192.168.20.99:8002/test/topsecret/orinoco.mp3', 'media_content_type': 'music'})
# Register our service with Home Assistant.
hass.services.async_register(DOMAIN, 'first', my_service)
"""Setup our skeleton component."""
# States are in the format DOMAIN.OBJECT_ID.
hass.states.async_set('explorer_media.status', 'Works!')
# Return boolean to indicate that initialization was successfully.
return True
{
"domain": "explorer_media",
"name": "WWW Network Media Explorer",
"documentation": "https://example.com",
"dependencies": ["media_player"],
"codeowners": [],
"requirements": []
}
first:
description: First Service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment