mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
add volumio discovery (#14220)
* add volumio discovery * add missing library * Update volumio.py
This commit is contained in:
parent
2f0fc0934f
commit
8d5c3a2b91
@ -79,6 +79,7 @@ SERVICE_HANDLERS = {
|
|||||||
'bluesound': ('media_player', 'bluesound'),
|
'bluesound': ('media_player', 'bluesound'),
|
||||||
'songpal': ('media_player', 'songpal'),
|
'songpal': ('media_player', 'songpal'),
|
||||||
'kodi': ('media_player', 'kodi'),
|
'kodi': ('media_player', 'kodi'),
|
||||||
|
'volumio': ('media_player', 'volumio'),
|
||||||
}
|
}
|
||||||
|
|
||||||
OPTIONAL_SERVICE_HANDLERS = {
|
OPTIONAL_SERVICE_HANDLERS = {
|
||||||
|
@ -8,6 +8,7 @@ Volumio rest API: https://volumio.github.io/docs/API/REST_API.html
|
|||||||
"""
|
"""
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
import socket
|
||||||
import asyncio
|
import asyncio
|
||||||
import aiohttp
|
import aiohttp
|
||||||
|
|
||||||
@ -31,6 +32,8 @@ DEFAULT_HOST = 'localhost'
|
|||||||
DEFAULT_NAME = 'Volumio'
|
DEFAULT_NAME = 'Volumio'
|
||||||
DEFAULT_PORT = 3000
|
DEFAULT_PORT = 3000
|
||||||
|
|
||||||
|
DATA_VOLUMIO = 'volumio'
|
||||||
|
|
||||||
TIMEOUT = 10
|
TIMEOUT = 10
|
||||||
|
|
||||||
SUPPORT_VOLUMIO = SUPPORT_PAUSE | SUPPORT_VOLUME_SET | SUPPORT_VOLUME_MUTE | \
|
SUPPORT_VOLUMIO = SUPPORT_PAUSE | SUPPORT_VOLUME_SET | SUPPORT_VOLUME_MUTE | \
|
||||||
@ -50,11 +53,29 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
|
def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
|
||||||
"""Set up the Volumio platform."""
|
"""Set up the Volumio platform."""
|
||||||
host = config.get(CONF_HOST)
|
if DATA_VOLUMIO not in hass.data:
|
||||||
port = config.get(CONF_PORT)
|
hass.data[DATA_VOLUMIO] = dict()
|
||||||
name = config.get(CONF_NAME)
|
|
||||||
|
|
||||||
async_add_devices([Volumio(name, host, port, hass)])
|
# This is a manual configuration?
|
||||||
|
if discovery_info is None:
|
||||||
|
name = config.get(CONF_NAME)
|
||||||
|
host = config.get(CONF_HOST)
|
||||||
|
port = config.get(CONF_PORT)
|
||||||
|
else:
|
||||||
|
name = "{} ({})".format(DEFAULT_NAME, discovery_info.get('hostname'))
|
||||||
|
host = discovery_info.get('host')
|
||||||
|
port = discovery_info.get('port')
|
||||||
|
|
||||||
|
# Only add a device once, so discovered devices do not override manual
|
||||||
|
# config.
|
||||||
|
ip_addr = socket.gethostbyname(host)
|
||||||
|
if ip_addr in hass.data[DATA_VOLUMIO]:
|
||||||
|
return
|
||||||
|
|
||||||
|
entity = Volumio(name, host, port, hass)
|
||||||
|
|
||||||
|
hass.data[DATA_VOLUMIO][ip_addr] = entity
|
||||||
|
async_add_devices([entity])
|
||||||
|
|
||||||
|
|
||||||
class Volumio(MediaPlayerDevice):
|
class Volumio(MediaPlayerDevice):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user