diff --git a/plugwise/legacy/smile.py b/plugwise/legacy/smile.py
index 02bd74abf..7cd22032c 100644
--- a/plugwise/legacy/smile.py
+++ b/plugwise/legacy/smile.py
@@ -171,15 +171,9 @@ async def set_preset(self, _: str, preset: str) -> None:
raise PlugwiseError("Plugwise: invalid preset.")
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.strip())
+ rule_id = self._domain_objects.find(locator).attrib["id"]
+ data = f"true"
+ await self.call_request(RULES, method="put", data=data)
async def set_regulation_mode(self, mode: str) -> None:
"""Set-function placeholder for legacy devices."""
@@ -224,17 +218,17 @@ async def set_schedule_state(
for rule in self._domain_objects.findall(locator):
template_id = rule.attrib["id"]
- data = f'''
-
-
-
-
- {new_state}
-
-
- '''
+ data = (
+ ""
+ f""
+ f""
+ f""
+ f"{new_state}"
+ ""
+ ""
+ )
uri = f"{RULES};id={schedule_rule_id}"
- await self.call_request(uri, method="put", data=data.strip())
+ await self.call_request(uri, method="put", data=data)
async def set_switch_state(
self, appl_id: str, members: list[str] | None, model: str, state: str
@@ -258,21 +252,21 @@ async def set_switch_state(
appliance = self._appliances.find(f'appliance[@id="{appl_id}"]')
appl_name = appliance.find("name").text
appl_type = appliance.find("type").text
- data = f'''
-
-
-
-
-
- <{switch.actuator}>
- <{switch.func_type}>
- {state}
- {switch.func_type}>
- {switch.actuator}>
-
-
- '''
- await self.call_request(APPLIANCES, method="post", data=data.strip())
+ data = (
+ ""
+ f""
+ f""
+ f""
+ f""
+ f"<{switch.actuator}>"
+ f"<{switch.func_type}>"
+ f"{state}"
+ f"{switch.func_type}>"
+ f"{switch.actuator}>"
+ ""
+ ""
+ )
+ await self.call_request(APPLIANCES, method="post", data=data)
return
# Handle group of switches
@@ -317,13 +311,13 @@ async def set_temperature(self, _: str, items: dict[str, float]) -> None:
) # pragma: no cover"
temperature = str(setpoint)
- data = f"""
-
- {temperature}
-
- """
+ data = (
+ ""
+ f"{temperature}"
+ ""
+ )
uri = self._thermostat_uri()
- await self.call_request(uri, method="put", data=data.strip())
+ await self.call_request(uri, method="put", data=data)
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 d90ce89fe..aec1a6fa8 100644
--- a/plugwise/smile.py
+++ b/plugwise/smile.py
@@ -174,13 +174,13 @@ async def set_number(
if thermostat_id is None:
raise PlugwiseError(f"Plugwise: cannot change setpoint, {key} not found.")
- data = f"""
-
- {temp}
-
- """
+ data = (
+ ""
+ f"{temp}"
+ ""
+ )
uri = f"{APPLIANCES};id={self._heater_id}/thermostat;id={thermostat_id}"
- await self.call_request(uri, method="put", data=data.strip())
+ await self.call_request(uri, method="put", data=data)
async def set_offset(self, dev_id: str, offset: float) -> None:
"""Set the Temperature offset for thermostats that support this feature."""
@@ -190,13 +190,9 @@ async def set_offset(self, dev_id: str, offset: float) -> None:
)
value = str(offset)
- data = f"""
-
- {value}
-
- """
+ data = f"{value}"
uri = f"{APPLIANCES};id={dev_id}/offset;type=temperature_offset"
- await self.call_request(uri, method="put", data=data.strip())
+ await self.call_request(uri, method="put", data=data)
async def set_preset(self, loc_id: str, preset: str) -> None:
"""Set the given Preset on the relevant Thermostat - from LOCATIONS."""
@@ -208,17 +204,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}
-
-
- '''
+ data = (
+ ""
+ f""
+ f"{location_name}"
+ f"{location_type}"
+ f"{preset}"
+ ""
+ ""
+ )
uri = f"{LOCATIONS};id={loc_id}"
- await self.call_request(uri, method="put", data=data.strip())
+ await self.call_request(uri, method="put", data=data)
async def set_select(
self, key: str, loc_id: str, option: str, state: str | None
@@ -240,13 +236,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}
-
- """
+ data = (
+ ""
+ f"{mode}"
+ ""
+ )
uri = f"{APPLIANCES};type=heater_central/domestic_hot_water_mode_control"
- await self.call_request(uri, method="put", data=data.strip())
+ await self.call_request(uri, method="put", data=data)
async def set_gateway_mode(self, mode: str) -> None:
"""Set the gateway mode."""
@@ -271,14 +267,14 @@ 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}
-
- """
+ data = (
+ ""
+ f"{mode}"
+ f"{valid}"
+ ""
+ )
uri = f"{APPLIANCES};id={self._smile_props['gateway_id']}/gateway_mode_control"
- await self.call_request(uri, method="put", data=data.strip())
+ await self.call_request(uri, method="put", data=data)
async def set_regulation_mode(self, mode: str) -> None:
"""Set the heating regulation mode."""
@@ -289,14 +285,14 @@ async def set_regulation_mode(self, mode: str) -> None:
if "bleeding" in mode:
duration = "300"
- data = f"""
-
- {duration}
- {mode}
-
- """
+ data = (
+ ""
+ f"{duration}"
+ f"{mode}"
+ ""
+ )
uri = f"{APPLIANCES};type=gateway/regulation_mode_control"
- await self.call_request(uri, method="put", data=data.strip())
+ await self.call_request(uri, method="put", data=data)
async def set_schedule_state(
self,
@@ -344,17 +340,17 @@ async def set_schedule_state(
template = f''
contexts = self.determine_contexts(loc_id, name, new_state, schedule_rule_id)
- data = f'''
-
-
-
- {template}
- {contexts}
-
-
- '''
+ data = (
+ ""
+ f""
+ f""
+ f"{template}"
+ f"{contexts}"
+ ""
+ ""
+ )
uri = f"{RULES};id={schedule_rule_id}"
- await self.call_request(uri, method="put", data=data.strip())
+ await self.call_request(uri, method="put", data=data)
self._schedule_old_states[loc_id][name] = new_state
def determine_contexts(
@@ -412,11 +408,11 @@ async def set_switch_state(
switch_id = item.attrib["id"]
break
- data = f"""
- <{switch.func_type}>
- <{switch.func}>{state}{switch.func}>
- {switch.func_type}>
- """
+ data = (
+ f"<{switch.func_type}>"
+ f"<{switch.func}>{state}{switch.func}>"
+ f"{switch.func_type}>"
+ )
uri = f"{APPLIANCES};id={appl_id}/{switch.device};id={switch_id}"
if model == "relay":
locator = (
@@ -426,7 +422,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.strip())
+ await self.call_request(uri, method="put", data=data)
async def _set_groupswitch_member_state(
self, members: list[str], state: str, switch: Munch
@@ -439,12 +435,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.strip())
+ data = (
+ f"<{switch.func_type}>"
+ f"<{switch.func}>{state}{switch.func}>"
+ f"{switch.func_type}>"
+ )
+ await self.call_request(uri, method="put", data=data)
async def set_temperature(self, loc_id: str, items: dict[str, float]) -> None:
"""Set the given Temperature on the relevant Thermostat."""
@@ -479,13 +475,13 @@ async def set_temperature(self, loc_id: str, items: dict[str, float]) -> None:
) # pragma: no cover"
temperature = str(setpoint)
- data = f"""
-
- {temperature}
-
- """
+ data = (
+ ""
+ f"{temperature}"
+ ""
+ )
uri = self._thermostat_uri(loc_id)
- await self.call_request(uri, method="put", data=data.strip())
+ await self.call_request(uri, method="put", data=data)
async def call_request(self, uri: str, **kwargs: Any) -> None:
"""ConnectionFailedError wrapper for calling request()."""