Skip to content

Commit 3a946cd

Browse files
authored
Merge pull request #702 from plugwise/split-partition
Change to using partition
2 parents 0c6ed90 + d1d7745 commit 3a946cd

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Ongoing
44

55
- Avoid None-init for smile_version [#699](https://github.com/plugwise/python-plugwise/pull/699)
6+
- Replace string.split() by string.partition() [#702](https://github.com/plugwise/python-plugwise/pull/702)
67

78
## v1.7.0
89

plugwise/legacy/helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ def _power_data_from_modules(self) -> GwEntityData:
306306
search = self._modules
307307
mod_logs = search.findall("./module/services")
308308
for loc.measurement, loc.attrs in P1_LEGACY_MEASUREMENTS.items():
309-
loc.meas_list = loc.measurement.split("_")
309+
loc.meas_list = loc.measurement.partition("_")[0::2]
310310
for loc.logs in mod_logs:
311311
for loc.log_type in mod_list:
312312
collect_power_values(data, loc, t_string, legacy=True)

plugwise/util.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def get_vendor_name(module: etree, model_data: ModuleData) -> ModuleData:
218218
if (vendor_name := module.find("vendor_name").text) is not None:
219219
model_data["vendor_name"] = vendor_name
220220
if "Plugwise" in vendor_name:
221-
model_data["vendor_name"] = vendor_name.split(" ", 1)[0]
221+
model_data["vendor_name"] = vendor_name.partition(" ")[0]
222222

223223
return model_data
224224

@@ -275,9 +275,9 @@ def power_data_peak_value(loc: Munch, legacy: bool) -> Munch:
275275
if not loc.found:
276276
return loc
277277

278-
if (peak := loc.peak_select.split("_")[1]) == "offpeak":
278+
if (peak := loc.peak_select.partition("_")[2]) == "offpeak":
279279
peak = "off_peak"
280-
log_found = loc.log_type.split("_")[0]
280+
log_found = loc.log_type.partition("_")[0]
281281
loc.key_string = f"{loc.measurement}_{peak}_{log_found}"
282282
if "gas" in loc.measurement or loc.log_type == "point_meter":
283283
loc.key_string = f"{loc.measurement}_{log_found}"
@@ -314,7 +314,7 @@ def skip_obsolete_measurements(xml: etree, measurement: str) -> bool:
314314
measurement in OBSOLETE_MEASUREMENTS
315315
and (updated_date_key := xml.find(locator)) is not None
316316
):
317-
updated_date = updated_date_key.text.split("T")[0]
317+
updated_date = updated_date_key.text.partition("T")[0]
318318
date_1 = dt.datetime.strptime(updated_date, "%Y-%m-%d")
319319
date_2 = dt.datetime.now()
320320
return int((date_2 - date_1).days) > 7

0 commit comments

Comments
 (0)