plugwise 1.6.4__py3-none-any.whl → 1.7.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
plugwise/util.py CHANGED
@@ -20,7 +20,6 @@ from plugwise.constants import (
20
20
  SPECIAL_FORMAT,
21
21
  SPECIALS,
22
22
  SWITCHES,
23
- TEMP_CELSIUS,
24
23
  UOM,
25
24
  BinarySensorType,
26
25
  GwEntityData,
@@ -117,6 +116,30 @@ def check_model(name: str | None, vendor_name: str | None) -> str | None:
117
116
  return None
118
117
 
119
118
 
119
+ def collect_power_values(
120
+ data: GwEntityData, loc: Munch, tariff: str, legacy: bool = False
121
+ ) -> None:
122
+ """Something."""
123
+ for loc.peak_select in ("nl_peak", "nl_offpeak"):
124
+ loc.locator = (
125
+ f'./{loc.log_type}[type="{loc.measurement}"]/period/'
126
+ f'measurement[@{tariff}="{loc.peak_select}"]'
127
+ )
128
+ if legacy:
129
+ loc.locator = (
130
+ f"./{loc.meas_list[0]}_{loc.log_type}/measurement"
131
+ f'[@directionality="{loc.meas_list[1]}"][@{tariff}="{loc.peak_select}"]'
132
+ )
133
+
134
+ loc = power_data_peak_value(loc, legacy)
135
+ if not loc.found:
136
+ continue
137
+
138
+ data = power_data_energy_diff(loc.measurement, loc.net_string, loc.f_val, data)
139
+ key = cast(SensorType, loc.key_string)
140
+ data["sensors"][key] = loc.f_val
141
+
142
+
120
143
  def common_match_cases(
121
144
  measurement: str,
122
145
  attrs: DATA | UOM,
@@ -146,6 +169,22 @@ def common_match_cases(
146
169
  data["binary_sensors"]["low_battery"] = False
147
170
 
148
171
 
172
+ def count_data_items(count: int, data: GwEntityData) -> int:
173
+ """When present, count the binary_sensors, sensors and switches dict-items, don't count the dicts.
174
+
175
+ Also, count the remaining single data items, the amount of dicts present have already been pre-subtracted in the previous step.
176
+ """
177
+ if "binary_sensors" in data:
178
+ count += len(data["binary_sensors"]) - 1
179
+ if "sensors" in data:
180
+ count += len(data["sensors"]) - 1
181
+ if "switches" in data:
182
+ count += len(data["switches"]) - 1
183
+
184
+ count += len(data)
185
+ return count
186
+
187
+
149
188
  def escape_illegal_xml_characters(xmldata: str) -> str:
150
189
  """Replace illegal &-characters."""
151
190
  return re.sub(r"&([^a-zA-Z#])", r"&\1", xmldata)
@@ -154,26 +193,22 @@ def escape_illegal_xml_characters(xmldata: str) -> str:
154
193
  def format_measure(measure: str, unit: str) -> float | int:
155
194
  """Format measure to correct type."""
156
195
  result: float | int = 0
157
- try:
158
- result = int(measure)
159
- if unit == TEMP_CELSIUS:
160
- result = float(measure)
161
- except ValueError:
162
- float_measure = float(measure)
163
- if unit == PERCENTAGE and 0 < float_measure <= 1:
164
- return int(float_measure * 100)
165
-
166
- if unit == ENERGY_KILO_WATT_HOUR:
167
- float_measure = float_measure / 1000
168
-
169
- if unit in SPECIAL_FORMAT:
170
- result = float(f"{round(float_measure, 3):.3f}")
171
- elif unit == ELECTRIC_POTENTIAL_VOLT:
172
- result = float(f"{round(float_measure, 1):.1f}")
173
- elif abs(float_measure) < 10:
174
- result = float(f"{round(float_measure, 2):.2f}")
175
- elif abs(float_measure) >= 10:
176
- result = float(f"{round(float_measure, 1):.1f}")
196
+
197
+ float_measure = float(measure)
198
+ if unit == PERCENTAGE and 0 < float_measure <= 1:
199
+ return int(float_measure * 100)
200
+
201
+ if unit == ENERGY_KILO_WATT_HOUR:
202
+ float_measure = float_measure / 1000
203
+
204
+ if unit in SPECIAL_FORMAT:
205
+ result = float(f"{round(float_measure, 3):.3f}")
206
+ elif unit == ELECTRIC_POTENTIAL_VOLT:
207
+ result = float(f"{round(float_measure, 1):.1f}")
208
+ elif abs(float_measure) < 10:
209
+ result = float(f"{round(float_measure, 2):.2f}")
210
+ elif abs(float_measure) >= 10:
211
+ result = float(f"{round(float_measure, 1):.1f}")
177
212
 
178
213
  return result
179
214
 
@@ -188,6 +223,37 @@ def get_vendor_name(module: etree, model_data: ModuleData) -> ModuleData:
188
223
  return model_data
189
224
 
190
225
 
226
+ def power_data_energy_diff(
227
+ measurement: str,
228
+ net_string: SensorType,
229
+ f_val: float | int,
230
+ data: GwEntityData,
231
+ ) -> GwEntityData:
232
+ """Calculate differential energy."""
233
+ if (
234
+ "electricity" in measurement
235
+ and "phase" not in measurement
236
+ and "interval" not in net_string
237
+ ):
238
+ diff = 1
239
+ if "produced" in measurement:
240
+ diff = -1
241
+ if net_string not in data["sensors"]:
242
+ tmp_val: float | int = 0
243
+ else:
244
+ tmp_val = data["sensors"][net_string]
245
+
246
+ if isinstance(f_val, int):
247
+ tmp_val += f_val * diff
248
+ else:
249
+ tmp_val += float(f_val * diff)
250
+ tmp_val = float(f"{round(tmp_val, 3):.3f}")
251
+
252
+ data["sensors"][net_string] = tmp_val
253
+
254
+ return data
255
+
256
+
191
257
  def power_data_local_format(
192
258
  attrs: dict[str, str], key_string: str, val: str
193
259
  ) -> float | int:
@@ -201,6 +267,31 @@ def power_data_local_format(
201
267
  return format_measure(val, attrs_uom)
202
268
 
203
269
 
270
+ def power_data_peak_value(loc: Munch, legacy: bool) -> Munch:
271
+ """Helper-function for _power_data_from_location() and _power_data_from_modules()."""
272
+ loc.found = True
273
+ if loc.logs.find(loc.locator) is None:
274
+ loc = check_alternative_location(loc, legacy)
275
+ if not loc.found:
276
+ return loc
277
+
278
+ if (peak := loc.peak_select.split("_")[1]) == "offpeak":
279
+ peak = "off_peak"
280
+ log_found = loc.log_type.split("_")[0]
281
+ loc.key_string = f"{loc.measurement}_{peak}_{log_found}"
282
+ if "gas" in loc.measurement or loc.log_type == "point_meter":
283
+ loc.key_string = f"{loc.measurement}_{log_found}"
284
+ # Only for P1 Actual -------------------#
285
+ if "phase" in loc.measurement:
286
+ loc.key_string = f"{loc.measurement}"
287
+ # --------------------------------------#
288
+ loc.net_string = f"net_electricity_{log_found}"
289
+ val = loc.logs.find(loc.locator).text
290
+ loc.f_val = power_data_local_format(loc.attrs, loc.key_string, val)
291
+
292
+ return loc
293
+
294
+
204
295
  def remove_empty_platform_dicts(data: GwEntityData) -> None:
205
296
  """Helper-function for removing any empty platform dicts."""
206
297
  if not data["binary_sensors"]:
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: plugwise
3
- Version: 1.6.4
3
+ Version: 1.7.0
4
4
  Summary: Plugwise Smile (Adam/Anna/P1) and Stretch module for Python 3.
5
5
  Home-page: https://github.com/plugwise/python-plugwise
6
6
  Author: Plugwise device owners
@@ -0,0 +1,18 @@
1
+ plugwise/__init__.py,sha256=fyot91I4cMkgo_8fL1hycRXwGBDecUq9ltxLAfSY-2U,17762
2
+ plugwise/common.py,sha256=_41FLLjgccaHjaV0Ndn1YEkxjB_qKev1k3ZnhSUzXjc,9305
3
+ plugwise/constants.py,sha256=Vd8tvOHsRtZxtUUFXBXolZj3QiKnxRt0bnwDT9DoEqE,17073
4
+ plugwise/data.py,sha256=ITGnS5RiRbd3O2KbYLc9_5okw81zLl7azXNXtuTwaoY,13022
5
+ plugwise/exceptions.py,sha256=Ce-tO9uNsMB-8FP6VAxBvsHNJ-NIM9F0onUZOdZI4Ys,1110
6
+ plugwise/helper.py,sha256=dsdPpwJHiZ3DQoTc7kWoOiFVPvRda5u1GRJwAEDxuBk,39388
7
+ plugwise/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
+ plugwise/smile.py,sha256=I8lssyqmq_PF8ptLxk3daS7lf20kXr5Z3L7SYg3S9j4,18928
9
+ plugwise/smilecomm.py,sha256=aQ2KkebDTou18k-flrVmTnFkgls33Xu8D9ZZQQt2R5k,5178
10
+ plugwise/util.py,sha256=7OPtC4FDbAweAqad6b-6tKtMlSSQd3OU7g5-0lplF34,11002
11
+ plugwise/legacy/data.py,sha256=s2WYjgxwcuAGS8UOxJVf7xLSxS38Zgr8GsjxlxfD98w,3574
12
+ plugwise/legacy/helper.py,sha256=GslPqZL0gAAnqJVy-Ydp_U-eGQ5jYhz9F_Y15BfQgt4,17056
13
+ plugwise/legacy/smile.py,sha256=TxjqRf7KIecECt48iHgSFI7bIOEHNkf4desSBVo1l-M,11666
14
+ plugwise-1.7.0.dist-info/LICENSE,sha256=mL22BjmXtg_wnoDnnaqps5_Bg_VGj_yHueX5lsKwbCc,1144
15
+ plugwise-1.7.0.dist-info/METADATA,sha256=ZWR9Mhkp1CknISTs1adzs9jePeIWqW9M89qMnUyvGI8,9148
16
+ plugwise-1.7.0.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
17
+ plugwise-1.7.0.dist-info/top_level.txt,sha256=MYOmktMFf8ZmX6_OE1y9MoCZFfY-L8DA0F2tA2IvE4s,9
18
+ plugwise-1.7.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.6.0)
2
+ Generator: setuptools (75.8.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,17 +0,0 @@
1
- plugwise/__init__.py,sha256=-c0b3nN7qFxCzr1VPmRHIJVuueRzOhGlQYFJfwzxmlM,17756
2
- plugwise/common.py,sha256=0A4o5ae3HfUKC3NO6NYiXbEWJgGZgGtc0VvDoVRiqtY,13075
3
- plugwise/constants.py,sha256=kDMrVqHnwfVmW3P-Qe16WJxzFvHadAUW2teCWTHAEEU,17245
4
- plugwise/data.py,sha256=mrNnY5gvsBB3MVuQUEqq24i9XUTPthHM6f9FW4dFxlY,12907
5
- plugwise/exceptions.py,sha256=Ce-tO9uNsMB-8FP6VAxBvsHNJ-NIM9F0onUZOdZI4Ys,1110
6
- plugwise/helper.py,sha256=YUOBHUdQbIkUa4mK5IMf6YY5QYu0AhF2corW6fCv-Hs,47111
7
- plugwise/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
- plugwise/smile.py,sha256=ksyjj2VNEKFxIfK7Tr_NEb-fnyXIwMfz7wFdEosBXgI,19335
9
- plugwise/util.py,sha256=YR_dLM1E1KZ6m0eVeQ7ZevrbfPvGzF6EOeC6rjTFktA,8015
10
- plugwise/legacy/data.py,sha256=YzVhMYTGQJTUzTVMt8TugL2f3Q6YMCjW7-dF7rjb5n4,3612
11
- plugwise/legacy/helper.py,sha256=KHbjcnptzeFMqUcQwg4_R24l6XgDKje6VRzUsWJIdSc,18168
12
- plugwise/legacy/smile.py,sha256=5rDlDXltYkHMI3SiRbugSY5fwCfyw1ElBCc7YSyQt6A,11996
13
- plugwise-1.6.4.dist-info/LICENSE,sha256=mL22BjmXtg_wnoDnnaqps5_Bg_VGj_yHueX5lsKwbCc,1144
14
- plugwise-1.6.4.dist-info/METADATA,sha256=DBAkkLJvhgzpDQwwUmu-lfv91x0g9nLqKjCJMxYMCM0,9148
15
- plugwise-1.6.4.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
16
- plugwise-1.6.4.dist-info/top_level.txt,sha256=MYOmktMFf8ZmX6_OE1y9MoCZFfY-L8DA0F2tA2IvE4s,9
17
- plugwise-1.6.4.dist-info/RECORD,,