Skip to content

Commit bef6e9d

Browse files
committed
Move power_data_local_format() to util.py
1 parent 3879759 commit bef6e9d

File tree

3 files changed

+15
-27
lines changed

3 files changed

+15
-27
lines changed

plugwise/helper.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
from plugwise.util import (
6464
escape_illegal_xml_characters,
6565
format_measure,
66+
power_data_local_format,
6667
version_to_model,
6768
)
6869

@@ -84,19 +85,6 @@ def check_model(name: str | None, vendor_name: str | None) -> str | None:
8485
return name
8586

8687

87-
def power_data_local_format(
88-
attrs: dict[str, str], key_string: str, val: str
89-
) -> float | int:
90-
"""Format power data."""
91-
# Special formatting of P1_MEASUREMENT POWER_WATT values, do not move to util-format_measure() function!
92-
if all(item in key_string for item in ("electricity", "cumulative")):
93-
return format_measure(val, ENERGY_KILO_WATT_HOUR)
94-
if (attrs_uom := getattr(attrs, ATTR_UNIT_OF_MEASUREMENT)) == POWER_WATT:
95-
return int(round(float(val)))
96-
97-
return format_measure(val, attrs_uom)
98-
99-
10088
class SmileComm:
10189
"""The SmileComm class."""
10290

plugwise/legacy/helper.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
SwitchType,
4949
ThermoLoc,
5050
)
51-
from plugwise.util import format_measure, version_to_model
51+
from plugwise.util import format_measure, power_data_local_format, version_to_model
5252

5353
# This way of importing aiohttp is because of patch/mocking in testing (aiohttp timeouts)
5454
from defusedxml import ElementTree as etree
@@ -65,19 +65,6 @@ def etree_to_dict(element: etree) -> dict[str, str]:
6565
return node
6666

6767

68-
def power_data_local_format(
69-
attrs: dict[str, str], key_string: str, val: str
70-
) -> float | int:
71-
"""Format power data."""
72-
# Special formatting of P1_MEASUREMENT POWER_WATT values, do not move to util-format_measure() function!
73-
if all(item in key_string for item in ("electricity", "cumulative")):
74-
return format_measure(val, ENERGY_KILO_WATT_HOUR)
75-
if (attrs_uom := getattr(attrs, ATTR_UNIT_OF_MEASUREMENT)) == POWER_WATT:
76-
return int(round(float(val)))
77-
78-
return format_measure(val, attrs_uom)
79-
80-
8168
class SmileLegacyHelper:
8269
"""The SmileLegacyHelper class."""
8370

plugwise/util.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,19 @@ def format_measure(measure: str, unit: str) -> float | int:
4848
return result
4949

5050

51+
def power_data_local_format(
52+
attrs: dict[str, str], key_string: str, val: str
53+
) -> float | int:
54+
"""Format power data."""
55+
# Special formatting of P1_MEASUREMENT POWER_WATT values, do not move to util-format_measure() function!
56+
if all(item in key_string for item in ("electricity", "cumulative")):
57+
return format_measure(val, ENERGY_KILO_WATT_HOUR)
58+
if (attrs_uom := getattr(attrs, ATTR_UNIT_OF_MEASUREMENT)) == POWER_WATT:
59+
return int(round(float(val)))
60+
61+
return format_measure(val, attrs_uom)
62+
63+
5164
# NOTE: this function version_to_model is shared between Smile and USB
5265
def version_to_model(version: str | None) -> str | None:
5366
"""Translate hardware_version to device type."""

0 commit comments

Comments
 (0)