# Buggy code
def _recursive_merge(pack_name, comp_name, config, conf, package):
    """Merge package into conf, recursively."""
    for key, pack_conf in package.items():
        if isinstance(pack_conf, dict):
            if not pack_conf:
                continue
            conf[key] = conf.get(key, OrderedDict())
            _recursive_merge(
                pack_name, comp_name, config, conf=conf[key], package=pack_conf
            )

        elif isinstance(pack_conf, list):
            if not pack_conf:
                continue
            conf[key] = cv.ensure_list(conf.get(key))
            conf[key].extend(cv.ensure_list(pack_conf))

        else:
            if conf.get(key) is not None:
                _log_pkg_error(
                    pack_name,
                    comp_name,
                    config,
                    "has keys that are defined multiple times",
                )
            else:
                conf[key] = pack_conf


# Traceback (AttributeError)
2018-06-10 00:27:15 INFO (SyncWorker_0) [homeassistant.config] Upgrading configuration directory from 0.70.1 to 0.71.0
2018-06-10 00:27:15 INFO (SyncWorker_0) [homeassistant.config] Migrating old system configuration files to new locations
2018-06-10 00:27:15 INFO (MainThread) [homeassistant.loader] Loaded device_tracker from homeassistant.components.device_tracker
2018-06-10 00:27:15 INFO (MainThread) [homeassistant.loader] Loaded sensor from homeassistant.components.sensor
2018-06-10 00:27:15 INFO (MainThread) [homeassistant.loader] Loaded automation from homeassistant.components.automation
2018-06-10 00:27:15 INFO (MainThread) [homeassistant.loader] Loaded map from homeassistant.components.map
Traceback (most recent call last):
File "/usr/local/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/local/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/usr/src/app/homeassistant/__main__.py", line 377, in <module>
sys.exit(main())
File "/usr/src/app/homeassistant/__main__.py", line 369, in main
exit_code = setup_and_run_hass(config_dir, args)
File "/usr/src/app/homeassistant/__main__.py", line 274, in setup_and_run_hass
log_no_color=args.log_no_color)
File "/usr/src/app/homeassistant/bootstrap.py", line 179, in from_config_file
log_rotate_days, log_file, log_no_color)
File "uvloop/loop.pyx", line 1422, in uvloop.loop.Loop.run_until_complete
File "/usr/src/app/homeassistant/bootstrap.py", line 215, in async_from_config_file
config_dict, hass, enable_log=False, skip_pip=skip_pip)
File "/usr/src/app/homeassistant/bootstrap.py", line 110, in async_from_config_dict
hass, config, core_config.get(conf_util.CONF_PACKAGES, {}))
File "/usr/src/app/homeassistant/config.py", line 638, in merge_packages_config
conf=config[comp_name], package=comp_conf)
File "/usr/src/app/homeassistant/config.py", line 553, in _recursive_merge
for key, pack_conf in package.items():
AttributeError: 'NoneType' object has no attribute 'items'

# Fixed code
def _recursive_merge(conf, package):
    """Merge package into conf, recursively."""
    error = False
    for key, pack_conf in package.items():
        if isinstance(pack_conf, dict):
            if not pack_conf:
                continue
            conf[key] = conf.get(key, OrderedDict())
            error = _recursive_merge(conf=conf[key], package=pack_conf)

        elif isinstance(pack_conf, list):
            if not pack_conf:
                continue
            conf[key] = cv.ensure_list(conf.get(key))
            conf[key].extend(cv.ensure_list(pack_conf))

        else:
            if conf.get(key) is not None:
                return key
            else:
                conf[key] = pack_conf
    return error