Skip to content

Commit

Permalink
fix pass for skyfi devices
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrike committed Aug 26, 2024
1 parent a961348 commit 897db39
Showing 1 changed file with 28 additions and 19 deletions.
47 changes: 28 additions & 19 deletions pydaikin/daikin_skyfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class DaikinSkyFi(Appliance):
"""Daikin class for SkyFi units."""

HTTP_RESOURCES = ['ac.cgi?pass={}', 'zones.cgi?pass={}']
HTTP_RESOURCES = ['ac.cgi', 'zones.cgi']

INFO_RESOURCES = HTTP_RESOURCES

Expand Down Expand Up @@ -102,6 +102,17 @@ def parse_response(response_body):
)
return response

async def _get_resource(self, path: str, params: dict | None = None):
"""Make the http request."""
if params is None:
params = {}

params["pass"] = "HIDDEN"
_LOGGER.debug("Sending request to %s with params: %s", path, params)

params["pass"] = self._password
return await super()._get_resource(path, params)

def represent(self, key):
"""Return translated value from key."""
k, val = super().represent(self.SKYFI_TO_DAIKIN.get(key, key))
Expand All @@ -115,7 +126,7 @@ def represent(self, key):
async def set(self, settings):
"""Set settings on Daikin device."""
_LOGGER.debug("Updating settings: %s", settings)
await self.update_status(['ac.cgi?pass={}'])
await self.update_status(['ac.cgi'])

# Merge current_val with mapped settings
self.values.update(
Expand All @@ -129,19 +140,20 @@ async def set(self, settings):
# we are using an extra mode "off" to power off the unit
if settings.get('mode', '') == 'off':
self.values['opmode'] = '0'
query_c = 'set.cgi?pass={}&p=0'
params = {
"p": self.values['opmode'],
}
else:
if 'mode' in settings:
self.values['opmode'] = '1'
query_c = (
f"set.cgi?pass={{}}"
f"&p={self.values['opmode']}"
f"&t={self.values['settemp']}"
f"&f={self.values['fanspeed']}"
f"&m={self.values['acmode']}"
)
params = {
"p": self.values['opmode'],
"t": self.values['settemp'],
"f": self.values['fanspeed'],
"m": self.values['acmode'],
}

await self.update_status([query_c])
self.values.update(await self._get_resource("set.cgi", params))

@property
def zones(self):
Expand All @@ -165,11 +177,8 @@ async def set_zone(self, zone_id, key, value):
return
zone_id += 1

path = "setzone.cgi"
params = {"pass": "HIDDEN", "z": zone_id, "s": value}
_LOGGER.debug("Sending request to %s with params: %s", path, params)

params["pass"] = self._password

current_state = await self._get_resource(path, params)
self.values.update(current_state)
params = {
"z": zone_id,
"s": value,
}
self.values.update(await self._get_resource("setzone.cgi", params))

0 comments on commit 897db39

Please sign in to comment.