Improve appliance import

This commit is contained in:
Andre Basche 2023-06-28 19:42:21 +02:00
parent 2a6b040193
commit 52837f16e3
3 changed files with 14 additions and 6 deletions

View File

@ -1,5 +1,6 @@
import importlib import importlib
import logging import logging
import re
from datetime import datetime, timedelta from datetime import datetime, timedelta
from pathlib import Path from pathlib import Path
from typing import Optional, Dict, Any, TYPE_CHECKING, List from typing import Optional, Dict, Any, TYPE_CHECKING, List
@ -69,9 +70,9 @@ class HonAppliance:
return default return default
def _check_name_zone(self, name: str, frontend: bool = True) -> str: 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: if (attribute := self._info.get(name, "")) and self._zone:
return f"{attribute}{middle}{self._zone}" return f"{attribute}{zone}{self._zone}"
return attribute return attribute
@property @property
@ -88,7 +89,11 @@ class HonAppliance:
@property @property
def unique_id(self) -> str: 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 @property
def model_name(self) -> str: def model_name(self) -> str:
@ -100,7 +105,10 @@ class HonAppliance:
@property @property
def nick_name(self) -> str: 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 @property
def code(self) -> str: def code(self) -> str:

View File

@ -29,7 +29,7 @@ def anonymize_data(data: str) -> str:
for match in re.findall(f'"{sensible}.*?":\\s"?(.+?)"?,?\\n', data): for match in re.findall(f'"{sensible}.*?":\\s"?(.+?)"?,?\\n', data):
replace = re.sub("[a-z]", "x", match) replace = re.sub("[a-z]", "x", match)
replace = re.sub("[A-Z]", "X", replace) replace = re.sub("[A-Z]", "X", replace)
replace = re.sub("\\d", "0", replace) replace = re.sub("\\d", "1", replace)
data = data.replace(match, replace) data = data.replace(match, replace)
return data return data

View File

@ -7,7 +7,7 @@ with open("README.md", "r") as f:
setup( setup(
name="pyhOn", name="pyhOn",
version="0.14.2", version="0.14.3",
author="Andre Basche", author="Andre Basche",
description="Control hOn devices with python", description="Control hOn devices with python",
long_description=long_description, long_description=long_description,