Improve Smappee integration (#37087)

This commit is contained in:
bsmappee 2020-06-26 19:46:14 +02:00 committed by GitHub
parent fe5bf96e5d
commit 680f8f8d5a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 41 additions and 35 deletions

View file

@ -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."""