Skip to content

Commit

Permalink
Improved handling of config entry vs yaml config
Browse files Browse the repository at this point in the history
  • Loading branch information
cgarwood committed Jul 12, 2019
1 parent a30c370 commit 44f448d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
22 changes: 13 additions & 9 deletions homeassistant/components/zwave/__init__.py
Expand Up @@ -26,12 +26,13 @@

from . import const
from . import config_flow # noqa pylint: disable=unused-import
from . import websocket_api as wsapi
from .const import (
CONF_AUTOHEAL, CONF_DEBUG, CONF_POLLING_INTERVAL,
CONF_USB_STICK_PATH, CONF_CONFIG_PATH, CONF_NETWORK_KEY,
DEFAULT_CONF_AUTOHEAL, DEFAULT_CONF_USB_STICK_PATH,
DEFAULT_POLLING_INTERVAL, DEFAULT_DEBUG, DOMAIN,
DATA_DEVICES, DATA_NETWORK, DATA_ENTITY_VALUES)
DATA_DEVICES, DATA_NETWORK, DATA_ENTITY_VALUES, DATA_ZWAVE_CONFIG)
from .node_entity import ZWaveBaseEntity, ZWaveNodeEntity
from . import workaround
from .discovery_schemas import DISCOVERY_SCHEMAS
Expand All @@ -55,8 +56,6 @@
CONF_DEVICE_CONFIG_GLOB = 'device_config_glob'
CONF_DEVICE_CONFIG_DOMAIN = 'device_config_domain'

DATA_ZWAVE_CONFIG = 'zwave_config'

DEFAULT_CONF_IGNORED = False
DEFAULT_CONF_INVERT_OPENCLOSE_BUTTONS = False
DEFAULT_CONF_INVERT_PERCENT = False
Expand Down Expand Up @@ -265,9 +264,13 @@ async def async_setup_entry(hass, config_entry):
from openzwave.network import ZWaveNetwork
from openzwave.group import ZWaveGroup

config = {}
# Merge config entry and yaml config
config = config_entry.data
if DATA_ZWAVE_CONFIG in hass.data:
config = hass.data[DATA_ZWAVE_CONFIG]
config.update(hass.data[DATA_ZWAVE_CONFIG])

# Update hass.data with merged config so we can access it elsewhere
hass.data[DATA_ZWAVE_CONFIG] = config

# Load configuration
use_debug = config.get(CONF_DEBUG, DEFAULT_DEBUG)
Expand All @@ -278,8 +281,7 @@ async def async_setup_entry(hass, config_entry):
config.get(CONF_DEVICE_CONFIG_DOMAIN),
config.get(CONF_DEVICE_CONFIG_GLOB))

usb_path = config.get(
CONF_USB_STICK_PATH, config_entry.data[CONF_USB_STICK_PATH])
usb_path = config[CONF_USB_STICK_PATH]

_LOGGER.info('Z-Wave USB path is %s', usb_path)

Expand All @@ -291,8 +293,8 @@ async def async_setup_entry(hass, config_entry):

options.set_console_output(use_debug)

if config_entry.data.get(CONF_NETWORK_KEY):
options.addOption("NetworkKey", config_entry.data[CONF_NETWORK_KEY])
if config.get(CONF_NETWORK_KEY):
options.addOption("NetworkKey", config[CONF_NETWORK_KEY])

await hass.async_add_executor_job(options.lock)
network = hass.data[DATA_NETWORK] = ZWaveNetwork(options, autostart=False)
Expand All @@ -301,6 +303,8 @@ async def async_setup_entry(hass, config_entry):

registry = await async_get_registry(hass)

wsapi.async_load_websocket_api(hass)

if use_debug: # pragma: no cover
def log_all(signal, value=None):
"""Log all the signals."""
Expand Down
25 changes: 13 additions & 12 deletions homeassistant/components/zwave/const.py
Expand Up @@ -19,27 +19,28 @@
ATTR_POLL_INTENSITY = "poll_intensity"
ATTR_VALUE_INDEX = "value_index"
ATTR_VALUE_INSTANCE = "value_instance"
ATTR_UPDATE_IDS = 'update_ids'
ATTR_UPDATE_IDS = "update_ids"
NETWORK_READY_WAIT_SECS = 300
NODE_READY_WAIT_SECS = 30

CONF_AUTOHEAL = 'autoheal'
CONF_DEBUG = 'debug'
CONF_POLLING_INTERVAL = 'polling_interval'
CONF_USB_STICK_PATH = 'usb_path'
CONF_CONFIG_PATH = 'config_path'
CONF_NETWORK_KEY = 'network_key'
CONF_AUTOHEAL = "autoheal"
CONF_DEBUG = "debug"
CONF_POLLING_INTERVAL = "polling_interval"
CONF_USB_STICK_PATH = "usb_path"
CONF_CONFIG_PATH = "config_path"
CONF_NETWORK_KEY = "network_key"

DEFAULT_CONF_AUTOHEAL = False
DEFAULT_CONF_USB_STICK_PATH = '/zwaveusbstick'
DEFAULT_CONF_USB_STICK_PATH = "/zwaveusbstick"
DEFAULT_POLLING_INTERVAL = 60000
DEFAULT_DEBUG = False

DISCOVERY_DEVICE = 'device'
DISCOVERY_DEVICE = "device"

DATA_DEVICES = 'zwave_devices'
DATA_NETWORK = 'zwave_network'
DATA_ENTITY_VALUES = 'zwave_entity_values'
DATA_DEVICES = "zwave_devices"
DATA_NETWORK = "zwave_network"
DATA_ENTITY_VALUES = "zwave_entity_values"
DATA_ZWAVE_CONFIG = "zwave_config"

SERVICE_CHANGE_ASSOCIATION = "change_association"
SERVICE_ADD_NODE = "add_node"
Expand Down

0 comments on commit 44f448d

Please sign in to comment.