Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use query string for set_zone on airbase #11

Merged
merged 6 commits into from
Jul 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions pydaikin/daikin_airbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ def parse_response(response_body):
def __init__( # pylint:disable=useless-parent-delegation
self, device_id, session=None
) -> None:
"""Init the pydaikin appliance, representing one Daikin AirBase
(BRP15B61) device."""
"""Init Daikin AirBase (BRP15B61) device."""
super().__init__(device_id, session)

async def init(self):
Expand Down Expand Up @@ -91,14 +90,13 @@ def support_swing_mode(self):

@property
def outside_temperature(self):
"""
AirBase unit returns otemp if master controller starts before it.
"""AirBase unit returns otemp if master controller starts before it.

No Outside Thermometor returns a '-' (Non Number).
Return current outside temperature if available.
"""
value = self.values.get('otemp')
return self._parse_number('otemp') if value != '-' else None
value = self.values.get("otemp")
return self._parse_number("otemp") if value != "-" else None

@property
def support_zone_temperature(self):
Expand Down Expand Up @@ -241,7 +239,20 @@ async def set_zone(self, zone_id, key, value):
}

if self.support_zone_temperature:
params.update({"lztemp_c": self.values["lztemp_c"]})
params.update({"lztemp_h": self.values["lztemp_h"]})

_LOGGER.debug("Sending request to %s with params: %s", path, params)
await self._get_resource(path, params)
# Zone Name requires %20 encoding which is not handled well
# within yarl resulting in '%20' being encoded again to '%2520'
# For detailed info before changing query string to pparam
# refer to: https://github.com/fredrike/pydaikin/pull/11

# # Convert params dictionary to query string format
params_str = "&".join(f"{k}={v}" for k, v in params.items())
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do think we should try to get the params way to work. Can you add some debugging on what's happening here in contrast to the params way?

Also it seems like httpx are using https://docs.python.org/3/library/urllib.parse.html#urllib.parse.urlencode. Isn't that a better way?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kingy444 could you try to run a few scenarios that uses the inbuilt params in httpx. I would like to understand what's going on here. Perhas you could enable verbose (NOTSET) debugging on httpx so we can see how the request differs.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kingy444 could you have a look at this ⬆️ .

path = f"{path}?{params_str}" # Append params as query string to path

_LOGGER.debug(
"Updating ['aircon/set_zone_setting']: %s",
",".join(f"{k}={unquote(v)}" for k, v in params.items()),
)
await self._get_resource(path)
Loading