|
14 | 14 |
|
15 | 15 | from homeassistant.util import Throttle
|
16 | 16 | from homeassistant.const import CONF_EMAIL, CONF_PASSWORD
|
| 17 | +from homeassistant.helpers import config_entry_oauth2_flow |
| 18 | +from homeassistant import config_entries, core |
17 | 19 |
|
18 | 20 | from .const import DOMAIN, DAIKIN_DEVICES, CONF_TOKENSET
|
19 | 21 |
|
|
32 | 34 | class DaikinApi:
|
33 | 35 | """Daikin Residential API."""
|
34 | 36 |
|
35 |
| - def __init__(self, hass, entry): |
| 37 | + def __init__(self, |
| 38 | + hass: core.HomeAssistant, |
| 39 | + entry: config_entries.ConfigEntry, |
| 40 | + implementation: config_entry_oauth2_flow.AbstractOAuth2Implementation,): |
36 | 41 | """Initialize a new Daikin Residential Altherma API."""
|
37 | 42 | _LOGGER.debug("Initialing Daikin Residential Altherma API...")
|
38 | 43 | self.hass = hass
|
39 | 44 | self._config_entry = entry
|
40 |
| - self.tokenSet = None |
| 45 | + self.session = config_entry_oauth2_flow.OAuth2Session( |
| 46 | + hass, entry, implementation |
| 47 | + ) |
| 48 | + |
| 49 | + self.tokenSet = [] |
| 50 | + |
| 51 | +# if entry is not None: |
| 52 | +# self.tokenSet = entry.data[CONF_TOKENSET].copy() |
41 | 53 |
|
42 |
| - if entry is not None: |
43 |
| - self.tokenSet = entry.data[CONF_TOKENSET].copy() |
| 54 | + #self.tokenSet["access_token"] = self.session.token |
44 | 55 |
|
45 | 56 | configuration = {
|
46 | 57 | "issuer": DAIKIN_ISSUER,
|
@@ -70,18 +81,19 @@ async def doBearerRequest(self, resourceUrl, options=None, refreshed=False):
|
70 | 81 | raise Exception("Missing TokenSet. Please repeat Authentication process.")
|
71 | 82 |
|
72 | 83 | if not resourceUrl.startswith("http"):
|
73 |
| - resourceUrl = "https://api.prod.unicloud.edc.dknadmin.be" + resourceUrl |
| 84 | + resourceUrl = "https://api.onecta.daikineurope.com" + resourceUrl |
74 | 85 |
|
75 | 86 | headers = {
|
76 | 87 | "user-agent": "Daikin/1.6.1.4681 CFNetwork/1209 Darwin/20.2.0",
|
77 | 88 | "x-api-key": "xw6gvOtBHq5b1pyceadRp6rujSNSZdjx2AqT03iC",
|
78 |
| - "Authorization": "Bearer " + self.tokenSet["access_token"], |
| 89 | + "Authorization": "Bearer " + self.session.token["access_token"], |
79 | 90 | "Content-Type": "application/json",
|
80 | 91 | }
|
81 | 92 |
|
82 | 93 | async with self._cloud_lock:
|
83 | 94 | _LOGGER.debug("BEARER REQUEST URL: %s", resourceUrl)
|
84 | 95 | _LOGGER.debug("BEARER REQUEST HEADERS: %s", headers)
|
| 96 | + _LOGGER.debug("TOKEN: %s", self.session.token["access_token"]) |
85 | 97 | if (
|
86 | 98 | options is not None
|
87 | 99 | and "method" in options
|
|
0 commit comments