Refactor Hue: phue -> aiohue (#13043)

* 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
This commit is contained in:
Paulus Schoutsen 2018-03-16 20:27:05 -07:00 committed by GitHub
parent d78e75db66
commit 5a9013cda5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 1289 additions and 1485 deletions

View file

@ -5,8 +5,6 @@ There are two different types of discoveries that can be fired/listened for.
- listen_platform/discover_platform is for platforms. These are used by
components to allow discovery of their platforms.
"""
import asyncio
from homeassistant import setup, core
from homeassistant.loader import bind_hass
from homeassistant.const import (
@ -58,17 +56,16 @@ def discover(hass, service, discovered=None, component=None, hass_config=None):
async_discover(hass, service, discovered, component, hass_config))
@asyncio.coroutine
@bind_hass
def async_discover(hass, service, discovered=None, component=None,
hass_config=None):
async def async_discover(hass, service, discovered=None, component=None,
hass_config=None):
"""Fire discovery event. Can ensure a component is loaded."""
if component in DEPENDENCY_BLACKLIST:
raise HomeAssistantError(
'Cannot discover the {} component.'.format(component))
if component is not None and component not in hass.config.components:
yield from setup.async_setup_component(
await setup.async_setup_component(
hass, component, hass_config)
data = {
@ -134,10 +131,9 @@ def load_platform(hass, component, platform, discovered=None,
hass_config))
@asyncio.coroutine
@bind_hass
def async_load_platform(hass, component, platform, discovered=None,
hass_config=None):
async def async_load_platform(hass, component, platform, discovered=None,
hass_config=None):
"""Load a component and platform dynamically.
Target components will be loaded and an EVENT_PLATFORM_DISCOVERED will be
@ -148,7 +144,7 @@ def async_load_platform(hass, component, platform, discovered=None,
Use `listen_platform` to register a callback for these events.
Warning: Do not yield from this inside a setup method to avoid a dead lock.
Warning: Do not await this inside a setup method to avoid a dead lock.
Use `hass.async_add_job(async_load_platform(..))` instead.
This method is a coroutine.
@ -160,7 +156,7 @@ def async_load_platform(hass, component, platform, discovered=None,
setup_success = True
if component not in hass.config.components:
setup_success = yield from setup.async_setup_component(
setup_success = await setup.async_setup_component(
hass, component, hass_config)
# No need to fire event if we could not setup component