Skip to content

Commit 8d0c508

Browse files
authored
Fix password for SkyFi devices (#21)
* fix pass for skyfi devices * update wait and exceptions in _get_resource
1 parent 7d0bebd commit 8d0c508

File tree

3 files changed

+49
-28
lines changed

3 files changed

+49
-28
lines changed

pydaikin/daikin_base.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
from urllib.parse import unquote
1111

1212
from aiohttp import ClientSession
13-
from aiohttp.client_exceptions import ServerDisconnectedError
13+
from aiohttp.client_exceptions import ClientOSError, ServerDisconnectedError
1414
from aiohttp.web_exceptions import HTTPError, HTTPForbidden
1515
from tenacity import (
1616
before_sleep_log,
1717
retry,
1818
retry_if_exception_type,
1919
stop_after_attempt,
20-
wait_fixed,
20+
wait_random_exponential,
2121
)
2222

2323
from .discovery import get_name
@@ -125,9 +125,14 @@ async def init(self):
125125

126126
@retry(
127127
reraise=True,
128-
wait=wait_fixed(1),
128+
wait=wait_random_exponential(multiplier=0.2, max=1.2),
129129
stop=stop_after_attempt(3),
130-
retry=retry_if_exception_type(ServerDisconnectedError),
130+
retry=retry_if_exception_type(
131+
(
132+
ServerDisconnectedError,
133+
ClientOSError,
134+
)
135+
),
131136
before_sleep=before_sleep_log(_LOGGER, logging.DEBUG),
132137
)
133138
async def _get_resource(self, path: str, params: Optional[dict] = None):
@@ -136,7 +141,11 @@ async def _get_resource(self, path: str, params: Optional[dict] = None):
136141
params = {}
137142

138143
_LOGGER.debug(
139-
"Calling: %s/%s %s [%s]", self.base_url, path, params, self.headers
144+
"Calling: %s/%s %s [%s]",
145+
self.base_url,
146+
path,
147+
params if "pass" not in params else {**params, **{"pass": "****"}},
148+
self.headers,
140149
)
141150

142151
# cannot manage session on outer async with or this will close the session

pydaikin/daikin_skyfi.py

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import logging
44
from urllib.parse import unquote
55

6+
from aiohttp import ClientSession
7+
68
from .daikin_base import Appliance
79

810
_LOGGER = logging.getLogger(__name__)
@@ -11,7 +13,7 @@
1113
class DaikinSkyFi(Appliance):
1214
"""Daikin class for SkyFi units."""
1315

14-
HTTP_RESOURCES = ['ac.cgi?pass={}', 'zones.cgi?pass={}']
16+
HTTP_RESOURCES = ['ac.cgi', 'zones.cgi']
1517

1618
INFO_RESOURCES = HTTP_RESOURCES
1719

@@ -47,11 +49,15 @@ class DaikinSkyFi(Appliance):
4749
},
4850
}
4951

50-
def __init__(self, device_id, session=None, password=None) -> None:
52+
def __init__(
53+
self,
54+
device_id: str,
55+
session: ClientSession | None,
56+
password: str,
57+
) -> None:
5158
"""Init the pydaikin appliance, representing one Daikin SkyFi device."""
5259
super().__init__(device_id, session)
53-
self.device_ip = f'{self.device_ip}:2000'
54-
self.base_url = f"http://{self.device_ip}"
60+
self.base_url = f"http://{self.device_ip}:2000"
5561
self._password = password
5662

5763
def __getitem__(self, name):
@@ -102,6 +108,14 @@ def parse_response(response_body):
102108
)
103109
return response
104110

111+
async def _get_resource(self, path: str, params: dict | None = None):
112+
"""Make the http request."""
113+
if params is None:
114+
params = {}
115+
params["pass"] = self._password
116+
117+
return await super()._get_resource(path, params)
118+
105119
def represent(self, key):
106120
"""Return translated value from key."""
107121
k, val = super().represent(self.SKYFI_TO_DAIKIN.get(key, key))
@@ -115,7 +129,7 @@ def represent(self, key):
115129
async def set(self, settings):
116130
"""Set settings on Daikin device."""
117131
_LOGGER.debug("Updating settings: %s", settings)
118-
await self.update_status(['ac.cgi?pass={}'])
132+
await self.update_status(['ac.cgi'])
119133

120134
# Merge current_val with mapped settings
121135
self.values.update(
@@ -129,19 +143,20 @@ async def set(self, settings):
129143
# we are using an extra mode "off" to power off the unit
130144
if settings.get('mode', '') == 'off':
131145
self.values['opmode'] = '0'
132-
query_c = 'set.cgi?pass={}&p=0'
146+
params = {
147+
"p": self.values['opmode'],
148+
}
133149
else:
134150
if 'mode' in settings:
135151
self.values['opmode'] = '1'
136-
query_c = (
137-
f"set.cgi?pass={{}}"
138-
f"&p={self.values['opmode']}"
139-
f"&t={self.values['settemp']}"
140-
f"&f={self.values['fanspeed']}"
141-
f"&m={self.values['acmode']}"
142-
)
152+
params = {
153+
"p": self.values['opmode'],
154+
"t": self.values['settemp'],
155+
"f": self.values['fanspeed'],
156+
"m": self.values['acmode'],
157+
}
143158

144-
await self.update_status([query_c])
159+
self.values.update(await self._get_resource("set.cgi", params))
145160

146161
@property
147162
def zones(self):
@@ -165,11 +180,8 @@ async def set_zone(self, zone_id, key, value):
165180
return
166181
zone_id += 1
167182

168-
path = "setzone.cgi"
169-
params = {"pass": "HIDDEN", "z": zone_id, "s": value}
170-
_LOGGER.debug("Sending request to %s with params: %s", path, params)
171-
172-
params["pass"] = self._password
173-
174-
current_state = await self._get_resource(path, params)
175-
self.values.update(current_state)
183+
params = {
184+
"z": zone_id,
185+
"s": value,
186+
}
187+
self.values.update(await self._get_resource("setzone.cgi", params))

pydaikin/factory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ async def __init__(
3737
"""Factory to init the corresponding Daikin class."""
3838

3939
if password is not None:
40-
self._generated_object = DaikinSkyFi(device_id, session, password=password)
40+
self._generated_object = DaikinSkyFi(device_id, session, password)
4141
elif key is not None:
4242
self._generated_object = DaikinBRP072C(
4343
device_id,

0 commit comments

Comments
 (0)