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: | run: |
python -m pip install --upgrade pip python -m pip install --upgrade pip
python -m pip install -r requirements.txt 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 - name: Lint with flake8
run: | run: |
# stop the build if there are Python syntax errors or undefined names # stop the build if there are Python syntax errors or undefined names

View File

@ -124,8 +124,8 @@ class HonAppliance:
if last is None: if last is None:
continue continue
parameters = command_history[last].get("command", {}).get("parameters", {}) parameters = command_history[last].get("command", {}).get("parameters", {})
if command._multi and parameters.get("program"): if command.programs and parameters.get("program"):
command.set_program(parameters.pop("program").split(".")[-1].lower()) command.program = parameters.pop("program").split(".")[-1].lower()
command = self.commands[name] command = self.commands[name]
for key, data in command.settings.items(): for key, data in command.settings.items():
if ( if (
@ -148,9 +148,7 @@ class HonAppliance:
multi = {} multi = {}
for program, attr2 in attr.items(): for program, attr2 in attr.items():
program = program.split(".")[-1].lower() program = program.split(".")[-1].lower()
cmd = HonCommand( cmd = HonCommand(command, attr2, self._api, self, programs=multi, program_name=program)
command, attr2, self._api, self, multi=multi, program=program
)
multi[program] = cmd multi[program] = cmd
commands[command] = cmd commands[command] = cmd
self._commands = commands self._commands = commands

View File

@ -7,12 +7,12 @@ from pyhon.parameter import (
class HonCommand: 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._connector = connector
self._device = device self._device = device
self._name = name self._name = name
self._multi = multi or {} self._programs = programs or {}
self._program = program self._program_name = program_name
self._description = attributes.get("description", "") self._description = attributes.get("description", "")
self._parameters = self._create_parameters(attributes.get("parameters", {})) self._parameters = self._create_parameters(attributes.get("parameters", {}))
self._ancillary_parameters = self._create_parameters( self._ancillary_parameters = self._create_parameters(
@ -34,7 +34,7 @@ class HonCommand:
result[parameter] = HonParameterEnum(parameter, attributes) result[parameter] = HonParameterEnum(parameter, attributes)
case "fixed": case "fixed":
result[parameter] = HonParameterFixed(parameter, attributes) result[parameter] = HonParameterFixed(parameter, attributes)
if self._multi: if self._programs:
result["program"] = HonParameterProgram("program", self) result["program"] = HonParameterProgram("program", self)
return result return result
@ -57,11 +57,17 @@ class HonCommand:
self._device, self._name, parameters, self.ancillary_parameters self._device, self._name, parameters, self.ancillary_parameters
) )
def get_programs(self): @property
return self._multi def programs(self):
return self._programs
def set_program(self, program): @property
self._device.commands[self._name] = self._multi[program] 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): def _get_settings_keys(self, command=None):
command = command or self command = command or self
@ -75,10 +81,10 @@ class HonCommand:
@property @property
def setting_keys(self): def setting_keys(self):
if not self._multi: if not self._programs:
return self._get_settings_keys() return self._get_settings_keys()
result = [ 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"])) return list(set(result + ["program"]))

View File

@ -2,15 +2,15 @@ import json
import logging import logging
from datetime import datetime from datetime import datetime
from typing import Dict, Optional from typing import Dict, Optional
from typing_extensions import Self
from aiohttp import ClientSession from aiohttp import ClientSession
from typing_extensions import Self
from pyhon import const, exceptions from pyhon import const, exceptions
from pyhon.appliance import HonAppliance from pyhon.appliance import HonAppliance
from pyhon.connection.auth import HonAuth from pyhon.connection.auth import HonAuth
from pyhon.connection.handler.hon import HonConnectionHandler
from pyhon.connection.handler.anonym import HonAnonymousConnectionHandler from pyhon.connection.handler.anonym import HonAnonymousConnectionHandler
from pyhon.connection.handler.hon import HonConnectionHandler
_LOGGER = logging.getLogger() _LOGGER = logging.getLogger()

View File

@ -6,8 +6,7 @@ import urllib
from contextlib import suppress from contextlib import suppress
from dataclasses import dataclass from dataclasses import dataclass
from datetime import datetime, timedelta from datetime import datetime, timedelta
from pprint import pformat from typing import Dict, Optional
from typing import Dict, Optional, List
from urllib import parse from urllib import parse
from urllib.parse import quote from urllib.parse import quote

View File

@ -1,7 +1,7 @@
import logging import logging
from collections.abc import AsyncIterator from collections.abc import AsyncIterator
from contextlib import asynccontextmanager from contextlib import asynccontextmanager
from typing import Optional, Callable, Dict, Any from typing import Optional, Callable, Dict
import aiohttp import aiohttp
from typing_extensions import Self from typing_extensions import Self

View File

@ -1,9 +1,8 @@
import asyncio import asyncio
import copy
from typing import List, Optional, Dict, Any from typing import List, Optional, Dict, Any
from typing_extensions import Self
from aiohttp import ClientSession from aiohttp import ClientSession
from typing_extensions import Self
from pyhon import HonAPI, exceptions from pyhon import HonAPI, exceptions
from pyhon.appliance import HonAppliance from pyhon.appliance import HonAppliance

View File

@ -124,8 +124,8 @@ class HonParameterProgram(HonParameterEnum):
def __init__(self, key, command): def __init__(self, key, command):
super().__init__(key, {}) super().__init__(key, {})
self._command = command self._command = command
self._value = command._program self._value = command.program
self._values = command._multi self._values = command.programs
self._typology = "enum" self._typology = "enum"
self._filter = "" self._filter = ""
@ -136,7 +136,7 @@ class HonParameterProgram(HonParameterEnum):
@value.setter @value.setter
def value(self, value): def value(self, value):
if value in self.values: if value in self.values:
self._command.set_program(value) self._command.program = value
else: else:
raise ValueError(f"Allowed values {self._values}") 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