diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1dccd7aab..87ebf800a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,9 @@
# Changelog
+## Ongoing
+
+- Improve readability of xml-data in POST/PUT requests
+
## v1.7.2
- Bugfix for Plugwise-beta issue [833](https://github.com/plugwise/plugwise-beta/issues/833) solving relay- and lock-switches not switching for the Stretch.
diff --git a/plugwise/legacy/smile.py b/plugwise/legacy/smile.py
index c74dcddcb..02bd74abf 100644
--- a/plugwise/legacy/smile.py
+++ b/plugwise/legacy/smile.py
@@ -172,9 +172,14 @@ async def set_preset(self, _: str, preset: str) -> None:
locator = f'rule/directives/when/then[@icon="{preset}"].../.../...'
rule = self._domain_objects.find(locator)
- data = f'true'
-
- await self.call_request(RULES, method="put", data=data)
+ data = f'''
+
+
+ true
+
+
+ '''
+ await self.call_request(RULES, method="put", data=data.strip())
async def set_regulation_mode(self, mode: str) -> None:
"""Set-function placeholder for legacy devices."""
@@ -219,14 +224,17 @@ async def set_schedule_state(
for rule in self._domain_objects.findall(locator):
template_id = rule.attrib["id"]
+ data = f'''
+
+
+
+
+ {new_state}
+
+
+ '''
uri = f"{RULES};id={schedule_rule_id}"
- data = (
- "{new_state}'
- )
-
- await self.call_request(uri, method="put", data=data)
+ await self.call_request(uri, method="put", data=data.strip())
async def set_switch_state(
self, appl_id: str, members: list[str] | None, model: str, state: str
@@ -262,8 +270,9 @@ async def set_switch_state(
{switch.func_type}>
{switch.actuator}>
- '''.strip()
- await self.call_request(APPLIANCES, method="post", data=data)
+
+ '''
+ await self.call_request(APPLIANCES, method="post", data=data.strip())
return
# Handle group of switches
@@ -308,13 +317,13 @@ async def set_temperature(self, _: str, items: dict[str, float]) -> None:
) # pragma: no cover"
temperature = str(setpoint)
+ data = f"""
+
+ {temperature}
+
+ """
uri = self._thermostat_uri()
- data = (
- ""
- f"{temperature}"
- )
-
- await self.call_request(uri, method="put", data=data)
+ await self.call_request(uri, method="put", data=data.strip())
async def call_request(self, uri: str, **kwargs: Any) -> None:
"""ConnectionFailedError wrapper for calling request()."""
diff --git a/plugwise/smile.py b/plugwise/smile.py
index 646a94824..d90ce89fe 100644
--- a/plugwise/smile.py
+++ b/plugwise/smile.py
@@ -174,9 +174,13 @@ async def set_number(
if thermostat_id is None:
raise PlugwiseError(f"Plugwise: cannot change setpoint, {key} not found.")
+ data = f"""
+
+ {temp}
+
+ """
uri = f"{APPLIANCES};id={self._heater_id}/thermostat;id={thermostat_id}"
- data = f"{temp}"
- await self.call_request(uri, method="put", data=data)
+ await self.call_request(uri, method="put", data=data.strip())
async def set_offset(self, dev_id: str, offset: float) -> None:
"""Set the Temperature offset for thermostats that support this feature."""
@@ -186,10 +190,13 @@ async def set_offset(self, dev_id: str, offset: float) -> None:
)
value = str(offset)
+ data = f"""
+
+ {value}
+
+ """
uri = f"{APPLIANCES};id={dev_id}/offset;type=temperature_offset"
- data = f"{value}"
-
- await self.call_request(uri, method="put", data=data)
+ await self.call_request(uri, method="put", data=data.strip())
async def set_preset(self, loc_id: str, preset: str) -> None:
"""Set the given Preset on the relevant Thermostat - from LOCATIONS."""
@@ -201,15 +208,17 @@ async def set_preset(self, loc_id: str, preset: str) -> None:
current_location = self._domain_objects.find(f'location[@id="{loc_id}"]')
location_name = current_location.find("name").text
location_type = current_location.find("type").text
-
+ data = f'''
+
+
+ {location_name}
+ {location_type}
+ {preset}
+
+
+ '''
uri = f"{LOCATIONS};id={loc_id}"
- data = (
- "{location_name}{location_type}'
- f"{preset}"
- )
-
- await self.call_request(uri, method="put", data=data)
+ await self.call_request(uri, method="put", data=data.strip())
async def set_select(
self, key: str, loc_id: str, option: str, state: str | None
@@ -231,10 +240,13 @@ async def set_dhw_mode(self, mode: str) -> None:
if mode not in self._dhw_allowed_modes:
raise PlugwiseError("Plugwise: invalid dhw mode.")
+ data = f"""
+
+ {mode}
+
+ """
uri = f"{APPLIANCES};type=heater_central/domestic_hot_water_mode_control"
- data = f"{mode}"
-
- await self.call_request(uri, method="put", data=data)
+ await self.call_request(uri, method="put", data=data.strip())
async def set_gateway_mode(self, mode: str) -> None:
"""Set the gateway mode."""
@@ -259,23 +271,32 @@ async def set_gateway_mode(self, mode: str) -> None:
vacation_time = time_2 + "T23:00:00.000Z"
valid = f"{vacation_time}{end_time}"
+ data = f"""
+
+ {mode}
+ {valid}
+
+ """
uri = f"{APPLIANCES};id={self._smile_props['gateway_id']}/gateway_mode_control"
- data = f"{mode}{valid}"
-
- await self.call_request(uri, method="put", data=data)
+ await self.call_request(uri, method="put", data=data.strip())
async def set_regulation_mode(self, mode: str) -> None:
"""Set the heating regulation mode."""
if mode not in self._reg_allowed_modes:
raise PlugwiseError("Plugwise: invalid regulation mode.")
- uri = f"{APPLIANCES};type=gateway/regulation_mode_control"
duration = ""
if "bleeding" in mode:
duration = "300"
- data = f"{duration}{mode}"
- await self.call_request(uri, method="put", data=data)
+ data = f"""
+
+ {duration}
+ {mode}
+
+ """
+ uri = f"{APPLIANCES};type=gateway/regulation_mode_control"
+ await self.call_request(uri, method="put", data=data.strip())
async def set_schedule_state(
self,
@@ -323,13 +344,17 @@ async def set_schedule_state(
template = f''
contexts = self.determine_contexts(loc_id, name, new_state, schedule_rule_id)
+ data = f'''
+
+
+
+ {template}
+ {contexts}
+
+
+ '''
uri = f"{RULES};id={schedule_rule_id}"
- data = (
- f''
- f"{template}{contexts}"
- )
-
- await self.call_request(uri, method="put", data=data)
+ await self.call_request(uri, method="put", data=data.strip())
self._schedule_old_states[loc_id][name] = new_state
def determine_contexts(
@@ -387,9 +412,12 @@ async def set_switch_state(
switch_id = item.attrib["id"]
break
+ data = f"""
+ <{switch.func_type}>
+ <{switch.func}>{state}{switch.func}>
+ {switch.func_type}>
+ """
uri = f"{APPLIANCES};id={appl_id}/{switch.device};id={switch_id}"
- data = f"<{switch.func_type}><{switch.func}>{state}{switch.func}>{switch.func_type}>"
-
if model == "relay":
locator = (
f'appliance[@id="{appl_id}"]/{switch.actuator}/{switch.func_type}/lock'
@@ -398,7 +426,7 @@ async def set_switch_state(
if self._domain_objects.find(locator).text == "true":
raise PlugwiseError("Plugwise: the locked Relay was not switched.")
- await self.call_request(uri, method="put", data=data)
+ await self.call_request(uri, method="put", data=data.strip())
async def _set_groupswitch_member_state(
self, members: list[str], state: str, switch: Munch
@@ -411,9 +439,12 @@ async def _set_groupswitch_member_state(
locator = f'appliance[@id="{member}"]/{switch.actuator}/{switch.func_type}'
switch_id = self._domain_objects.find(locator).attrib["id"]
uri = f"{APPLIANCES};id={member}/{switch.device};id={switch_id}"
- data = f"<{switch.func_type}><{switch.func}>{state}{switch.func}>{switch.func_type}>"
-
- await self.call_request(uri, method="put", data=data)
+ data = f"""
+ <{switch.func_type}>
+ <{switch.func}>{state}{switch.func}>
+ {switch.func_type}>
+ """
+ await self.call_request(uri, method="put", data=data.strip())
async def set_temperature(self, loc_id: str, items: dict[str, float]) -> None:
"""Set the given Temperature on the relevant Thermostat."""
@@ -448,13 +479,13 @@ async def set_temperature(self, loc_id: str, items: dict[str, float]) -> None:
) # pragma: no cover"
temperature = str(setpoint)
+ data = f"""
+
+ {temperature}
+
+ """
uri = self._thermostat_uri(loc_id)
- data = (
- ""
- f"{temperature}"
- )
-
- await self.call_request(uri, method="put", data=data)
+ await self.call_request(uri, method="put", data=data.strip())
async def call_request(self, uri: str, **kwargs: Any) -> None:
"""ConnectionFailedError wrapper for calling request()."""