mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Upgrade netdisco to 1.0.0rc2 (#7008)
* Upgrade netdisco to 1.0.0rc2 * fix tests
This commit is contained in:
parent
72a01b8a90
commit
edf500e66b
@ -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
|
from homeassistant.helpers.discovery import async_load_platform, async_discover
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
|
|
||||||
REQUIREMENTS = ['netdisco==0.9.2']
|
REQUIREMENTS = ['netdisco==1.0.0rc2']
|
||||||
|
|
||||||
DOMAIN = 'discovery'
|
DOMAIN = 'discovery'
|
||||||
|
|
||||||
@ -45,7 +45,6 @@ SERVICE_HANDLERS = {
|
|||||||
'denonavr': ('media_player', 'denonavr'),
|
'denonavr': ('media_player', 'denonavr'),
|
||||||
'samsung_tv': ('media_player', 'samsungtv'),
|
'samsung_tv': ('media_player', 'samsungtv'),
|
||||||
'yeelight': ('light', 'yeelight'),
|
'yeelight': ('light', 'yeelight'),
|
||||||
'flux_led': ('light', 'flux_led'),
|
|
||||||
'apple_tv': ('media_player', 'apple_tv'),
|
'apple_tv': ('media_player', 'apple_tv'),
|
||||||
'frontier_silicon': ('media_player', 'frontier_silicon'),
|
'frontier_silicon': ('media_player', 'frontier_silicon'),
|
||||||
'openhome': ('media_player', 'openhome'),
|
'openhome': ('media_player', 'openhome'),
|
||||||
|
@ -108,20 +108,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
lights.append(light)
|
lights.append(light)
|
||||||
light_ips.append(ipaddr)
|
light_ips.append(ipaddr)
|
||||||
|
|
||||||
if discovery_info:
|
|
||||||
device = {}
|
|
||||||
# discovery_info: ip address,device id,device type
|
|
||||||
device['ipaddr'] = discovery_info[0]
|
|
||||||
device['name'] = discovery_info[1]
|
|
||||||
# As we don't know protocol and mode set to none to autodetect.
|
|
||||||
device[CONF_PROTOCOL] = None
|
|
||||||
device[ATTR_MODE] = None
|
|
||||||
|
|
||||||
light = FluxLight(device)
|
|
||||||
if light.is_valid:
|
|
||||||
lights.append(light)
|
|
||||||
light_ips.append(device['ipaddr'])
|
|
||||||
|
|
||||||
if not config.get(CONF_AUTOMATIC_ADD, False):
|
if not config.get(CONF_AUTOMATIC_ADD, False):
|
||||||
add_devices(lights)
|
add_devices(lights)
|
||||||
return
|
return
|
||||||
|
@ -10,7 +10,6 @@ import os
|
|||||||
import random
|
import random
|
||||||
import socket
|
import socket
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from urllib.parse import urlparse
|
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
@ -115,11 +114,11 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
allow_hue_groups = config.get(CONF_ALLOW_HUE_GROUPS)
|
allow_hue_groups = config.get(CONF_ALLOW_HUE_GROUPS)
|
||||||
|
|
||||||
if discovery_info is not None:
|
if discovery_info is not None:
|
||||||
host = urlparse(discovery_info[1]).hostname
|
if "HASS Bridge" in discovery_info.get('name', ''):
|
||||||
|
|
||||||
if "HASS Bridge" in discovery_info[0]:
|
|
||||||
_LOGGER.info('Emulated hue found, will not add')
|
_LOGGER.info('Emulated hue found, will not add')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
host = discovery_info.get('host')
|
||||||
else:
|
else:
|
||||||
host = config.get(CONF_HOST, None)
|
host = config.get(CONF_HOST, None)
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
|
|||||||
if discovery_info is not None:
|
if discovery_info is not None:
|
||||||
name = discovery_info['name']
|
name = discovery_info['name']
|
||||||
host = discovery_info['host']
|
host = discovery_info['host']
|
||||||
login_id = discovery_info['hsgid']
|
login_id = discovery_info['properties']['hsgid']
|
||||||
start_off = False
|
start_off = False
|
||||||
else:
|
else:
|
||||||
name = config.get(CONF_NAME)
|
name = config.get(CONF_NAME)
|
||||||
|
@ -51,11 +51,13 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
|
|
||||||
hosts = []
|
hosts = []
|
||||||
|
|
||||||
if discovery_info and discovery_info in KNOWN_HOSTS:
|
if discovery_info:
|
||||||
return
|
host = (discovery_info.get('host'), discovery_info.get('port'))
|
||||||
|
|
||||||
elif discovery_info:
|
if host in KNOWN_HOSTS:
|
||||||
hosts = [discovery_info]
|
return
|
||||||
|
|
||||||
|
hosts = [host]
|
||||||
|
|
||||||
elif CONF_HOST in config:
|
elif CONF_HOST in config:
|
||||||
hosts = [(config.get(CONF_HOST), DEFAULT_PORT)]
|
hosts = [(config.get(CONF_HOST), DEFAULT_PORT)]
|
||||||
|
@ -64,8 +64,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
_LOGGER.info("Denon receiver at host %s initialized", host)
|
_LOGGER.info("Denon receiver at host %s initialized", host)
|
||||||
# 2. option: discovery using netdisco
|
# 2. option: discovery using netdisco
|
||||||
if discovery_info is not None:
|
if discovery_info is not None:
|
||||||
host = discovery_info[0]
|
host = discovery_info.get('host')
|
||||||
name = discovery_info[1]
|
name = discovery_info.get('name')
|
||||||
# Check if host not in cache, append it and save for later starting
|
# Check if host not in cache, append it and save for later starting
|
||||||
if host not in cache:
|
if host not in cache:
|
||||||
cache.add(host)
|
cache.add(host)
|
||||||
|
@ -37,14 +37,15 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
"""Setup the DirecTV platform."""
|
"""Setup the DirecTV platform."""
|
||||||
hosts = []
|
hosts = []
|
||||||
|
|
||||||
if discovery_info and discovery_info in KNOWN_HOSTS:
|
if discovery_info:
|
||||||
return
|
host = discovery_info.get('host')
|
||||||
|
|
||||||
|
if host in KNOWN_HOSTS:
|
||||||
|
return
|
||||||
|
|
||||||
if discovery_info is not None:
|
|
||||||
hosts.append([
|
hosts.append([
|
||||||
'DirecTV_' + discovery_info[1],
|
'DirecTV_' + discovery_info.get('serial', ''),
|
||||||
discovery_info[0],
|
host, DEFAULT_PORT
|
||||||
DEFAULT_PORT
|
|
||||||
])
|
])
|
||||||
|
|
||||||
elif CONF_HOST in config:
|
elif CONF_HOST in config:
|
||||||
|
@ -47,7 +47,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
|
|
||||||
if discovery_info is not None:
|
if discovery_info is not None:
|
||||||
add_devices(
|
add_devices(
|
||||||
[FSAPIDevice(discovery_info, DEFAULT_PASSWORD)],
|
[FSAPIDevice(discovery_info['ssdp_description'],
|
||||||
|
DEFAULT_PASSWORD)],
|
||||||
update_before_add=True)
|
update_before_add=True)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -31,21 +31,23 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
"""Setup Openhome Platform."""
|
"""Setup Openhome Platform."""
|
||||||
from openhomedevice.Device import Device
|
from openhomedevice.Device import Device
|
||||||
|
|
||||||
if discovery_info:
|
if not discovery_info:
|
||||||
_LOGGER.info('Openhome device found, (%s)', discovery_info[0])
|
|
||||||
device = Device(discovery_info[1])
|
|
||||||
|
|
||||||
# if device has already been discovered
|
|
||||||
if device.Uuid() in [x.unique_id for x in DEVICES]:
|
|
||||||
return True
|
|
||||||
|
|
||||||
device = OpenhomeDevice(hass, device)
|
|
||||||
|
|
||||||
add_devices([device], True)
|
|
||||||
DEVICES.append(device)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
name = discovery_info.get('name')
|
||||||
|
description = discovery_info.get('ssdp_description')
|
||||||
|
_LOGGER.info('Openhome device found, (%s)', name)
|
||||||
|
device = Device(description)
|
||||||
|
|
||||||
|
# if device has already been discovered
|
||||||
|
if device.Uuid() in [x.unique_id for x in DEVICES]:
|
||||||
|
return True
|
||||||
|
|
||||||
|
device = OpenhomeDevice(hass, device)
|
||||||
|
|
||||||
|
add_devices([device], True)
|
||||||
|
DEVICES.append(device)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@ -51,11 +51,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
|
|
||||||
if discovery_info:
|
if discovery_info:
|
||||||
_LOGGER.debug('%s', discovery_info)
|
_LOGGER.debug('%s', discovery_info)
|
||||||
vals = discovery_info.split(':')
|
host = discovery_info.get('host')
|
||||||
if len(vals) > 1:
|
port = discovery_info.get('port')
|
||||||
port = vals[1]
|
|
||||||
|
|
||||||
host = vals[0]
|
|
||||||
remote = RemoteControl(host, port)
|
remote = RemoteControl(host, port)
|
||||||
add_devices([PanasonicVieraTVDevice(mac, name, remote)])
|
add_devices([PanasonicVieraTVDevice(mac, name, remote)])
|
||||||
return True
|
return True
|
||||||
|
@ -102,7 +102,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
|||||||
# Via discovery
|
# Via discovery
|
||||||
elif discovery_info is not None:
|
elif discovery_info is not None:
|
||||||
# Parse discovery data
|
# Parse discovery data
|
||||||
host = urlparse(discovery_info[1]).netloc
|
host = discovery_info.get('host')
|
||||||
_LOGGER.info('Discovered PLEX server: %s', host)
|
_LOGGER.info('Discovered PLEX server: %s', host)
|
||||||
|
|
||||||
if host in _CONFIGURING:
|
if host in _CONFIGURING:
|
||||||
|
@ -42,11 +42,13 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
"""Setup the Roku platform."""
|
"""Setup the Roku platform."""
|
||||||
hosts = []
|
hosts = []
|
||||||
|
|
||||||
if discovery_info and discovery_info in KNOWN_HOSTS:
|
if discovery_info:
|
||||||
return
|
host = discovery_info[0]
|
||||||
|
|
||||||
if discovery_info is not None:
|
if host in KNOWN_HOSTS:
|
||||||
_LOGGER.debug('Discovered Roku: %s', discovery_info[0])
|
return
|
||||||
|
|
||||||
|
_LOGGER.debug('Discovered Roku: %s', host)
|
||||||
hosts.append(discovery_info[0])
|
hosts.append(discovery_info[0])
|
||||||
|
|
||||||
elif CONF_HOST in config:
|
elif CONF_HOST in config:
|
||||||
|
@ -58,7 +58,9 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
mac = config.get(CONF_MAC)
|
mac = config.get(CONF_MAC)
|
||||||
timeout = config.get(CONF_TIMEOUT)
|
timeout = config.get(CONF_TIMEOUT)
|
||||||
elif discovery_info is not None:
|
elif discovery_info is not None:
|
||||||
tv_name, model, host = discovery_info
|
tv_name = discovery_info.get('name')
|
||||||
|
model = discovery_info.get('model_name')
|
||||||
|
host = discovery_info.get('host')
|
||||||
name = "{} ({})".format(tv_name, model)
|
name = "{} ({})".format(tv_name, model)
|
||||||
port = DEFAULT_PORT
|
port = DEFAULT_PORT
|
||||||
timeout = DEFAULT_TIMEOUT
|
timeout = DEFAULT_TIMEOUT
|
||||||
|
@ -103,7 +103,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
soco.config.EVENT_ADVERTISE_IP = advertise_addr
|
soco.config.EVENT_ADVERTISE_IP = advertise_addr
|
||||||
|
|
||||||
if discovery_info:
|
if discovery_info:
|
||||||
player = soco.SoCo(discovery_info)
|
player = soco.SoCo(discovery_info.get('host'))
|
||||||
|
|
||||||
# if device allready exists by config
|
# if device allready exists by config
|
||||||
if player.uid in [x.unique_id for x in hass.data[DATA_SONOS]]:
|
if player.uid in [x.unique_id for x in hass.data[DATA_SONOS]]:
|
||||||
|
@ -59,10 +59,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
zone_ignore = config.get(CONF_ZONE_IGNORE)
|
zone_ignore = config.get(CONF_ZONE_IGNORE)
|
||||||
|
|
||||||
if discovery_info is not None:
|
if discovery_info is not None:
|
||||||
name = discovery_info[0]
|
name = discovery_info.get('name')
|
||||||
model = discovery_info[1]
|
model = discovery_info.get('model_name')
|
||||||
ctrl_url = discovery_info[2]
|
ctrl_url = discovery_info.get('control_url')
|
||||||
desc_url = discovery_info[3]
|
desc_url = discovery_info.get('description_url')
|
||||||
if ctrl_url in hass.data[KNOWN]:
|
if ctrl_url in hass.data[KNOWN]:
|
||||||
_LOGGER.info("%s already manually configured", ctrl_url)
|
_LOGGER.info("%s already manually configured", ctrl_url)
|
||||||
return
|
return
|
||||||
|
@ -62,7 +62,8 @@ def setup(hass, config):
|
|||||||
def discovery_dispatch(service, discovery_info):
|
def discovery_dispatch(service, discovery_info):
|
||||||
"""Dispatcher for WeMo discovery events."""
|
"""Dispatcher for WeMo discovery events."""
|
||||||
# name, model, location, mac
|
# name, model, location, mac
|
||||||
_, model_name, _, _, serial = discovery_info
|
model_name = discovery_info.get('model_name')
|
||||||
|
serial = discovery_info.get('serial')
|
||||||
|
|
||||||
# Only register a device once
|
# Only register a device once
|
||||||
if serial in KNOWN_DEVICES:
|
if serial in KNOWN_DEVICES:
|
||||||
|
@ -393,7 +393,7 @@ mutagen==1.36.2
|
|||||||
myusps==1.0.5
|
myusps==1.0.5
|
||||||
|
|
||||||
# homeassistant.components.discovery
|
# homeassistant.components.discovery
|
||||||
netdisco==0.9.2
|
netdisco==1.0.0rc2
|
||||||
|
|
||||||
# homeassistant.components.sensor.neurio_energy
|
# homeassistant.components.sensor.neurio_energy
|
||||||
neurio==0.3.1
|
neurio==0.3.1
|
||||||
|
@ -37,6 +37,8 @@ class TestCastMediaPlayer(unittest.TestCase):
|
|||||||
assert not mock_device.called
|
assert not mock_device.called
|
||||||
|
|
||||||
# Test chromecasts as if they were automatically discovered
|
# Test chromecasts as if they were automatically discovered
|
||||||
cast.setup_platform(None, {}, lambda _: _, ('some_host',
|
cast.setup_platform(None, {}, lambda _: _, {
|
||||||
cast.DEFAULT_PORT))
|
'host': 'some_host',
|
||||||
|
'port': cast.DEFAULT_PORT,
|
||||||
|
})
|
||||||
assert not mock_device.called
|
assert not mock_device.called
|
||||||
|
@ -143,7 +143,9 @@ class TestSonosMediaPlayer(unittest.TestCase):
|
|||||||
@mock.patch('socket.create_connection', side_effect=socket.error())
|
@mock.patch('socket.create_connection', side_effect=socket.error())
|
||||||
def test_ensure_setup_discovery(self, *args):
|
def test_ensure_setup_discovery(self, *args):
|
||||||
"""Test a single device using the autodiscovery provided by HASS."""
|
"""Test a single device using the autodiscovery provided by HASS."""
|
||||||
sonos.setup_platform(self.hass, {}, fake_add_device, '192.0.2.1')
|
sonos.setup_platform(self.hass, {}, fake_add_device, {
|
||||||
|
'host': '192.0.2.1'
|
||||||
|
})
|
||||||
|
|
||||||
self.assertEqual(len(self.hass.data[sonos.DATA_SONOS]), 1)
|
self.assertEqual(len(self.hass.data[sonos.DATA_SONOS]), 1)
|
||||||
self.assertEqual(self.hass.data[sonos.DATA_SONOS][0].name, 'Kitchen')
|
self.assertEqual(self.hass.data[sonos.DATA_SONOS][0].name, 'Kitchen')
|
||||||
@ -250,7 +252,9 @@ class TestSonosMediaPlayer(unittest.TestCase):
|
|||||||
@mock.patch.object(SoCoMock, 'join')
|
@mock.patch.object(SoCoMock, 'join')
|
||||||
def test_sonos_group_players(self, join_mock, *args):
|
def test_sonos_group_players(self, join_mock, *args):
|
||||||
"""Ensuring soco methods called for sonos_group_players service."""
|
"""Ensuring soco methods called for sonos_group_players service."""
|
||||||
sonos.setup_platform(self.hass, {}, fake_add_device, '192.0.2.1')
|
sonos.setup_platform(self.hass, {}, fake_add_device, {
|
||||||
|
'host': '192.0.2.1'
|
||||||
|
})
|
||||||
device = self.hass.data[sonos.DATA_SONOS][-1]
|
device = self.hass.data[sonos.DATA_SONOS][-1]
|
||||||
device.hass = self.hass
|
device.hass = self.hass
|
||||||
|
|
||||||
@ -268,7 +272,9 @@ class TestSonosMediaPlayer(unittest.TestCase):
|
|||||||
@mock.patch.object(SoCoMock, 'unjoin')
|
@mock.patch.object(SoCoMock, 'unjoin')
|
||||||
def test_sonos_unjoin(self, unjoinMock, *args):
|
def test_sonos_unjoin(self, unjoinMock, *args):
|
||||||
"""Ensuring soco methods called for sonos_unjoin service."""
|
"""Ensuring soco methods called for sonos_unjoin service."""
|
||||||
sonos.setup_platform(self.hass, {}, fake_add_device, '192.0.2.1')
|
sonos.setup_platform(self.hass, {}, fake_add_device, {
|
||||||
|
'host': '192.0.2.1'
|
||||||
|
})
|
||||||
device = self.hass.data[sonos.DATA_SONOS][-1]
|
device = self.hass.data[sonos.DATA_SONOS][-1]
|
||||||
device.hass = self.hass
|
device.hass = self.hass
|
||||||
|
|
||||||
@ -282,7 +288,9 @@ class TestSonosMediaPlayer(unittest.TestCase):
|
|||||||
@mock.patch.object(SoCoMock, 'set_sleep_timer')
|
@mock.patch.object(SoCoMock, 'set_sleep_timer')
|
||||||
def test_sonos_set_sleep_timer(self, set_sleep_timerMock, *args):
|
def test_sonos_set_sleep_timer(self, set_sleep_timerMock, *args):
|
||||||
"""Ensuring soco methods called for sonos_set_sleep_timer service."""
|
"""Ensuring soco methods called for sonos_set_sleep_timer service."""
|
||||||
sonos.setup_platform(self.hass, {}, fake_add_device, '192.0.2.1')
|
sonos.setup_platform(self.hass, {}, fake_add_device, {
|
||||||
|
'host': '192.0.2.1'
|
||||||
|
})
|
||||||
device = self.hass.data[sonos.DATA_SONOS][-1]
|
device = self.hass.data[sonos.DATA_SONOS][-1]
|
||||||
device.hass = self.hass
|
device.hass = self.hass
|
||||||
|
|
||||||
@ -294,7 +302,9 @@ class TestSonosMediaPlayer(unittest.TestCase):
|
|||||||
@mock.patch.object(SoCoMock, 'set_sleep_timer')
|
@mock.patch.object(SoCoMock, 'set_sleep_timer')
|
||||||
def test_sonos_clear_sleep_timer(self, set_sleep_timerMock, *args):
|
def test_sonos_clear_sleep_timer(self, set_sleep_timerMock, *args):
|
||||||
"""Ensuring soco methods called for sonos_clear_sleep_timer service."""
|
"""Ensuring soco methods called for sonos_clear_sleep_timer service."""
|
||||||
sonos.setup_platform(self.hass, {}, mock.MagicMock(), '192.0.2.1')
|
sonos.setup_platform(self.hass, {}, mock.MagicMock(), {
|
||||||
|
'host': '192.0.2.1'
|
||||||
|
})
|
||||||
device = self.hass.data[sonos.DATA_SONOS][-1]
|
device = self.hass.data[sonos.DATA_SONOS][-1]
|
||||||
device.hass = self.hass
|
device.hass = self.hass
|
||||||
|
|
||||||
@ -306,7 +316,9 @@ class TestSonosMediaPlayer(unittest.TestCase):
|
|||||||
@mock.patch.object(soco.snapshot.Snapshot, 'snapshot')
|
@mock.patch.object(soco.snapshot.Snapshot, 'snapshot')
|
||||||
def test_sonos_snapshot(self, snapshotMock, *args):
|
def test_sonos_snapshot(self, snapshotMock, *args):
|
||||||
"""Ensuring soco methods called for sonos_snapshot service."""
|
"""Ensuring soco methods called for sonos_snapshot service."""
|
||||||
sonos.setup_platform(self.hass, {}, fake_add_device, '192.0.2.1')
|
sonos.setup_platform(self.hass, {}, fake_add_device, {
|
||||||
|
'host': '192.0.2.1'
|
||||||
|
})
|
||||||
device = self.hass.data[sonos.DATA_SONOS][-1]
|
device = self.hass.data[sonos.DATA_SONOS][-1]
|
||||||
device.hass = self.hass
|
device.hass = self.hass
|
||||||
|
|
||||||
@ -322,7 +334,9 @@ class TestSonosMediaPlayer(unittest.TestCase):
|
|||||||
"""Ensuring soco methods called for sonos_restor service."""
|
"""Ensuring soco methods called for sonos_restor service."""
|
||||||
from soco.snapshot import Snapshot
|
from soco.snapshot import Snapshot
|
||||||
|
|
||||||
sonos.setup_platform(self.hass, {}, fake_add_device, '192.0.2.1')
|
sonos.setup_platform(self.hass, {}, fake_add_device, {
|
||||||
|
'host': '192.0.2.1'
|
||||||
|
})
|
||||||
device = self.hass.data[sonos.DATA_SONOS][-1]
|
device = self.hass.data[sonos.DATA_SONOS][-1]
|
||||||
device.hass = self.hass
|
device.hass = self.hass
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user