From 52837f16e33b225f482f466351b411155c3ad42d Mon Sep 17 00:00:00 2001 From: Andre Basche Date: Wed, 28 Jun 2023 19:42:21 +0200 Subject: [PATCH] Improve appliance import --- pyhon/appliance.py | 16 ++++++++++++---- pyhon/diagnose.py | 2 +- setup.py | 2 +- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/pyhon/appliance.py b/pyhon/appliance.py index a368cfa..e8cffc3 100644 --- a/pyhon/appliance.py +++ b/pyhon/appliance.py @@ -1,5 +1,6 @@ import importlib import logging +import re from datetime import datetime, timedelta from pathlib import Path from typing import Optional, Dict, Any, TYPE_CHECKING, List @@ -69,9 +70,9 @@ class HonAppliance: return default def _check_name_zone(self, name: str, frontend: bool = True) -> str: - middle = " Z" if frontend else "_z" + zone = " Z" if frontend else "_z" if (attribute := self._info.get(name, "")) and self._zone: - return f"{attribute}{middle}{self._zone}" + return f"{attribute}{zone}{self._zone}" return attribute @property @@ -88,7 +89,11 @@ class HonAppliance: @property def unique_id(self) -> str: - return self._check_name_zone("macAddress", frontend=False) + default_mac = "xx-xx-xx-xx-xx-xx" + import_name = f"{self.appliance_type.lower()}_{self.appliance_model_id}" + result = self._check_name_zone("macAddress", frontend=False) + result = result.replace(default_mac, import_name) + return result @property def model_name(self) -> str: @@ -100,7 +105,10 @@ class HonAppliance: @property def nick_name(self) -> str: - return self._check_name_zone("nickName") + result = self._check_name_zone("nickName") + if not result or re.findall("^[xX\s]+$", result): + return self.model_name + return result @property def code(self) -> str: diff --git a/pyhon/diagnose.py b/pyhon/diagnose.py index bffb17c..9d2b9b8 100644 --- a/pyhon/diagnose.py +++ b/pyhon/diagnose.py @@ -29,7 +29,7 @@ def anonymize_data(data: str) -> str: for match in re.findall(f'"{sensible}.*?":\\s"?(.+?)"?,?\\n', data): replace = re.sub("[a-z]", "x", match) replace = re.sub("[A-Z]", "X", replace) - replace = re.sub("\\d", "0", replace) + replace = re.sub("\\d", "1", replace) data = data.replace(match, replace) return data diff --git a/setup.py b/setup.py index ceaad66..d8bcf15 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ with open("README.md", "r") as f: setup( name="pyhOn", - version="0.14.2", + version="0.14.3", author="Andre Basche", description="Control hOn devices with python", long_description=long_description,