mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 07:07:28 +00:00
Support new tradfri individual DTLS identification method (#10282)
This commit is contained in:
parent
d9805160bc
commit
79da44a6b3
@ -13,17 +13,18 @@ import voluptuous as vol
|
|||||||
|
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers import discovery
|
from homeassistant.helpers import discovery
|
||||||
from homeassistant.const import CONF_HOST, CONF_API_KEY
|
from homeassistant.const import CONF_HOST
|
||||||
from homeassistant.components.discovery import SERVICE_IKEA_TRADFRI
|
from homeassistant.components.discovery import SERVICE_IKEA_TRADFRI
|
||||||
|
|
||||||
REQUIREMENTS = ['pytradfri==3.0.2',
|
REQUIREMENTS = ['pytradfri==4.0.1',
|
||||||
'DTLSSocket==0.1.4',
|
'DTLSSocket==0.1.4',
|
||||||
'https://github.com/chrysn/aiocoap/archive/'
|
'https://github.com/chrysn/aiocoap/archive/'
|
||||||
'3286f48f0b949901c8b5c04c0719dc54ab63d431.zip'
|
'3286f48f0b949901c8b5c04c0719dc54ab63d431.zip'
|
||||||
'#aiocoap==0.3']
|
'#aiocoap==0.3']
|
||||||
|
|
||||||
DOMAIN = 'tradfri'
|
DOMAIN = 'tradfri'
|
||||||
CONFIG_FILE = 'tradfri.conf'
|
GATEWAY_IDENTITY = 'homeassistant'
|
||||||
|
CONFIG_FILE = '.tradfri_psk.conf'
|
||||||
KEY_CONFIG = 'tradfri_configuring'
|
KEY_CONFIG = 'tradfri_configuring'
|
||||||
KEY_GATEWAY = 'tradfri_gateway'
|
KEY_GATEWAY = 'tradfri_gateway'
|
||||||
KEY_API = 'tradfri_api'
|
KEY_API = 'tradfri_api'
|
||||||
@ -34,7 +35,6 @@ DEFAULT_ALLOW_TRADFRI_GROUPS = True
|
|||||||
CONFIG_SCHEMA = vol.Schema({
|
CONFIG_SCHEMA = vol.Schema({
|
||||||
DOMAIN: vol.Schema({
|
DOMAIN: vol.Schema({
|
||||||
vol.Inclusive(CONF_HOST, 'gateway'): cv.string,
|
vol.Inclusive(CONF_HOST, 'gateway'): cv.string,
|
||||||
vol.Inclusive(CONF_API_KEY, 'gateway'): cv.string,
|
|
||||||
vol.Optional(CONF_ALLOW_TRADFRI_GROUPS,
|
vol.Optional(CONF_ALLOW_TRADFRI_GROUPS,
|
||||||
default=DEFAULT_ALLOW_TRADFRI_GROUPS): cv.boolean,
|
default=DEFAULT_ALLOW_TRADFRI_GROUPS): cv.boolean,
|
||||||
})
|
})
|
||||||
@ -56,9 +56,17 @@ def request_configuration(hass, config, host):
|
|||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def configuration_callback(callback_data):
|
def configuration_callback(callback_data):
|
||||||
"""Handle the submitted configuration."""
|
"""Handle the submitted configuration."""
|
||||||
res = yield from _setup_gateway(hass, config, host,
|
try:
|
||||||
callback_data.get('key'),
|
from pytradfri.api.aiocoap_api import APIFactory
|
||||||
|
except ImportError:
|
||||||
|
_LOGGER.exception("Looks like something isn't installed!")
|
||||||
|
return
|
||||||
|
|
||||||
|
api_factory = APIFactory(host, psk_id=GATEWAY_IDENTITY)
|
||||||
|
psk = yield from api_factory.generate_psk(callback_data.get('key'))
|
||||||
|
res = yield from _setup_gateway(hass, config, host, psk,
|
||||||
DEFAULT_ALLOW_TRADFRI_GROUPS)
|
DEFAULT_ALLOW_TRADFRI_GROUPS)
|
||||||
|
|
||||||
if not res:
|
if not res:
|
||||||
hass.async_add_job(configurator.notify_errors, instance,
|
hass.async_add_job(configurator.notify_errors, instance,
|
||||||
"Unable to connect.")
|
"Unable to connect.")
|
||||||
@ -67,7 +75,7 @@ def request_configuration(hass, config, host):
|
|||||||
def success():
|
def success():
|
||||||
"""Set up was successful."""
|
"""Set up was successful."""
|
||||||
conf = _read_config(hass)
|
conf = _read_config(hass)
|
||||||
conf[host] = {'key': callback_data.get('key')}
|
conf[host] = {'key': psk}
|
||||||
_write_config(hass, conf)
|
_write_config(hass, conf)
|
||||||
hass.async_add_job(configurator.request_done, instance)
|
hass.async_add_job(configurator.request_done, instance)
|
||||||
|
|
||||||
@ -87,13 +95,12 @@ def async_setup(hass, config):
|
|||||||
"""Set up the Tradfri component."""
|
"""Set up the Tradfri component."""
|
||||||
conf = config.get(DOMAIN, {})
|
conf = config.get(DOMAIN, {})
|
||||||
host = conf.get(CONF_HOST)
|
host = conf.get(CONF_HOST)
|
||||||
key = conf.get(CONF_API_KEY)
|
|
||||||
allow_tradfri_groups = conf.get(CONF_ALLOW_TRADFRI_GROUPS)
|
allow_tradfri_groups = conf.get(CONF_ALLOW_TRADFRI_GROUPS)
|
||||||
|
keys = yield from hass.async_add_job(_read_config, hass)
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def gateway_discovered(service, info):
|
def gateway_discovered(service, info):
|
||||||
"""Run when a gateway is discovered."""
|
"""Run when a gateway is discovered."""
|
||||||
keys = yield from hass.async_add_job(_read_config, hass)
|
|
||||||
host = info['host']
|
host = info['host']
|
||||||
|
|
||||||
if host in keys:
|
if host in keys:
|
||||||
@ -104,11 +111,16 @@ def async_setup(hass, config):
|
|||||||
|
|
||||||
discovery.async_listen(hass, SERVICE_IKEA_TRADFRI, gateway_discovered)
|
discovery.async_listen(hass, SERVICE_IKEA_TRADFRI, gateway_discovered)
|
||||||
|
|
||||||
if host is None:
|
if not host:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return (yield from _setup_gateway(hass, config, host, key,
|
if host and keys.get(host):
|
||||||
|
return (yield from _setup_gateway(hass, config, host,
|
||||||
|
keys[host]['key'],
|
||||||
allow_tradfri_groups))
|
allow_tradfri_groups))
|
||||||
|
else:
|
||||||
|
hass.async_add_job(request_configuration, hass, config, host)
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
@ -116,19 +128,21 @@ def _setup_gateway(hass, hass_config, host, key, allow_tradfri_groups):
|
|||||||
"""Create a gateway."""
|
"""Create a gateway."""
|
||||||
from pytradfri import Gateway, RequestError
|
from pytradfri import Gateway, RequestError
|
||||||
try:
|
try:
|
||||||
from pytradfri.api.aiocoap_api import api_factory
|
from pytradfri.api.aiocoap_api import APIFactory
|
||||||
except ImportError:
|
except ImportError:
|
||||||
_LOGGER.exception("Looks like something isn't installed!")
|
_LOGGER.exception("Looks like something isn't installed!")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
api = yield from api_factory(host, key, loop=hass.loop)
|
factory = APIFactory(host, psk_id=GATEWAY_IDENTITY, psk=key,
|
||||||
|
loop=hass.loop)
|
||||||
|
api = factory.request
|
||||||
|
gateway = Gateway()
|
||||||
|
gateway_info_result = yield from api(gateway.get_gateway_info())
|
||||||
except RequestError:
|
except RequestError:
|
||||||
_LOGGER.exception("Tradfri setup failed.")
|
_LOGGER.exception("Tradfri setup failed.")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
gateway = Gateway()
|
|
||||||
gateway_info_result = yield from api(gateway.get_gateway_info())
|
|
||||||
gateway_id = gateway_info_result.id
|
gateway_id = gateway_info_result.id
|
||||||
hass.data.setdefault(KEY_API, {})
|
hass.data.setdefault(KEY_API, {})
|
||||||
hass.data.setdefault(KEY_GATEWAY, {})
|
hass.data.setdefault(KEY_GATEWAY, {})
|
||||||
|
@ -893,7 +893,7 @@ pythonwhois==2.4.3
|
|||||||
pytrackr==0.0.5
|
pytrackr==0.0.5
|
||||||
|
|
||||||
# homeassistant.components.tradfri
|
# homeassistant.components.tradfri
|
||||||
pytradfri==3.0.2
|
pytradfri==4.0.1
|
||||||
|
|
||||||
# homeassistant.components.device_tracker.unifi
|
# homeassistant.components.device_tracker.unifi
|
||||||
pyunifi==2.13
|
pyunifi==2.13
|
||||||
|
Loading…
x
Reference in New Issue
Block a user