Example #1
0
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
    """Set up Atag integration from a config entry."""
    async def _async_update_data():
        """Update data via library."""
        async with async_timeout.timeout(20):
            try:
                await atag.update()
            except AtagException as err:
                raise UpdateFailed(err) from err
        return atag

    atag = AtagOne(session=async_get_clientsession(hass),
                   **entry.data,
                   device=entry.unique_id)
    coordinator = DataUpdateCoordinator(
        hass,
        _LOGGER,
        name=DOMAIN.title(),
        update_method=_async_update_data,
        update_interval=timedelta(seconds=60),
    )

    await coordinator.async_config_entry_first_refresh()

    hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator
    if entry.unique_id is None:
        hass.config_entries.async_update_entry(entry, unique_id=atag.id)

    hass.config_entries.async_setup_platforms(entry, PLATFORMS)

    return True
Example #2
0
    def __init__(self, hass, session, entry):
        """Initialize."""
        self.atag = AtagOne(session=session, **entry.data)

        super().__init__(hass,
                         _LOGGER,
                         name=DOMAIN,
                         update_interval=timedelta(seconds=30))
Example #3
0
    async def async_step_user(self, user_input=None):
        """Handle a flow initialized by the user."""

        if self._async_current_entries():
            return self.async_abort(reason="already_configured")

        if not user_input:
            return await self._show_form()
        session = async_get_clientsession(self.hass)
        try:
            atag = AtagOne(session=session, **user_input)
            await atag.authorize()
            await atag.update(force=True)

        except AtagException:
            return await self._show_form({"base": "connection_error"})

        user_input.update({CONF_DEVICE: atag.id})
        return self.async_create_entry(title=atag.id, data=user_input)
async def setup(session: aiohttp.ClientSession,
                loop: asyncio.AbstractEventLoop) -> DeviceAtagOne:
    """Setup the connection with the ATAG ONE device."""
    if SETTINGS.atag_host:
        LOGGER.info(f"Using configured ATAG ONE @ {SETTINGS.atag_host}")
    else:
        LOGGER.info("Discovering ATAG ONE")
        atag_ip, _ = await async_discover_atag(
        )  # for auto discovery, requires access to UDP broadcast (hostnet)
        SETTINGS.atag_host = atag_ip
        LOGGER.info(f"Using discovered ATAG ONE @ {SETTINGS.atag_host}")

    atag = AtagOne(SETTINGS.atag_host, session)
    LOGGER.info("Authorizing...")
    await atag.authorize()
    LOGGER.info("Updating...")
    await atag.update(force=True)
    LOGGER.info("Creating Homie device...")
    device = DeviceAtagOne(atag, loop)
    LOGGER.info(
        f"Setup connection from Homie device '{SETTINGS.homie_topic}/{device.device_id}'"
        f" to ATAG ONE @ {atag.host} succeeded")
    return device
Example #5
0
async def run(session):
    """Run example main program."""
    atag_ip, device_id = await async_discover_atag()
    _LOGGER.info(f"Found Atag device {device_id }at address {atag_ip}")
    atag = AtagOne(atag_ip, session)
    try:
        await atag.authorize()
        await atag.update()
    except AtagException as err:
        _LOGGER.error(err)
        return False

    for sensor in atag.report:
        _LOGGER.debug("%s = %s", sensor.name, sensor.state)

    for attribute in dir(atag.climate):
        _LOGGER.debug("atag.climate.%s = %s", attribute,
                      getattr(atag.climate, attribute))

    await atag.climate.set_preset_mode("manual")
    await atag.climate.set_temp(21)

    _LOGGER.debug(atag.report.report_time)
    _LOGGER.debug(atag.dhw.temperature)