async def main(): """Show example on using the ToonAPI.""" async with Toon(token="put-in-token-here") as toon: agreements = await toon.agreements() print(agreements) await toon.activate_agreement(agreement=agreements[0]) status = await toon.update() print(status.gas_usage) print(status.thermostat) print(status.power_usage)
async def async_oauth_create_entry(self, data: dict[str, Any]) -> FlowResult: """Test connection and load up agreements.""" self.data = data toon = Toon( token=self.data["token"]["access_token"], session=async_get_clientsession(self.hass), ) try: self.agreements = await toon.agreements() except ToonError: return self.async_abort(reason="connection_error") if not self.agreements: return self.async_abort(reason="no_agreements") return await self.async_step_agreement()
def __init__( self, hass: HomeAssistant, *, entry: ConfigEntry, session: OAuth2Session ) -> None: """Initialize global Toon data updater.""" self.session = session self.entry = entry async def async_token_refresh() -> str: await session.async_ensure_token_valid() return session.token["access_token"] self.toon = Toon( token=session.token["access_token"], session=async_get_clientsession(hass), token_refresh_method=async_token_refresh, ) super().__init__( hass, _LOGGER, name=DOMAIN, update_interval=DEFAULT_SCAN_INTERVAL )