Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 5 additions & 3 deletions homeassistant/components/light/tradfri.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
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
from homeassistant.components.tradfri import KEY_GATEWAY, KEY_TRADFRI_GROUPS
from homeassistant.util import color as color_util

_LOGGER = logging.getLogger(__name__)
Expand All @@ -35,8 +35,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
lights = [dev for dev in devices if dev.has_light_control]
add_devices(Tradfri(light) for light in lights)

groups = gateway.get_groups()
add_devices(TradfriGroup(group) for group in groups)
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)


class TradfriGroup(Light):
Expand Down
24 changes: 19 additions & 5 deletions homeassistant/components/tradfri.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,22 @@
from homeassistant.loader import get_component
from homeassistant.components.discovery import SERVICE_IKEA_TRADFRI

REQUIREMENTS = ['pytradfri==1.1']

DOMAIN = 'tradfri'
CONFIG_FILE = 'tradfri.conf'
KEY_CONFIG = 'tradfri_configuring'
KEY_GATEWAY = 'tradfri_gateway'
REQUIREMENTS = ['pytradfri==1.1']
KEY_TRADFRI_GROUPS = 'tradfri_allow_tradfri_groups'
CONF_ALLOW_TRADFRI_GROUPS = 'allow_tradfri_groups'
DEFAULT_ALLOW_TRADFRI_GROUPS = True

CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.Schema({
vol.Inclusive(CONF_HOST, 'gateway'): cv.string,
vol.Inclusive(CONF_API_KEY, 'gateway'): cv.string,
vol.Optional(CONF_ALLOW_TRADFRI_GROUPS,
default=DEFAULT_ALLOW_TRADFRI_GROUPS): cv.boolean,
})
}, extra=vol.ALLOW_EXTRA)

Expand All @@ -47,7 +53,8 @@ def request_configuration(hass, config, host):
def configuration_callback(callback_data):
"""Handle the submitted configuration."""
res = yield from _setup_gateway(hass, config, host,
callback_data.get('key'))
callback_data.get('key'),
DEFAULT_ALLOW_TRADFRI_GROUPS)
if not res:
hass.async_add_job(configurator.notify_errors, instance,
"Unable to connect.")
Expand Down Expand Up @@ -77,6 +84,7 @@ def async_setup(hass, config):
conf = config.get(DOMAIN, {})
host = conf.get(CONF_HOST)
key = conf.get(CONF_API_KEY)
allow_tradfri_groups = conf.get(CONF_ALLOW_TRADFRI_GROUPS)

@asyncio.coroutine
def gateway_discovered(service, info):
Expand All @@ -85,7 +93,8 @@ def gateway_discovered(service, info):
host = info['host']

if host in keys:
yield from _setup_gateway(hass, config, host, keys[host]['key'])
yield from _setup_gateway(hass, config, host, keys[host]['key'],
allow_tradfri_groups)
else:
hass.async_add_job(request_configuration, hass, config, host)

Expand All @@ -94,11 +103,12 @@ def gateway_discovered(service, info):
if host is None:
return True

return (yield from _setup_gateway(hass, config, host, key))
return (yield from _setup_gateway(hass, config, host, key,
allow_tradfri_groups))


@asyncio.coroutine
def _setup_gateway(hass, hass_config, host, key):
def _setup_gateway(hass, hass_config, host, key, allow_tradfri_groups):
"""Create a gateway."""
from pytradfri import cli_api_factory, Gateway, RequestError, retry_timeout

Expand All @@ -112,6 +122,10 @@ def _setup_gateway(hass, hass_config, host, key):
hass.data.setdefault(KEY_GATEWAY, {})
gateways = hass.data[KEY_GATEWAY]

hass.data.setdefault(KEY_TRADFRI_GROUPS, {})
tradfri_groups = hass.data[KEY_TRADFRI_GROUPS]
tradfri_groups[gateway_id] = allow_tradfri_groups

# Check if already set up
if gateway_id in gateways:
return True
Expand Down