Skip to content

Commit 26f6828

Browse files
committed
Initial connect is working
* custom_components/daikin_residential_altherma/__init__.py: * custom_components/daikin_residential_altherma/config_flow.py: * custom_components/daikin_residential_altherma/daikin_api.py:
1 parent 833e1d0 commit 26f6828

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

custom_components/daikin_residential_altherma/__init__.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
88
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD, SERVICE_RELOAD
99
from homeassistant.helpers.typing import HomeAssistantType
10+
from homeassistant.helpers import config_entry_oauth2_flow
1011

1112
from .const import DOMAIN, DAIKIN_API, DAIKIN_DEVICES, CONF_TOKENSET
1213

@@ -77,8 +78,13 @@ async def _handle_reload(service):
7778

7879
async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry):
7980
"""Establish connection with Daikin."""
81+
implementation = (
82+
await config_entry_oauth2_flow.async_get_config_entry_implementation(
83+
hass, entry
84+
)
85+
)
8086

81-
daikin_api = DaikinApi(hass, entry)
87+
daikin_api = DaikinApi(hass, entry, implementation)
8288
await daikin_api.getCloudDeviceDetails()
8389

8490
devices = await daikin_api.getCloudDevices()

custom_components/daikin_residential_altherma/config_flow.py

-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ async def async_oauth_create_entry(self, data: dict) -> FlowResult:
4343

4444
return await super().async_oauth_create_entry(data)
4545

46-
4746
async def async_step_user(self, user_input: dict | None = None) -> FlowResult:
4847
"""Handle a flow start."""
4948
await self.async_set_unique_id(DOMAIN)
@@ -67,7 +66,6 @@ async def async_step_reauth_confirm(
6766
if user_input is None:
6867
return self.async_show_form(step_id="reauth_confirm")
6968

70-
7169
@property
7270
def logger(self) -> logging.Logger:
7371
"""Return logger."""

custom_components/daikin_residential_altherma/daikin_api.py

+18-6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
from homeassistant.util import Throttle
1616
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD
17+
from homeassistant.helpers import config_entry_oauth2_flow
18+
from homeassistant import config_entries, core
1719

1820
from .const import DOMAIN, DAIKIN_DEVICES, CONF_TOKENSET
1921

@@ -32,15 +34,24 @@
3234
class DaikinApi:
3335
"""Daikin Residential API."""
3436

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,):
3641
"""Initialize a new Daikin Residential Altherma API."""
3742
_LOGGER.debug("Initialing Daikin Residential Altherma API...")
3843
self.hass = hass
3944
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()
4153

42-
if entry is not None:
43-
self.tokenSet = entry.data[CONF_TOKENSET].copy()
54+
#self.tokenSet["access_token"] = self.session.token
4455

4556
configuration = {
4657
"issuer": DAIKIN_ISSUER,
@@ -70,18 +81,19 @@ async def doBearerRequest(self, resourceUrl, options=None, refreshed=False):
7081
raise Exception("Missing TokenSet. Please repeat Authentication process.")
7182

7283
if not resourceUrl.startswith("http"):
73-
resourceUrl = "https://api.prod.unicloud.edc.dknadmin.be" + resourceUrl
84+
resourceUrl = "https://api.onecta.daikineurope.com" + resourceUrl
7485

7586
headers = {
7687
"user-agent": "Daikin/1.6.1.4681 CFNetwork/1209 Darwin/20.2.0",
7788
"x-api-key": "xw6gvOtBHq5b1pyceadRp6rujSNSZdjx2AqT03iC",
78-
"Authorization": "Bearer " + self.tokenSet["access_token"],
89+
"Authorization": "Bearer " + self.session.token["access_token"],
7990
"Content-Type": "application/json",
8091
}
8192

8293
async with self._cloud_lock:
8394
_LOGGER.debug("BEARER REQUEST URL: %s", resourceUrl)
8495
_LOGGER.debug("BEARER REQUEST HEADERS: %s", headers)
96+
_LOGGER.debug("TOKEN: %s", self.session.token["access_token"])
8597
if (
8698
options is not None
8799
and "method" in options

0 commit comments

Comments
 (0)