File tree Expand file tree Collapse file tree 3 files changed +15
-27
lines changed
Expand file tree Collapse file tree 3 files changed +15
-27
lines changed Original file line number Diff line number Diff line change 6363from 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-
10088class SmileComm :
10189 """The SmileComm class."""
10290
Original file line number Diff line number Diff line change 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)
5454from 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-
8168class SmileLegacyHelper :
8269 """The SmileLegacyHelper class."""
8370
Original file line number Diff line number Diff 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
5265def version_to_model (version : str | None ) -> str | None :
5366 """Translate hardware_version to device type."""
You can’t perform that action at this time.
0 commit comments