Improvements

This commit is contained in:
Andre Basche 2023-07-01 14:31:37 +02:00
parent 44f40c531e
commit 0553e6c17d
8 changed files with 16 additions and 15 deletions

View File

@ -99,7 +99,7 @@ async def main() -> None:
print(printer.key_print(data)) print(printer.key_print(data))
print( print(
printer.pretty_print( printer.pretty_print(
printer.create_command(device.commands, concat=True) printer.create_commands(device.commands, concat=True)
) )
) )
else: else:

View File

@ -106,7 +106,7 @@ class HonAppliance:
@property @property
def nick_name(self) -> str: def nick_name(self) -> str:
result = self._check_name_zone("nickName") result = self._check_name_zone("nickName")
if not result or re.findall("^[xX\s]+$", result): if not result or re.findall("^[xX1\\s]+$", result):
return self.model_name return self.model_name
return result return result
@ -238,12 +238,12 @@ class HonAppliance:
if not (command := self.commands.get(command_name)): if not (command := self.commands.get(command_name)):
return return
for key, value in self.attributes.get("parameters", {}).items(): for key, value in self.attributes.get("parameters", {}).items():
if isinstance(value, str) and (new := command.parameters.get(key)): if new := command.parameters.get(key):
self.attributes["parameters"][key].update( self.attributes["parameters"][key].update(
str(new.intern_value), shield=True str(new.intern_value), shield=True
) )
def sync_command(self, main: str, target: Optional[List[str]] = None) -> None: def sync_command(self, main: str, target: Optional[List[str] | str] = None) -> None:
base: Optional[HonCommand] = self.commands.get(main) base: Optional[HonCommand] = self.commands.get(main)
if not base: if not base:
return return

View File

@ -4,7 +4,7 @@ API_KEY = "GRCqFhC6Gk@ikWXm1RmnSmX1cm,MxY-configuration"
APP = "hon" APP = "hon"
# All seen id's (different accounts, different devices) are the same, so I guess this hash is static # All seen id's (different accounts, different devices) are the same, so I guess this hash is static
CLIENT_ID = "3MVG9QDx8IX8nP5T2Ha8ofvlmjLZl5L_gvfbT9.HJvpHGKoAS_dcMN8LYpTSYeVFCraUnV.2Ag1Ki7m4znVO6" CLIENT_ID = "3MVG9QDx8IX8nP5T2Ha8ofvlmjLZl5L_gvfbT9.HJvpHGKoAS_dcMN8LYpTSYeVFCraUnV.2Ag1Ki7m4znVO6"
APP_VERSION = "2.0.10" APP_VERSION = "2.1.2"
OS_VERSION = 31 OS_VERSION = 31
OS = "android" OS = "android"
DEVICE_MODEL = "exynos9820" DEVICE_MODEL = "exynos9820"

View File

@ -89,12 +89,11 @@ def yaml_export(appliance: "HonAppliance", anonymous: bool = False) -> str:
if anonymous: if anonymous:
for sensible in ["serialNumber", "coords"]: for sensible in ["serialNumber", "coords"]:
data.get("appliance", {}).pop(sensible, None) data.get("appliance", {}).pop(sensible, None)
data = { result = printer.pretty_print({"data": data})
"data": data, if commands := printer.create_commands(appliance.commands):
"commands": printer.create_command(appliance.commands), result += printer.pretty_print({"commands": commands})
"rules": printer.create_rules(appliance.commands), if rules := printer.create_rules(appliance.commands):
} result += printer.pretty_print({"rules": rules})
result = printer.pretty_print(data)
if anonymous: if anonymous:
result = anonymize_data(result) result = anonymize_data(result)
return result return result

View File

@ -41,4 +41,4 @@ class HonParameterEnum(HonParameter):
self._value = value self._value = value
self.check_trigger(value) self.check_trigger(value)
else: else:
raise ValueError(f"Allowed values {self._values}") raise ValueError(f"Allowed values: {self._values} But was: {value}")

View File

@ -28,7 +28,7 @@ class HonParameterProgram(HonParameterEnum):
if value in self.values: if value in self.values:
self._command.category = value self._command.category = value
else: else:
raise ValueError(f"Allowed values {self.values}") raise ValueError(f"Allowed values: {self.values} But was: {value}")
@property @property
def values(self) -> List[str]: def values(self) -> List[str]:

View File

@ -53,7 +53,9 @@ class HonParameterRange(HonParameter):
self._value = value self._value = value
self.check_trigger(value) self.check_trigger(value)
else: else:
raise ValueError(f"Allowed: min {self.min} max {self.max} step {self.step}") raise ValueError(
f"Allowed: min {self.min} max {self.max} step {self.step} But was: {value}"
)
@property @property
def values(self) -> List[str]: def values(self) -> List[str]:

View File

@ -59,7 +59,7 @@ def pretty_print(
return result return result
def create_command( def create_commands(
commands: Dict[str, "HonCommand"], concat: bool = False commands: Dict[str, "HonCommand"], concat: bool = False
) -> Dict[str, Any]: ) -> Dict[str, Any]:
result: Dict[str, Any] = {} result: Dict[str, Any] = {}