Exemple #1
0
class FullyKioskDataUpdateCoordinator(DataUpdateCoordinator):
    """Define an object to hold Fully Kiosk Browser data."""
    def __init__(self, hass: HomeAssistantType, session: ClientSession, host,
                 port, password):
        """Initialize."""
        self.fully = FullyKiosk(session, host, port, password)

        super().__init__(
            hass,
            _LOGGER,
            name=f"{host} deviceInfo",
            update_interval=timedelta(seconds=UPDATE_INTERVAL),
        )

    async def _async_update_data(self):
        """Update data via library."""
        try:
            with timeout(15):
                """Get device info and settings in parallel"""
                result = await asyncio.gather(self.fully.getDeviceInfo(),
                                              self.fully.getSettings())
                """Store settings under settings key in data"""
                result[0]["settings"] = result[1]
                return result[0]
        except (FullyKioskError, ClientConnectorError) as error:
            raise UpdateFailed(error) from error
Exemple #2
0
class FullyKioskDataUpdateCoordinator(DataUpdateCoordinator):
    """Define an object to hold Fully Kiosk Browser data."""
    def __init__(self, hass: HomeAssistant, entry: ConfigEntry) -> None:
        """Initialize."""
        self.fully = FullyKiosk(
            async_get_clientsession(hass),
            entry.data[CONF_HOST],
            DEFAULT_PORT,
            entry.data[CONF_PASSWORD],
        )
        super().__init__(
            hass,
            LOGGER,
            name=entry.data[CONF_HOST],
            update_interval=UPDATE_INTERVAL,
        )

    async def _async_update_data(self) -> dict[str, Any]:
        """Update data via library."""
        try:
            async with timeout(15):
                # Get device info and settings in parallel
                result = await asyncio.gather(self.fully.getDeviceInfo(),
                                              self.fully.getSettings())
                # Store settings under settings key in data
                result[0]["settings"] = result[1]
                return cast(dict[str, Any], result[0])
        except FullyKioskError as error:
            raise UpdateFailed(error) from error