Skip to content

Commit db9d6da

Browse files
committed
Revert format_measure() update, move try-except to helper.py
1 parent e66d8be commit db9d6da

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

plugwise/helper.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,8 +519,11 @@ def _get_actuator_functionalities(
519519
key = "setpoint"
520520

521521
act_key = cast(ActuatorDataType, key)
522-
temp_dict[act_key] = format_measure(pw_function.text, TEMP_CELSIUS)
523522
self._count += 1
523+
try:
524+
temp_dict[act_key] = format_measure(pw_function.text, TEMP_CELSIUS)
525+
except ValueError:
526+
temp_dict[act_key] = str(pw_function.text)
524527

525528
if temp_dict:
526529
# If domestic_hot_water_setpoint is present as actuator,

plugwise/util.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,9 @@ def escape_illegal_xml_characters(xmldata: str) -> str:
193193
return re.sub(r"&([^a-zA-Z#])", r"&\1", xmldata)
194194

195195

196-
def format_measure(measure: str, unit: str) -> float | int | str:
196+
def format_measure(measure: str, unit: str) -> float | int:
197197
"""Format measure to correct type."""
198-
try:
199-
float_measure = float(measure)
200-
except ValueError:
201-
return measure # return string
202-
198+
float_measure = float(measure)
203199
if unit == PERCENTAGE and 0 < float_measure <= 1:
204200
return int(float_measure * 100)
205201

0 commit comments

Comments
 (0)