Skip to content

Commit

Permalink
Refactor Hue: phue -> aiohue (#13043)
Browse files Browse the repository at this point in the history
* phue -> aiohue

* Clean up

* Fix config

* Address comments

* Typo

* Fix rebase error

* Mark light as unavailable when bridge is disconnected

* Tests

* Make Throttle work with double delay and async

* Rework update logic

* Don't resolve host to IP

* Clarify comment

* No longer do unnecessary updates

* Add more doc

* Another comment update

* Wrap up tests

* Lint

* Fix tests

* PyLint does not like mix 'n match async and coroutine

* Lint

* Update aiohue to 1.2

* Lint

* Fix await MagicMock
  • Loading branch information
balloob committed Mar 17, 2018
1 parent d78e75d commit 5a9013c
Show file tree
Hide file tree
Showing 20 changed files with 1,302 additions and 1,498 deletions.
16 changes: 6 additions & 10 deletions homeassistant/components/discovery.py
Expand Up @@ -6,7 +6,6 @@
Knows which components handle certain types, will make sure they are
loaded before the EVENT_PLATFORM_DISCOVERED is fired.
"""
import asyncio
import json
from datetime import timedelta
import logging
Expand Down Expand Up @@ -84,8 +83,7 @@
}, extra=vol.ALLOW_EXTRA)


@asyncio.coroutine
def async_setup(hass, config):
async def async_setup(hass, config):
"""Start a discovery service."""
from netdisco.discovery import NetworkDiscovery

Expand All @@ -99,8 +97,7 @@ def async_setup(hass, config):
# Platforms ignore by config
ignored_platforms = config[DOMAIN][CONF_IGNORE]

@asyncio.coroutine
def new_service_found(service, info):
async def new_service_found(service, info):
"""Handle a new service if one is found."""
if service in ignored_platforms:
logger.info("Ignoring service: %s %s", service, info)
Expand All @@ -124,15 +121,14 @@ def new_service_found(service, info):
component, platform = comp_plat

if platform is None:
yield from async_discover(hass, service, info, component, config)
await async_discover(hass, service, info, component, config)
else:
yield from async_load_platform(
await async_load_platform(
hass, component, platform, info, config)

@asyncio.coroutine
def scan_devices(now):
async def scan_devices(now):
"""Scan for devices."""
results = yield from hass.async_add_job(_discover, netdisco)
results = await hass.async_add_job(_discover, netdisco)

for result in results:
hass.async_add_job(new_service_found(*result))
Expand Down

0 comments on commit 5a9013c

Please sign in to comment.