Improve Smappee integration (#37087)
This commit is contained in:
1 parent
fe5bf96e5d
commit
680f8f8d5a
7 files changed
+41
-35
No files matched your search
@@ -4,8 +4,11 @@ from asyncio import run_coroutine_threadsafe
|
||||
from pysmappee import api
|
||||
|
||||
from homeassistant import config_entries, core
|
||||
from homeassistant.const import CONF_PLATFORM
|
||||
from homeassistant.helpers import config_entry_oauth2_flow
|
||||
|
||||
from .const import DOMAIN
|
||||
|
||||
|
||||
class ConfigEntrySmappeeApi(api.SmappeeApi):
|
||||
"""Provide Smappee authentication tied to an OAuth2 based config entry."""
|
||||
@@ -22,7 +25,18 @@ class ConfigEntrySmappeeApi(api.SmappeeApi):
|
||||
self.session = config_entry_oauth2_flow.OAuth2Session(
|
||||
hass, config_entry, implementation
|
||||
)
|
||||
super().__init__(None, None, token=self.session.token)
|
||||
|
||||
platform_to_farm = {
|
||||
"PRODUCTION": 1,
|
||||
"ACCEPTANCE": 2,
|
||||
"DEVELOPMENT": 3,
|
||||
}
|
||||
super().__init__(
|
||||
None,
|
||||
None,
|
||||
token=self.session.token,
|
||||
farm=platform_to_farm[hass.data[DOMAIN][CONF_PLATFORM]],
|
||||
)
|
||||
|
||||
def refresh_tokens(self) -> dict:
|
||||
"""Refresh and return new Smappee tokens using Home Assistant OAuth2 session."""
|
||||
|
||||
Reference in new issue
Block a user