Add discovery support to HEOS component (#22652)
* Add discovery entry point * Fix test * Correct test call method * Update netdisco to 2.6.0
This commit is contained in:
parent
471afb4702
commit
5651db4b5c
4 changed files with 35 additions and 3 deletions
|
@ -20,7 +20,7 @@ from homeassistant.helpers.event import async_track_point_in_utc_time
|
|||
from homeassistant.helpers.discovery import async_load_platform, async_discover
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
REQUIREMENTS = ['netdisco==2.5.0']
|
||||
REQUIREMENTS = ['netdisco==2.6.0']
|
||||
|
||||
DOMAIN = 'discovery'
|
||||
|
||||
|
@ -35,6 +35,7 @@ SERVICE_FREEBOX = 'freebox'
|
|||
SERVICE_HASS_IOS_APP = 'hass_ios'
|
||||
SERVICE_HASSIO = 'hassio'
|
||||
SERVICE_HOMEKIT = 'homekit'
|
||||
SERVICE_HEOS = 'heos'
|
||||
SERVICE_HUE = 'philips_hue'
|
||||
SERVICE_IGD = 'igd'
|
||||
SERVICE_IKEA_TRADFRI = 'ikea_tradfri'
|
||||
|
@ -57,6 +58,7 @@ CONFIG_ENTRY_HANDLERS = {
|
|||
SERVICE_DECONZ: 'deconz',
|
||||
'esphome': 'esphome',
|
||||
'google_cast': 'cast',
|
||||
SERVICE_HEOS: 'heos',
|
||||
SERVICE_HUE: 'hue',
|
||||
SERVICE_TELLDUSLIVE: 'tellduslive',
|
||||
SERVICE_IKEA_TRADFRI: 'tradfri',
|
||||
|
|
|
@ -21,6 +21,11 @@ class HeosFlowHandler(config_entries.ConfigFlow):
|
|||
VERSION = 1
|
||||
CONNECTION_CLASS = config_entries.CONN_CLASS_LOCAL_PUSH
|
||||
|
||||
async def async_step_discovery(self, discovery_info):
|
||||
"""Handle a discovered Heos device."""
|
||||
return await self.async_step_user(
|
||||
{CONF_HOST: discovery_info[CONF_HOST]})
|
||||
|
||||
async def async_step_import(self, user_input=None):
|
||||
"""Occurs when an entry is setup through config."""
|
||||
host = user_input[CONF_HOST]
|
||||
|
@ -32,7 +37,7 @@ class HeosFlowHandler(config_entries.ConfigFlow):
|
|||
"""Obtain host and validate connection."""
|
||||
from pyheos import Heos
|
||||
|
||||
# Only a single entry is supported
|
||||
# Only a single entry is needed for all devices
|
||||
entries = self.hass.config_entries.async_entries(DOMAIN)
|
||||
if entries:
|
||||
return self.async_abort(reason='already_setup')
|
||||
|
|
|
@ -741,7 +741,7 @@ nessclient==0.9.15
|
|||
netdata==0.1.2
|
||||
|
||||
# homeassistant.components.discovery
|
||||
netdisco==2.5.0
|
||||
netdisco==2.6.0
|
||||
|
||||
# homeassistant.components.neurio_energy.sensor
|
||||
neurio==0.3.1
|
||||
|
|
|
@ -55,3 +55,28 @@ async def test_create_entry_when_host_valid(hass, controller):
|
|||
assert result['data'] == data
|
||||
assert controller.connect.call_count == 1
|
||||
assert controller.disconnect.call_count == 1
|
||||
|
||||
|
||||
async def test_create_entry_with_discovery(hass, controller):
|
||||
"""Test result type is create entry when valid through discovery."""
|
||||
flow = HeosFlowHandler()
|
||||
flow.hass = hass
|
||||
data = {
|
||||
'host': '127.0.0.1',
|
||||
'manufacturer': 'Denon',
|
||||
'model_name': 'HEOS Drive',
|
||||
'model_number': 'DWSA-10 4.0',
|
||||
'name': 'Office',
|
||||
'port': 60006,
|
||||
'serial': None,
|
||||
'ssdp_description':
|
||||
'http://127.0.0.1:60006/upnp/desc/aios_device/aios_device.xml',
|
||||
'udn': 'uuid:e61de70c-2250-1c22-0080-0005cdf512be',
|
||||
'upnp_device_type': 'urn:schemas-denon-com:device:AiosDevice:1'
|
||||
}
|
||||
result = await flow.async_step_discovery(data)
|
||||
assert result['type'] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
assert result['title'] == 'Controller (127.0.0.1)'
|
||||
assert result['data'] == {'host': '127.0.0.1'}
|
||||
assert controller.connect.call_count == 1
|
||||
assert controller.disconnect.call_count == 1
|
||||
|
|
Loading…
Add table
Reference in a new issue