Пример #1
0
async def async_setup_platform(hass,
                               config,
                               async_add_entities,
                               discovery_info=None):
    """Set up the OpenGarage covers."""
    covers = []
    devices = config.get(CONF_COVERS)

    for device_config in devices.values():
        opengarage_url = (
            f"{'https' if device_config[CONF_SSL] else 'http'}://"
            f"{device_config.get(CONF_HOST)}:{device_config.get(CONF_PORT)}")

        open_garage = opengarage.OpenGarage(
            opengarage_url,
            device_config[CONF_DEVICE_KEY],
            device_config[CONF_VERIFY_SSL],
            async_get_clientsession(hass),
        )
        status = await open_garage.update_state()
        covers.append(
            OpenGarageCover(device_config.get(CONF_NAME), open_garage,
                            format_mac(status["mac"])))

    async_add_entities(covers, True)
Пример #2
0
async def validate_input(hass: HomeAssistant,
                         data: dict[str, Any]) -> dict[str, Any]:
    """Validate the user input allows us to connect.

    Data has the keys from STEP_USER_DATA_SCHEMA with values provided by the user.
    """
    open_garage = opengarage.OpenGarage(
        f"{data[CONF_HOST]}:{data[CONF_PORT]}",
        data[CONF_DEVICE_KEY],
        data[CONF_VERIFY_SSL],
        async_get_clientsession(hass),
    )

    try:
        status = await open_garage.update_state()
    except aiohttp.ClientError as exp:
        raise CannotConnect from exp

    if status is None:
        raise InvalidAuth

    return {
        "title": status.get("name"),
        "unique_id": format_mac(status["mac"])
    }
Пример #3
0
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
    """Set up OpenGarage from a config entry."""
    hass.data.setdefault(DOMAIN, {})

    hass.data[DOMAIN][entry.entry_id] = opengarage.OpenGarage(
        f"{entry.data[CONF_HOST]}:{entry.data[CONF_PORT]}",
        entry.data[CONF_DEVICE_KEY],
        entry.data[CONF_VERIFY_SSL],
        async_get_clientsession(hass),
    )

    hass.config_entries.async_setup_platforms(entry, PLATFORMS)

    return True
Пример #4
0
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
    """Set up OpenGarage from a config entry."""
    hass.data.setdefault(DOMAIN, {})

    open_garage_connection = opengarage.OpenGarage(
        f"{entry.data[CONF_HOST]}:{entry.data[CONF_PORT]}",
        entry.data[CONF_DEVICE_KEY],
        entry.data[CONF_VERIFY_SSL],
        async_get_clientsession(hass),
    )
    open_garage_data_coordinator = OpenGarageDataUpdateCoordinator(
        hass,
        open_garage_connection=open_garage_connection,
    )
    await open_garage_data_coordinator.async_config_entry_first_refresh()
    hass.data[DOMAIN][entry.entry_id] = open_garage_data_coordinator

    hass.config_entries.async_setup_platforms(entry, PLATFORMS)

    return True