Pass hass_config to load_platform (#17952)
* Pass hass_config to load_platform * Fix tests * Lint
This commit is contained in:
1 parent
04e0fd1d46
commit
3a8891d9ac
21 files changed
+70
-57
No files matched your search
@@ -88,7 +88,7 @@ DEVICE_SCHEMA = vol.Schema({
|
||||
}, extra=vol.ALLOW_EXTRA)
|
||||
|
||||
|
||||
def do_authentication(hass, config):
|
||||
def do_authentication(hass, hass_config, config):
|
||||
"""Notify user of actions and authenticate.
|
||||
|
||||
Notify user of user_code and verification_url then poll
|
||||
@@ -145,7 +145,7 @@ def do_authentication(hass, config):
|
||||
|
||||
storage = Storage(hass.config.path(TOKEN_FILE))
|
||||
storage.put(credentials)
|
||||
do_setup(hass, config)
|
||||
do_setup(hass, hass_config, config)
|
||||
listener()
|
||||
hass.components.persistent_notification.create(
|
||||
'We are all setup now. Check {} for calendars that have '
|
||||
@@ -167,14 +167,15 @@ def setup(hass, config):
|
||||
|
||||
token_file = hass.config.path(TOKEN_FILE)
|
||||
if not os.path.isfile(token_file):
|
||||
do_authentication(hass, conf)
|
||||
do_authentication(hass, config, conf)
|
||||
else:
|
||||
do_setup(hass, conf)
|
||||
do_setup(hass, config, conf)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def setup_services(hass, track_new_found_calendars, calendar_service):
|
||||
def setup_services(hass, hass_config, track_new_found_calendars,
|
||||
calendar_service):
|
||||
"""Set up the service listeners."""
|
||||
def _found_calendar(call):
|
||||
"""Check if we know about a calendar and generate PLATFORM_DISCOVER."""
|
||||
@@ -190,7 +191,8 @@ def setup_services(hass, track_new_found_calendars, calendar_service):
|
||||
)
|
||||
|
||||
discovery.load_platform(hass, 'calendar', DOMAIN,
|
||||
hass.data[DATA_INDEX][calendar[CONF_CAL_ID]])
|
||||
hass.data[DATA_INDEX][calendar[CONF_CAL_ID]],
|
||||
hass_config)
|
||||
|
||||
hass.services.register(
|
||||
DOMAIN, SERVICE_FOUND_CALENDARS, _found_calendar)
|
||||
@@ -210,7 +212,7 @@ def setup_services(hass, track_new_found_calendars, calendar_service):
|
||||
return True
|
||||
|
||||
|
||||
def do_setup(hass, config):
|
||||
def do_setup(hass, hass_config, config):
|
||||
"""Run the setup after we have everything configured."""
|
||||
# Load calendars the user has configured
|
||||
hass.data[DATA_INDEX] = load_config(hass.config.path(YAML_DEVICES))
|
||||
@@ -218,13 +220,15 @@ def do_setup(hass, config):
|
||||
calendar_service = GoogleCalendarService(hass.config.path(TOKEN_FILE))
|
||||
track_new_found_calendars = convert(config.get(CONF_TRACK_NEW),
|
||||
bool, DEFAULT_CONF_TRACK_NEW)
|
||||
setup_services(hass, track_new_found_calendars, calendar_service)
|
||||
setup_services(hass, hass_config, track_new_found_calendars,
|
||||
calendar_service)
|
||||
|
||||
# Ensure component is loaded
|
||||
setup_component(hass, 'calendar', config)
|
||||
|
||||
for calendar in hass.data[DATA_INDEX].values():
|
||||
discovery.load_platform(hass, 'calendar', DOMAIN, calendar)
|
||||
discovery.load_platform(hass, 'calendar', DOMAIN, calendar,
|
||||
hass_config)
|
||||
|
||||
# Look for any new calendars
|
||||
hass.services.call(DOMAIN, SERVICE_SCAN_CALENDARS, None)
|
||||
|
||||
Reference in new issue
Block a user