add volumio discovery (#14220)

* add volumio discovery

* add missing library

* Update volumio.py
pull/14229/head
escoand 2018-05-01 21:20:38 +02:00 committed by Paulus Schoutsen
parent 2f0fc0934f
commit 8d5c3a2b91
2 changed files with 26 additions and 4 deletions

View File

@ -79,6 +79,7 @@ SERVICE_HANDLERS = {
'bluesound': ('media_player', 'bluesound'),
'songpal': ('media_player', 'songpal'),
'kodi': ('media_player', 'kodi'),
'volumio': ('media_player', 'volumio'),
}
OPTIONAL_SERVICE_HANDLERS = {

View File

@ -8,6 +8,7 @@ Volumio rest API: https://volumio.github.io/docs/API/REST_API.html
"""
from datetime import timedelta
import logging
import socket
import asyncio
import aiohttp
@ -31,6 +32,8 @@ DEFAULT_HOST = 'localhost'
DEFAULT_NAME = 'Volumio'
DEFAULT_PORT = 3000
DATA_VOLUMIO = 'volumio'
TIMEOUT = 10
SUPPORT_VOLUMIO = SUPPORT_PAUSE | SUPPORT_VOLUME_SET | SUPPORT_VOLUME_MUTE | \
@ -50,11 +53,29 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
@asyncio.coroutine
def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
"""Set up the Volumio platform."""
host = config.get(CONF_HOST)
port = config.get(CONF_PORT)
name = config.get(CONF_NAME)
if DATA_VOLUMIO not in hass.data:
hass.data[DATA_VOLUMIO] = dict()
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):