Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async support with resource observation. #7815

Merged
merged 83 commits into from
Oct 5, 2017
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
fb921f3
[light.tradfri] Initial support for observe
lwis May 29, 2017
140cd0b
Merge upstream
lwis Jun 5, 2017
416559b
Update for pytradfri 2.0
lwis Jun 5, 2017
976527c
Fix imports
lwis Jun 5, 2017
ebc408a
Fix missing call
lwis Jun 5, 2017
304857f
Don't yield from add devices
lwis Jun 5, 2017
264b43c
Fix imports
lwis Jun 5, 2017
b83ce62
Minor fixes to async code.
lwis Jun 6, 2017
836bb63
Imports, formatting
lwis Jun 6, 2017
93bdbd0
Docker updates, some minor async code changes.
lwis Jun 6, 2017
6a13613
Lint
lwis Jun 6, 2017
b1e1fc2
Lint
lwis Jun 6, 2017
089c65e
Merge remote-tracking branch 'origin' into tradfri-observe
lwis Jun 10, 2017
b6ed0ed
Update pytradfri
lwis Jun 10, 2017
acf27bc
Merge remote-tracking branch 'origin/dev' into tradfri-observe
lwis Jun 14, 2017
dd6d5b6
Minor updates for release version
lwis Jun 14, 2017
27ff361
Build fixes
lwis Jun 14, 2017
e432e7f
Retry observation if failed
lwis Jun 14, 2017
748a7cf
Revert
lwis Jun 14, 2017
0158959
Additional logging, fix returns
lwis Jun 15, 2017
597464d
Fix rename
lwis Jun 15, 2017
949ace2
Merge branch 'dev' into tradfri-observe
lwis Jun 22, 2017
10887e2
Bump version
lwis Jun 22, 2017
2e7e6c1
Bump version
lwis Jun 22, 2017
2d6b3df
Support transitions
lwis Jun 22, 2017
d4255c2
Lint
lwis Jun 22, 2017
44f70f8
Merge remote-tracking branch 'origin/dev' into tradfri-observe
lwis Jun 24, 2017
0a3f3d5
Fix transitions
lwis Jun 24, 2017
462c641
Update Dockerfile
balloob Jun 25, 2017
7858e0c
Merge remote-tracking branch 'origin/dev' into tradfri-observe
lwis Jun 26, 2017
c726069
Merge remote-tracking branch 'origin/dev' into tradfri-observe
lwis Jun 27, 2017
a45c7dc
Set temp first
lwis Jun 27, 2017
8899efb
Merge remote-tracking branch 'origin/dev' into tradfri-observe
lwis Jun 28, 2017
1052a78
Merge upstream
lwis Jul 1, 2017
dec727d
Merge remote-tracking branch 'origin/dev' into tradfri-observe
lwis Jul 1, 2017
0c841c3
Observation error handling
lwis Jul 1, 2017
5906591
Lint
lwis Jul 1, 2017
814f420
Lint
lwis Jul 1, 2017
a2ac6a9
Merge remote-tracking branch 'origin/dev' into tradfri-observe
lwis Jul 2, 2017
c9ce479
Merge remote-tracking branch 'origin/dev' into tradfri-observe
lwis Jul 3, 2017
14af049
Lint
lwis Jul 3, 2017
b6bc24d
Merge remote-tracking branch 'origin/dev' into tradfri-observe
lwis Jul 5, 2017
f4e1df5
Merge remote-tracking branch 'origin/dev' into tradfri-observe
lwis Jul 7, 2017
61797d3
Merge remote-tracking branch 'origin/dev' into tradfri-observe
lwis Jul 11, 2017
b2ba3e7
Merge remote-tracking branch 'origin/dev' into tradfri-observe
lwis Jul 13, 2017
82d9aef
Merge remote-tracking branch 'origin/dev' into tradfri-observe
lwis Jul 14, 2017
bf68cfd
Merge remote-tracking branch 'origin/dev' into tradfri-observe
lwis Jul 16, 2017
7c9ff4b
Merge remote-tracking branch 'origin/dev' into tradfri-observe
lwis Jul 18, 2017
fae1ff5
Merge remote-tracking branch 'origin/dev' into tradfri-observe
lwis Jul 19, 2017
06e594e
Merge remote-tracking branch 'origin/dev' into tradfri-observe
lwis Jul 22, 2017
952dbc0
Merge remote-tracking branch 'origin/dev' into tradfri-observe
lwis Jul 26, 2017
a243655
Merge remote-tracking branch 'origin/dev' into tradfri-observe
lwis Aug 5, 2017
cfcf227
Merge remote-tracking branch 'origin/dev' into tradfri-observe
lwis Aug 9, 2017
90e513c
Merge remote-tracking branch 'origin/dev' into tradfri-observe
lwis Aug 9, 2017
6e30db9
Merge remote-tracking branch 'origin/dev' into tradfri-observe
lwis Aug 12, 2017
5db61e4
Merge remote-tracking branch 'origin/dev' into tradfri-observe
lwis Aug 17, 2017
0cbb660
Merge remote-tracking branch 'origin/dev' into tradfri-observe
lwis Aug 27, 2017
03647e0
Merge remote-tracking branch 'origin/dev' into tradfri-observe
lwis Aug 29, 2017
8b3ca01
Merge remote-tracking branch 'origin/dev' into tradfri-observe
lwis Aug 31, 2017
aef1005
Merge upstream changes
lwis Aug 31, 2017
76b1913
Fix bugs
lwis Aug 31, 2017
719c1f1
Fix bugs
lwis Aug 31, 2017
fb168b4
Fix bugs
lwis Aug 31, 2017
4197a91
Lint
lwis Aug 31, 2017
0b33ebc
Add sensor
lwis Sep 1, 2017
98f4cc1
Add sensor
lwis Sep 1, 2017
cc327a0
Move sensor attrs
lwis Sep 1, 2017
152f279
Filter devices better
lwis Sep 1, 2017
72b6c59
Merge remote-tracking branch 'origin/dev' into tradfri-observe
lwis Sep 1, 2017
06d3e72
Lint
lwis Sep 1, 2017
537f3df
Merge remote-tracking branch 'origin/dev' into tradfri-observe
lwis Sep 6, 2017
b6749eb
Merge remote-tracking branch 'origin/dev' into tradfri-observe
lwis Sep 7, 2017
c839e66
Merge remote-tracking branch 'origin/dev' into tradfri-observe
lwis Sep 9, 2017
7189363
Merge remote-tracking branch 'origin/dev' into tradfri-observe
lwis Sep 9, 2017
1813db0
Merge remote-tracking branch 'origin/dev' into tradfri-observe
lwis Sep 13, 2017
047d1b1
Merge remote-tracking branch 'origin/dev' into tradfri-observe
lwis Sep 14, 2017
c7f4373
Merge remote-tracking branch 'origin/dev' into tradfri-observe
lwis Sep 21, 2017
e86ea21
Address comments
lwis Sep 21, 2017
32ae7c1
Merge remote-tracking branch 'origin/dev' into tradfri-observe
lwis Sep 30, 2017
3eba9aa
Pin aiocoap
lwis Sep 30, 2017
4141908
Merge remote-tracking branch 'origin/dev' into tradfri-observe
lwis Oct 1, 2017
bc589c8
Fix bug if no devices
lwis Oct 1, 2017
f77fd09
Requirements
lwis Oct 1, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ MAINTAINER Paulus Schoutsen <Paulus@PaulusSchoutsen.nl>
#ENV INSTALL_FFMPEG no
#ENV INSTALL_LIBCEC no
#ENV INSTALL_PHANTOMJS no
#ENV INSTALL_COAP_CLIENT no
#ENV INSTALL_COAP no
#ENV INSTALL_SSOCR no


VOLUME /config

RUN mkdir -p /usr/src/app
Expand All @@ -22,7 +23,7 @@ RUN virtualization/Docker/setup_docker_prereqs
# Install hass component dependencies
COPY requirements_all.txt requirements_all.txt
RUN pip3 install --no-cache-dir -r requirements_all.txt && \
pip3 install --no-cache-dir mysqlclient psycopg2 uvloop cchardet
pip3 install --no-cache-dir mysqlclient psycopg2 cchardet
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't remove uvloop


# Copy source
COPY . .
Expand Down
185 changes: 140 additions & 45 deletions homeassistant/components/light/tradfri.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,55 +4,80 @@
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/light.tradfri/
"""
import asyncio
import logging

from homeassistant.core import callback
from homeassistant.components.light import (
ATTR_BRIGHTNESS, ATTR_COLOR_TEMP, ATTR_RGB_COLOR, SUPPORT_BRIGHTNESS,
SUPPORT_COLOR_TEMP, SUPPORT_RGB_COLOR, Light)
SUPPORT_TRANSITION, SUPPORT_COLOR_TEMP, SUPPORT_RGB_COLOR, Light)
from homeassistant.components.light import \
PLATFORM_SCHEMA as LIGHT_PLATFORM_SCHEMA
from homeassistant.components.tradfri import KEY_GATEWAY, KEY_TRADFRI_GROUPS
from homeassistant.components.tradfri import KEY_GATEWAY, KEY_TRADFRI_GROUPS, \
KEY_API
from homeassistant.util import color as color_util

_LOGGER = logging.getLogger(__name__)

DEPENDENCIES = ['tradfri']
PLATFORM_SCHEMA = LIGHT_PLATFORM_SCHEMA
IKEA = 'IKEA of Sweden'
TRADFRI_LIGHT_MANAGER = 'Tradfri Light Manager'
SUPPORTED_FEATURES = (SUPPORT_BRIGHTNESS | SUPPORT_TRANSITION)
ALLOWED_TEMPERATURES = {
IKEA: {2200: 'efd275', 2700: 'f1e0b5', 4000: 'f5faf6'}
}


def setup_platform(hass, config, add_devices, discovery_info=None):
@asyncio.coroutine
def async_setup_platform(hass, config, add_devices, discovery_info=None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename that into async_add_devices

"""Set up the IKEA Tradfri Light platform."""
if discovery_info is None:
return

gateway_id = discovery_info['gateway']
gateway = hass.data[KEY_GATEWAY][gateway_id]
devices = gateway.get_devices()
api = hass.data[KEY_API]

devices_command = gateway.get_devices()
devices_commands = yield from api(devices_command)
devices = yield from api(*devices_commands)
lights = [dev for dev in devices if dev.has_light_control]
add_devices(Tradfri(light) for light in lights)
add_devices(TradfriLight(light, api) for light in lights)

allow_tradfri_groups = hass.data[KEY_TRADFRI_GROUPS][gateway_id]
if allow_tradfri_groups:
groups = gateway.get_groups()
add_devices(TradfriGroup(group) for group in groups)
groups_command = gateway.get_groups()
groups_commands = yield from api(groups_command)
groups = yield from api(*groups_commands)
add_devices(TradfriGroup(group, api) for group in groups)


class TradfriGroup(Light):
"""The platform class required by hass."""

def __init__(self, light):
def __init__(self, light, api):
"""Initialize a Group."""
self._api = api
self._group = light
self._name = light.name

self._refresh(light)

@asyncio.coroutine
def async_added_to_hass(self):
"""Start thread when added to hass."""
self._async_start_observe()

@property
def should_poll(self):
"""No polling needed for tradfri group."""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a group

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is?

return False

@property
def supported_features(self):
"""Flag supported features."""
return SUPPORT_BRIGHTNESS
return SUPPORTED_FEATURES

@property
def name(self):
Expand All @@ -69,44 +94,71 @@ def brightness(self):
"""Return the brightness of the group lights."""
return self._group.dimmer

def turn_off(self, **kwargs):
@asyncio.coroutine
def async_turn_off(self, **kwargs):
"""Instruct the group lights to turn off."""
return self._group.set_state(0)
self.hass.async_add_job(self._api(self._group.set_state(0)))

def turn_on(self, **kwargs):
@asyncio.coroutine
def async_turn_on(self, **kwargs):
"""Instruct the group lights to turn on, or dim."""
if ATTR_BRIGHTNESS in kwargs:
self._group.set_dimmer(kwargs[ATTR_BRIGHTNESS])
transition = kwargs[ATTR_TRANSITION]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undefined name 'ATTR_TRANSITION'

self.hass.async_add_job(self._api(
self._group.set_dimmer(kwargs[ATTR_BRIGHTNESS],
transition_time=transition)))
else:
self._group.set_state(1)
self.hass.async_add_job(self._api(self._group.set_state(1)))

def update(self):
"""Fetch new state data for this group."""
self._group.update()
@callback
def _async_start_observe(self, exc=None):
"""Start observation of light."""
if exc:
_LOGGER.info("Observation failed for %s", self._name,
exc_info=exc)

cmd = self._group.observe(callback=self._observe_update,
err_callback=self._async_start_observe,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will the error callback also be called when the time expires?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't believe so

duration=0)
self.hass.async_add_job(self._api(cmd))

class Tradfri(Light):
"""The platform class required by Home Asisstant."""
def _refresh(self, group):
"""Refresh the light data."""
self._group = group
self._name = group.name

def __init__(self, light):
"""Initialize a Light."""
self._light = light
def _observe_update(self, tradfri_device):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also when a method is an async friendly callback, add an async prefix ot the name

"""Receive new state data for this light."""
self._refresh(tradfri_device)

# Caching of LightControl and light object
self._light_control = light.light_control
self._light_data = light.light_control.lights[0]
self._name = light.name
self.hass.async_add_job(self.async_update_ha_state())


class TradfriLight(Light):
"""The platform class required by Home Assistant."""

def __init__(self, light, api):
"""Initialize a Light."""
self._api = api
self._light = None
self._light_control = None
self._light_data = None
self._name = None
self._rgb_color = None
self._features = SUPPORT_BRIGHTNESS
self._features = SUPPORTED_FEATURES
self._ok_temps = None

if self._light_data.hex_color is not None:
if self._light.device_info.manufacturer == IKEA:
self._features |= SUPPORT_COLOR_TEMP
else:
self._features |= SUPPORT_RGB_COLOR
self._refresh(light)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that should be call inside async_add_to_hass. A init can be run on thread or loop

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not actually doing a refresh here, just setting instance variables.


self._ok_temps = ALLOWED_TEMPERATURES.get(
self._light.device_info.manufacturer)
@asyncio.coroutine
def async_added_to_hass(self):
"""Start thread when added to hass."""
self._async_start_observe()

@property
def should_poll(self):
"""No polling needed for tradfri light."""
return False

@property
def supported_features(self):
Expand Down Expand Up @@ -151,40 +203,83 @@ def rgb_color(self):
"""RGB color of the light."""
return self._rgb_color

def turn_off(self, **kwargs):
@asyncio.coroutine
def async_turn_off(self, **kwargs):
"""Instruct the light to turn off."""
return self._light_control.set_state(False)
self.hass.async_add_job(self._api(
self._light_control.set_state(False)))

def turn_on(self, **kwargs):
@asyncio.coroutine
def async_turn_on(self, **kwargs):
"""
Instruct the light to turn on.

After adding "self._light_data.hexcolor is not None"
for ATTR_RGB_COLOR, this also supports Philips Hue bulbs.
"""
if ATTR_BRIGHTNESS in kwargs:
self._light_control.set_dimmer(kwargs[ATTR_BRIGHTNESS])
transition = kwargs[ATTR_TRANSITION]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undefined name 'ATTR_TRANSITION'

self.hass.async_add_job(self._api(
self._light_control.set_dimmer(kwargs[ATTR_BRIGHTNESS],
transition_time=transition)))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continuation line under-indented for visual indent

else:
self._light_control.set_state(True)
self.hass.async_add_job(self._api(
self._light_control.set_state(True)))

if ATTR_RGB_COLOR in kwargs and self._light_data.hex_color is not None:
self._light.light_control.set_hex_color(
color_util.color_rgb_to_hex(*kwargs[ATTR_RGB_COLOR]))
self.hass.async_add_job(self._api(
self._light.light_control.set_hex_color(
color_util.color_rgb_to_hex(*kwargs[ATTR_RGB_COLOR]))))

elif ATTR_COLOR_TEMP in kwargs and \
self._light_data.hex_color is not None and self._ok_temps:
kelvin = color_util.color_temperature_mired_to_kelvin(
kwargs[ATTR_COLOR_TEMP])
# find closest allowed kelvin temp from user input
kelvin = min(self._ok_temps.keys(), key=lambda x: abs(x - kelvin))
self._light_control.set_hex_color(self._ok_temps[kelvin])
self.hass.async_add_job(self._api(
self._light_control.set_hex_color(self._ok_temps[kelvin])))

@callback
def _async_start_observe(self, exc=None):
"""Start observation of light."""
if exc:
_LOGGER.info("Observation failed for %s", self._name,
exc_info=exc)

cmd = self._light.observe(callback=self._observe_update,
err_callback=self._async_start_observe,
duration=0)
self.hass.async_add_job(self._api(cmd))

def _refresh(self, light):
"""Refresh the light data."""
self._light = light

# Caching of LightControl and light object
self._light_control = light.light_control
self._light_data = light.light_control.lights[0]
self._name = light.name
self._rgb_color = None
self._features = SUPPORTED_FEATURES

def update(self):
"""Fetch new state data for this light."""
self._light.update()
if self._light_data.hex_color is not None:
if self._light.device_info.manufacturer == IKEA:
self._features |= SUPPORT_COLOR_TEMP
else:
self._features |= SUPPORT_RGB_COLOR

self._ok_temps = ALLOWED_TEMPERATURES.get(
self._light.device_info.manufacturer)

def _observe_update(self, tradfri_device):
"""Receive new state data for this light."""
self._refresh(tradfri_device)

# Handle Hue lights paired with the gateway
# hex_color is 0 when bulb is unreachable
if self._light_data.hex_color not in (None, '0'):
self._rgb_color = color_util.rgb_hex_to_rgb_list(
self._light_data.hex_color)

self.hass.async_add_job(self.async_update_ha_state())
20 changes: 15 additions & 5 deletions homeassistant/components/tradfri.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
from homeassistant.loader import get_component
from homeassistant.components.discovery import SERVICE_IKEA_TRADFRI

REQUIREMENTS = ['pytradfri==1.1']
REQUIREMENTS = ['pytradfri==2.1.1']

DOMAIN = 'tradfri'
CONFIG_FILE = 'tradfri.conf'
KEY_CONFIG = 'tradfri_configuring'
KEY_GATEWAY = 'tradfri_gateway'
KEY_TRADFRI_GROUPS = 'tradfri_allow_tradfri_groups'
KEY_API = 'tradfri_api'
CONF_ALLOW_TRADFRI_GROUPS = 'allow_tradfri_groups'
DEFAULT_ALLOW_TRADFRI_GROUPS = True

Expand Down Expand Up @@ -110,15 +111,24 @@ def gateway_discovered(service, info):
@asyncio.coroutine
def _setup_gateway(hass, hass_config, host, key, allow_tradfri_groups):
"""Create a gateway."""
from pytradfri import cli_api_factory, Gateway, RequestError, retry_timeout
from pytradfri import Gateway, RequestError
try:
from pytradfri.api.aiocoap_api import api_factory
except ImportError:
_LOGGER.exception("Looks like something isn't installed!")
return False

try:
api = retry_timeout(cli_api_factory(host, key))
api = yield from api_factory(host, key, loop=hass.loop)
hass.data[KEY_API] = api
except RequestError:
_LOGGER.exception("Tradfri setup failed.")
return False
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we print an error ?


gateway = Gateway(api)
gateway_id = gateway.get_gateway_info().id
gateway = Gateway()
gateway_info_cmd = gateway.get_gateway_info()
gateway_info_result = yield from api(gateway_info_cmd)
gateway_id = gateway_info_result.id
hass.data.setdefault(KEY_GATEWAY, {})
gateways = hass.data[KEY_GATEWAY]

Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ python_openzwave==0.4.0.31
pytrackr==0.0.5

# homeassistant.components.tradfri
pytradfri==1.1
pytradfri==2.1.1

# homeassistant.components.device_tracker.unifi
pyunifi==2.13
Expand Down
4 changes: 2 additions & 2 deletions virtualization/Docker/Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ MAINTAINER Paulus Schoutsen <Paulus@PaulusSchoutsen.nl>
#ENV INSTALL_FFMPEG no
#ENV INSTALL_LIBCEC no
#ENV INSTALL_PHANTOMJS no
#ENV INSTALL_COAP_CLIENT no
#ENV INSTALL_COAP no
#ENV INSTALL_SSOCR no

VOLUME /config
Expand All @@ -26,7 +26,7 @@ RUN virtualization/Docker/setup_docker_prereqs
# Install hass component dependencies
COPY requirements_all.txt requirements_all.txt
RUN pip3 install --no-cache-dir -r requirements_all.txt && \
pip3 install --no-cache-dir mysqlclient psycopg2 uvloop cchardet
pip3 install --no-cache-dir mysqlclient psycopg2 cchardet
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please reinstate uvloop

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As uvloop isn't compatible with aiocoap, how can I get around it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is uvloop not compatible? Why would aiocoap be tied to an event loop implementation ?

We can't just remove uvloop, that's a big performance degradation. Also, many users will run under uvloop.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When running with uvloop installed;

hass_1  | 2017-06-24 09:55:52 ERROR (MainThread) [homeassistant.setup] Error during setup of component tradfri
hass_1  | Traceback (most recent call last):
hass_1  |   File "/usr/lib/python3.6/site-packages/homeassistant/setup.py", line 187, in _async_setup_component
hass_1  |     result = yield from component.async_setup(hass, processed_config)
hass_1  |   File "/usr/lib/python3.6/site-packages/homeassistant/components/tradfri.py", line 108, in async_setup
hass_1  |     allow_tradfri_groups))
hass_1  |   File "/usr/lib/python3.6/site-packages/homeassistant/components/tradfri.py", line 122, in _setup_gateway
hass_1  |     api = yield from api_factory(host, key, loop=hass.loop)
hass_1  |   File "/config/deps/pytradfri/api/aiocoap_api.py", line 46, in api_factory
hass_1  |     _protocol = yield from Context.create_client_context(loop=loop)
hass_1  |   File "/usr/lib/python3.6/site-packages/aiocoap/protocol.py", line 524, in create_client_context
hass_1  |     self.transport_endpoints.append((yield from TransportEndpointUDP6.create_client_transport_endpoint(new_message_callback=self._dispatch_message, 
new_error_callback=self._dispatch_error, log=self.log, loop=loop, dump_to=dump_to)))
hass_1  |   File "/usr/lib/python3.6/site-packages/aiocoap/transports/udp6.py", line 179, in create_client_transport_endpoint
hass_1  |     return (yield from cls._create_transport_endpoint(new_message_callback, new_error_callback, log, loop, dump_to, None, multicast=False))
hass_1  |   File "/usr/lib/python3.6/site-packages/aiocoap/transports/udp6.py", line 140, in _create_transport_endpoint
hass_1  |     transport, protocol = yield from loop.create_datagram_endpoint(protofact, family=socket.AF_INET6)
hass_1  |   File "uvloop/loop.pyx", line 2436, in create_datagram_endpoint (uvloop/loop.c:44170)
hass_1  | socket.gaierror: [Errno -9] Address family for hostname not supported
hass_1  | 2017-06-24 09:55:52 ERROR (MainThread) [homeassistant.setup] Unable to setup dependencies of light.tradfri. Setup failed for dependencies: tradfri
hass_1  | 2017-06-24 09:55:52 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform light.tradfri: Could not setup all dependencies.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like it but I'm down to remove uvloop from the Docker container. Make sure we raise an issue with aiocoap and/or uvloop. Not sure where the problem is.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, I'm not happy about it either. Hopefully we can re-enable it soon.


# BEGIN: Development additions

Expand Down
22 changes: 22 additions & 0 deletions virtualization/Docker/scripts/aiocoap
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh
# Installs a modified coap client with support for dtls for use with IKEA Tradfri

# Stop on errors
set -e

python3 -m pip install cython

mkdir -p /usr/src/build
cd /usr/src/build

git clone --depth 1 https://git.fslab.de/jkonra2m/tinydtls
cd tinydtls
autoreconf
./configure --with-ecc --without-debug
cd cython
python3 setup.py install

cd ../..
git clone --depth 1 -b tinydtls https://github.com/chrysn/aiocoap/
cd aiocoap
python3 -m pip install .
Loading