Fix code depts

This commit is contained in:
Andre Basche 2023-04-15 23:02:37 +02:00
parent a1618bb18a
commit 46ff9be4a2
10 changed files with 34 additions and 27 deletions

View File

@ -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

View File

@ -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

View File

@ -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"]))

View File

@ -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()

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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}")

View File

@ -1 +1,2 @@
aiohttp
aiohttp==3.8.4
yarl==1.8.2

4
requirements_dev.txt Normal file
View File

@ -0,0 +1,4 @@
black==23.3.0
flake8==6.0.0
mypy==1.2.0
pylint==2.17.2