* Split initialization from data retrival * Await class initialization * Async camera * More async * Remove stale code * Clean up * Update tests * Fix test * Improve error handling * Bump pyatmo version to 5.0.0 * Add tests * Add cloudhook test * Increase coverage * Add test with no camera devices * Add test for ApiError * Add test for timeout * Clean up * Catch pyatmo ApiError * Fix PublicData * Fix media source bug * Increase coverage for light * Test webhook with delayed start * Increase coverage * Clean up leftover data classes * Make nonprivate * Review comments * Clean up stale code * Increase cov * Clean up code * Code clean up * Revert delay * Update homeassistant/components/netatmo/climate.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/netatmo/sensor.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Address comment * Raise cov Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
24 lines
834 B
Python
24 lines
834 B
Python
"""API for Netatmo bound to HASS OAuth."""
|
|
from aiohttp import ClientSession
|
|
import pyatmo
|
|
|
|
from homeassistant.helpers import config_entry_oauth2_flow
|
|
|
|
|
|
class AsyncConfigEntryNetatmoAuth(pyatmo.auth.AbstractAsyncAuth):
|
|
"""Provide Netatmo authentication tied to an OAuth2 based config entry."""
|
|
|
|
def __init__(
|
|
self,
|
|
websession: ClientSession,
|
|
oauth_session: config_entry_oauth2_flow.OAuth2Session,
|
|
) -> None:
|
|
"""Initialize the auth."""
|
|
super().__init__(websession)
|
|
self._oauth_session = oauth_session
|
|
|
|
async def async_get_access_token(self):
|
|
"""Return a valid access token for Netatmo API."""
|
|
if not self._oauth_session.valid_token:
|
|
await self._oauth_session.async_ensure_token_valid()
|
|
return self._oauth_session.token["access_token"]
|