Пример #1
0
async def hacs_startup():
    """HACS startup tasks."""
    hacs = get_hacs()
    if not check_requirements():
        return False
    if hacs.configuration.debug:
        try:
            await hacs.hass.services.async_call("logger", "set_level",
                                                {"hacs": "debug"})
            await hacs.hass.services.async_call("logger", "set_level",
                                                {"queueman": "debug"})
            await hacs.hass.services.async_call("logger", "set_level",
                                                {"AioGitHub": "debug"})
        except ServiceNotFound:
            hacs.logger.error(
                "Could not set logging level to debug, logger is not enabled")

    lovelace_info = await system_health_info(hacs.hass)
    hacs.logger.debug(f"Configuration type: {hacs.configuration.config_type}")
    hacs.version = VERSION
    hacs.logger.info(STARTUP)
    hacs.system.config_path = hacs.hass.config.path()
    hacs.system.ha_version = HAVERSION

    hacs.system.lovelace_mode = lovelace_info.get("mode", "yaml")
    hacs.system.disabled = False
    hacs.github = AIOGitHub(hacs.configuration.token,
                            async_create_clientsession(hacs.hass))
    hacs.data = HacsData()

    can_update = await get_fetch_updates_for(hacs.github)
    if can_update == 0:
        hacs.logger.info(
            "HACS is ratelimited, repository updates will resume in 1h.")
    else:
        hacs.logger.debug(f"Can update {can_update} repositories")

    # Check HACS Constrains
    if not await hacs.hass.async_add_executor_job(check_constans):
        if hacs.configuration.config_type == "flow":
            if hacs.configuration.config_entry is not None:
                await async_remove_entry(hacs.hass,
                                         hacs.configuration.config_entry)
        return False

    # Set up frontend
    await setup_frontend()

    if not await hacs.hass.async_add_executor_job(internet_connectivity_check):
        hacs.logger.critical("No network connectivity")
        return False

    # Load HACS
    if not await load_hacs_repository():
        if hacs.configuration.config_type == "flow":
            if hacs.configuration.config_entry is not None:
                await async_remove_entry(hacs.hass,
                                         hacs.configuration.config_entry)
        return False

    # Restore from storefiles
    if not await hacs.data.restore():
        hacs_repo = hacs.get_by_name("hacs/integration")
        hacs_repo.pending_restart = True
        if hacs.configuration.config_type == "flow":
            if hacs.configuration.config_entry is not None:
                await async_remove_entry(hacs.hass,
                                         hacs.configuration.config_entry)
        return False

    # Add aditional categories
    hacs.common.categories = ELEMENT_TYPES
    if hacs.configuration.appdaemon:
        hacs.common.categories.append("appdaemon")
    if hacs.configuration.netdaemon:
        hacs.common.categories.append("netdaemon")
    if hacs.configuration.python_script:
        hacs.configuration.python_script = False
        if hacs.configuration.config_type == "yaml":
            hacs.logger.warning(
                "Configuration option 'python_script' is deprecated and you should remove it from your configuration, HACS will know if you use 'python_script' in your Home Assistant configuration, this option will be removed in a future release."
            )
    if hacs.configuration.theme:
        hacs.configuration.theme = False
        if hacs.configuration.config_type == "yaml":
            hacs.logger.warning(
                "Configuration option 'theme' is deprecated and you should remove it from your configuration, HACS will know if you use 'theme' in your Home Assistant configuration, this option will be removed in a future release."
            )

    # Setup startup tasks
    if hacs.configuration.config_type == "yaml":
        hacs.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_START,
                                        hacs.startup_tasks())
    else:
        async_call_later(hacs.hass, 5, hacs.startup_tasks())

    # Show the configuration
    hacs.configuration.print()

    # Set up sensor
    await hacs.hass.async_add_executor_job(add_sensor)

    # Mischief managed!
    return True
Пример #2
0
def test_requirements():
    assert check_requirements()