From 46ff9be4a2cb07003e7168776274c27503d301ec Mon Sep 17 00:00:00 2001 From: Andre Basche Date: Sat, 15 Apr 2023 23:02:37 +0200 Subject: [PATCH] Fix code depts --- .github/workflows/python-check.yml | 2 +- pyhon/appliance.py | 8 +++----- pyhon/commands.py | 26 ++++++++++++++++---------- pyhon/connection/api.py | 4 ++-- pyhon/connection/auth.py | 3 +-- pyhon/connection/handler/base.py | 2 +- pyhon/hon.py | 3 +-- pyhon/parameter.py | 6 +++--- requirements.txt | 3 ++- requirements_dev.txt | 4 ++++ 10 files changed, 34 insertions(+), 27 deletions(-) create mode 100644 requirements_dev.txt diff --git a/.github/workflows/python-check.yml b/.github/workflows/python-check.yml index f2b0bd0..813ebd7 100644 --- a/.github/workflows/python-check.yml +++ b/.github/workflows/python-check.yml @@ -25,7 +25,7 @@ jobs: run: | python -m pip install --upgrade pip python -m pip install -r requirements.txt - python -m pip install flake8 pylint black mypy + python -m pip install -r requirements_dev.txt - name: Lint with flake8 run: | # stop the build if there are Python syntax errors or undefined names diff --git a/pyhon/appliance.py b/pyhon/appliance.py index 297f87e..bf070ff 100644 --- a/pyhon/appliance.py +++ b/pyhon/appliance.py @@ -124,8 +124,8 @@ class HonAppliance: if last is None: continue parameters = command_history[last].get("command", {}).get("parameters", {}) - if command._multi and parameters.get("program"): - command.set_program(parameters.pop("program").split(".")[-1].lower()) + if command.programs and parameters.get("program"): + command.program = parameters.pop("program").split(".")[-1].lower() command = self.commands[name] for key, data in command.settings.items(): if ( @@ -148,9 +148,7 @@ class HonAppliance: multi = {} for program, attr2 in attr.items(): program = program.split(".")[-1].lower() - cmd = HonCommand( - command, attr2, self._api, self, multi=multi, program=program - ) + cmd = HonCommand(command, attr2, self._api, self, programs=multi, program_name=program) multi[program] = cmd commands[command] = cmd self._commands = commands diff --git a/pyhon/commands.py b/pyhon/commands.py index b6a5427..f9c47f2 100644 --- a/pyhon/commands.py +++ b/pyhon/commands.py @@ -7,12 +7,12 @@ from pyhon.parameter import ( class HonCommand: - def __init__(self, name, attributes, connector, device, multi=None, program=""): + def __init__(self, name:str, attributes, connector, device, programs=None, program_name=""): self._connector = connector self._device = device self._name = name - self._multi = multi or {} - self._program = program + self._programs = programs or {} + self._program_name = program_name self._description = attributes.get("description", "") self._parameters = self._create_parameters(attributes.get("parameters", {})) self._ancillary_parameters = self._create_parameters( @@ -34,7 +34,7 @@ class HonCommand: result[parameter] = HonParameterEnum(parameter, attributes) case "fixed": result[parameter] = HonParameterFixed(parameter, attributes) - if self._multi: + if self._programs: result["program"] = HonParameterProgram("program", self) return result @@ -57,11 +57,17 @@ class HonCommand: self._device, self._name, parameters, self.ancillary_parameters ) - def get_programs(self): - return self._multi + @property + def programs(self): + return self._programs - def set_program(self, program): - self._device.commands[self._name] = self._multi[program] + @property + def program(self): + return self._program_name + + @program.setter + def program(self, program): + self._device.commands[self._name] = self._programs[program] def _get_settings_keys(self, command=None): command = command or self @@ -75,10 +81,10 @@ class HonCommand: @property def setting_keys(self): - if not self._multi: + if not self._programs: return self._get_settings_keys() result = [ - key for cmd in self._multi.values() for key in self._get_settings_keys(cmd) + key for cmd in self._programs.values() for key in self._get_settings_keys(cmd) ] return list(set(result + ["program"])) diff --git a/pyhon/connection/api.py b/pyhon/connection/api.py index 3af519a..4852a10 100644 --- a/pyhon/connection/api.py +++ b/pyhon/connection/api.py @@ -2,15 +2,15 @@ import json import logging from datetime import datetime from typing import Dict, Optional -from typing_extensions import Self from aiohttp import ClientSession +from typing_extensions import Self from pyhon import const, exceptions from pyhon.appliance import HonAppliance from pyhon.connection.auth import HonAuth -from pyhon.connection.handler.hon import HonConnectionHandler from pyhon.connection.handler.anonym import HonAnonymousConnectionHandler +from pyhon.connection.handler.hon import HonConnectionHandler _LOGGER = logging.getLogger() diff --git a/pyhon/connection/auth.py b/pyhon/connection/auth.py index a48c054..6f26f1b 100644 --- a/pyhon/connection/auth.py +++ b/pyhon/connection/auth.py @@ -6,8 +6,7 @@ import urllib from contextlib import suppress from dataclasses import dataclass from datetime import datetime, timedelta -from pprint import pformat -from typing import Dict, Optional, List +from typing import Dict, Optional from urllib import parse from urllib.parse import quote diff --git a/pyhon/connection/handler/base.py b/pyhon/connection/handler/base.py index ad77ebe..7ccf5f4 100644 --- a/pyhon/connection/handler/base.py +++ b/pyhon/connection/handler/base.py @@ -1,7 +1,7 @@ import logging from collections.abc import AsyncIterator from contextlib import asynccontextmanager -from typing import Optional, Callable, Dict, Any +from typing import Optional, Callable, Dict import aiohttp from typing_extensions import Self diff --git a/pyhon/hon.py b/pyhon/hon.py index 9aa236c..872461e 100644 --- a/pyhon/hon.py +++ b/pyhon/hon.py @@ -1,9 +1,8 @@ import asyncio -import copy from typing import List, Optional, Dict, Any -from typing_extensions import Self from aiohttp import ClientSession +from typing_extensions import Self from pyhon import HonAPI, exceptions from pyhon.appliance import HonAppliance diff --git a/pyhon/parameter.py b/pyhon/parameter.py index 7d9208e..853c521 100644 --- a/pyhon/parameter.py +++ b/pyhon/parameter.py @@ -124,8 +124,8 @@ class HonParameterProgram(HonParameterEnum): def __init__(self, key, command): super().__init__(key, {}) self._command = command - self._value = command._program - self._values = command._multi + self._value = command.program + self._values = command.programs self._typology = "enum" self._filter = "" @@ -136,7 +136,7 @@ class HonParameterProgram(HonParameterEnum): @value.setter def value(self, value): if value in self.values: - self._command.set_program(value) + self._command.program = value else: raise ValueError(f"Allowed values {self._values}") diff --git a/requirements.txt b/requirements.txt index ee4ba4f..9ba048c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ -aiohttp +aiohttp==3.8.4 +yarl==1.8.2 diff --git a/requirements_dev.txt b/requirements_dev.txt new file mode 100644 index 0000000..9bb012e --- /dev/null +++ b/requirements_dev.txt @@ -0,0 +1,4 @@ +black==23.3.0 +flake8==6.0.0 +mypy==1.2.0 +pylint==2.17.2