Skip to content
Snippets Groups Projects
Unverified Commit cc0fb804 authored by Brynley McDonald's avatar Brynley McDonald Committed by GitHub
Browse files

Fix Flick Electric authentication (#134611)

parent 276806d3
No related branches found
No related tags found
No related merge requests found
...@@ -2,10 +2,11 @@ ...@@ -2,10 +2,11 @@
from datetime import datetime as dt from datetime import datetime as dt
import logging import logging
from typing import Any
import jwt import jwt
from pyflick import FlickAPI from pyflick import FlickAPI
from pyflick.authentication import AbstractFlickAuth from pyflick.authentication import SimpleFlickAuth
from pyflick.const import DEFAULT_CLIENT_ID, DEFAULT_CLIENT_SECRET from pyflick.const import DEFAULT_CLIENT_ID, DEFAULT_CLIENT_SECRET
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
...@@ -93,16 +94,22 @@ async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> ...@@ -93,16 +94,22 @@ async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->
return True return True
class HassFlickAuth(AbstractFlickAuth): class HassFlickAuth(SimpleFlickAuth):
"""Implementation of AbstractFlickAuth based on a Home Assistant entity config.""" """Implementation of AbstractFlickAuth based on a Home Assistant entity config."""
def __init__(self, hass: HomeAssistant, entry: ConfigEntry) -> None: def __init__(self, hass: HomeAssistant, entry: FlickConfigEntry) -> None:
"""Flick authentication based on a Home Assistant entity config.""" """Flick authentication based on a Home Assistant entity config."""
super().__init__(aiohttp_client.async_get_clientsession(hass)) super().__init__(
username=entry.data[CONF_USERNAME],
password=entry.data[CONF_PASSWORD],
client_id=entry.data.get(CONF_CLIENT_ID, DEFAULT_CLIENT_ID),
client_secret=entry.data.get(CONF_CLIENT_SECRET, DEFAULT_CLIENT_SECRET),
websession=aiohttp_client.async_get_clientsession(hass),
)
self._entry = entry self._entry = entry
self._hass = hass self._hass = hass
async def _get_entry_token(self): async def _get_entry_token(self) -> dict[str, Any]:
# No token saved, generate one # No token saved, generate one
if ( if (
CONF_TOKEN_EXPIRY not in self._entry.data CONF_TOKEN_EXPIRY not in self._entry.data
...@@ -119,13 +126,8 @@ class HassFlickAuth(AbstractFlickAuth): ...@@ -119,13 +126,8 @@ class HassFlickAuth(AbstractFlickAuth):
async def _update_token(self): async def _update_token(self):
_LOGGER.debug("Fetching new access token") _LOGGER.debug("Fetching new access token")
token = await self.get_new_token( token = await super().get_new_token(
username=self._entry.data[CONF_USERNAME], self._username, self._password, self._client_id, self._client_secret
password=self._entry.data[CONF_PASSWORD],
client_id=self._entry.data.get(CONF_CLIENT_ID, DEFAULT_CLIENT_ID),
client_secret=self._entry.data.get(
CONF_CLIENT_SECRET, DEFAULT_CLIENT_SECRET
),
) )
_LOGGER.debug("New token: %s", token) _LOGGER.debug("New token: %s", token)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment