Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
ffba85bf0d | |||
10c8d961c4 | |||
61dd470588 | |||
1ed81c2a77 | |||
e4dc3cb1d0 | |||
2523069ce9 | |||
eeb458cb1b |
2
.github/workflows/python-check.yml
vendored
2
.github/workflows/python-check.yml
vendored
@ -34,7 +34,7 @@ jobs:
|
|||||||
mypy pyhon/
|
mypy pyhon/
|
||||||
- name: Analysing the code with pylint
|
- name: Analysing the code with pylint
|
||||||
run: |
|
run: |
|
||||||
pylint $(git ls-files '*.py')
|
pylint $(git ls-files '*.py')
|
||||||
- name: Check black style
|
- name: Check black style
|
||||||
run: |
|
run: |
|
||||||
black . --check
|
black . --check
|
||||||
|
1
MANIFEST.in
Normal file
1
MANIFEST.in
Normal file
@ -0,0 +1 @@
|
|||||||
|
include pyhon/py.typed
|
@ -20,7 +20,7 @@ if TYPE_CHECKING:
|
|||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
T = TypeVar('T')
|
T = TypeVar("T")
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=too-many-public-methods,too-many-instance-attributes
|
# pylint: disable=too-many-public-methods,too-many-instance-attributes
|
||||||
|
@ -184,23 +184,44 @@ class HonCommandLoader:
|
|||||||
def _add_favourites(self) -> None:
|
def _add_favourites(self) -> None:
|
||||||
"""Patch program categories with favourites"""
|
"""Patch program categories with favourites"""
|
||||||
for favourite in self._favourites:
|
for favourite in self._favourites:
|
||||||
name = favourite.get("favouriteName", {})
|
name, command_name, base = self._get_favourite_info(favourite)
|
||||||
command = favourite.get("command", {})
|
if not base:
|
||||||
command_name = command.get("commandName", "")
|
|
||||||
program_name = self._clean_name(command.get("programName", ""))
|
|
||||||
if not (base := self.commands[command_name].categories.get(program_name)):
|
|
||||||
continue
|
continue
|
||||||
base_command: HonCommand = copy(base)
|
base_command: HonCommand = copy(base)
|
||||||
for data in command.values():
|
self._update_base_command_with_data(base_command, favourite)
|
||||||
if isinstance(data, str):
|
self._update_base_command_with_favourite(base_command)
|
||||||
|
self._update_program_categories(command_name, name, base_command)
|
||||||
|
|
||||||
|
def _get_favourite_info(
|
||||||
|
self, favourite: Dict[str, Any]
|
||||||
|
) -> tuple[str, str, HonCommand | None]:
|
||||||
|
name: str = favourite.get("favouriteName", {})
|
||||||
|
command = favourite.get("command", {})
|
||||||
|
command_name: str = command.get("commandName", "")
|
||||||
|
program_name = self._clean_name(command.get("programName", ""))
|
||||||
|
base_command = self.commands[command_name].categories.get(program_name)
|
||||||
|
return name, command_name, base_command
|
||||||
|
|
||||||
|
def _update_base_command_with_data(
|
||||||
|
self, base_command: HonCommand, command: Dict[str, Any]
|
||||||
|
) -> None:
|
||||||
|
for data in command.values():
|
||||||
|
if isinstance(data, str):
|
||||||
|
continue
|
||||||
|
for key, value in data.items():
|
||||||
|
if not (parameter := base_command.parameters.get(key)):
|
||||||
continue
|
continue
|
||||||
for key, value in data.items():
|
with suppress(ValueError):
|
||||||
if parameter := base_command.parameters.get(key):
|
parameter.value = value
|
||||||
with suppress(ValueError):
|
|
||||||
parameter.value = value
|
def _update_base_command_with_favourite(self, base_command: HonCommand) -> None:
|
||||||
extra_param = HonParameterFixed("favourite", {"fixedValue": "1"}, "custom")
|
extra_param = HonParameterFixed("favourite", {"fixedValue": "1"}, "custom")
|
||||||
base_command.parameters.update(favourite=extra_param)
|
base_command.parameters.update(favourite=extra_param)
|
||||||
program = base_command.parameters["program"]
|
|
||||||
if isinstance(program, HonParameterProgram):
|
def _update_program_categories(
|
||||||
program.set_value(name)
|
self, command_name: str, name: str, base_command: HonCommand
|
||||||
self.commands[command_name].categories[name] = base_command
|
) -> None:
|
||||||
|
program = base_command.parameters["program"]
|
||||||
|
if isinstance(program, HonParameterProgram):
|
||||||
|
program.set_value(name)
|
||||||
|
self.commands[command_name].categories[name] = base_command
|
||||||
|
@ -102,10 +102,12 @@ class HonCommand:
|
|||||||
if name == "zoneMap" and self._appliance.zone:
|
if name == "zoneMap" and self._appliance.zone:
|
||||||
data["default"] = self._appliance.zone
|
data["default"] = self._appliance.zone
|
||||||
if data.get("category") == "rule":
|
if data.get("category") == "rule":
|
||||||
if "fixedValue" not in data:
|
if "fixedValue" in data:
|
||||||
_LOGGER.error("Rule not supported: %s", data)
|
|
||||||
else:
|
|
||||||
self._rules.append(HonRuleSet(self, data["fixedValue"]))
|
self._rules.append(HonRuleSet(self, data["fixedValue"]))
|
||||||
|
elif "enumValues" in data:
|
||||||
|
self._rules.append(HonRuleSet(self, data["enumValues"]))
|
||||||
|
else:
|
||||||
|
_LOGGER.warning("Rule not supported: %s", data)
|
||||||
match data.get("typology"):
|
match data.get("typology"):
|
||||||
case "range":
|
case "range":
|
||||||
self._parameters[name] = HonParameterRange(name, data, parameter)
|
self._parameters[name] = HonParameterRange(name, data, parameter)
|
||||||
|
@ -68,8 +68,9 @@ class HonParameter:
|
|||||||
self._triggers.setdefault(value, []).append((func, data))
|
self._triggers.setdefault(value, []).append((func, data))
|
||||||
|
|
||||||
def check_trigger(self, value: str | float) -> None:
|
def check_trigger(self, value: str | float) -> None:
|
||||||
if str(value) in self._triggers:
|
triggers = {str(k).lower(): v for k, v in self._triggers.items()}
|
||||||
for trigger in self._triggers[str(value)]:
|
if str(value).lower() in triggers:
|
||||||
|
for trigger in triggers[str(value)]:
|
||||||
func, args = trigger
|
func, args = trigger
|
||||||
func(args)
|
func(args)
|
||||||
|
|
||||||
|
@ -56,6 +56,11 @@ class HonRuleSet:
|
|||||||
extra[trigger_key] = trigger_value
|
extra[trigger_key] = trigger_value
|
||||||
for extra_key, extra_data in param_data.items():
|
for extra_key, extra_data in param_data.items():
|
||||||
self._parse_conditions(param_key, extra_key, extra_data, extra)
|
self._parse_conditions(param_key, extra_key, extra_data, extra)
|
||||||
|
else:
|
||||||
|
param_data = {"typology": "fixed", "fixedValue": param_data}
|
||||||
|
self._create_rule(
|
||||||
|
param_key, trigger_key, trigger_value, param_data, extra
|
||||||
|
)
|
||||||
|
|
||||||
def _create_rule(
|
def _create_rule(
|
||||||
self,
|
self,
|
||||||
@ -102,6 +107,10 @@ class HonRuleSet:
|
|||||||
param.values = [str(value)]
|
param.values = [str(value)]
|
||||||
param.value = str(value)
|
param.value = str(value)
|
||||||
elif isinstance(param, HonParameterRange):
|
elif isinstance(param, HonParameterRange):
|
||||||
|
if float(value) < param.min:
|
||||||
|
param.min = float(value)
|
||||||
|
elif float(value) > param.max:
|
||||||
|
param.max = float(value)
|
||||||
param.value = float(value)
|
param.value = float(value)
|
||||||
return
|
return
|
||||||
param.value = str(value)
|
param.value = str(value)
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
aiohttp==3.8.5
|
aiohttp~=3.8.5
|
||||||
yarl==1.9.2
|
yarl~=1.9.2
|
||||||
typing-extensions==4.7.1
|
typing-extensions~=4.7.1
|
||||||
|
4
setup.py
4
setup.py
@ -7,7 +7,7 @@ with open("README.md", "r", encoding="utf-8") as f:
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="pyhOn",
|
name="pyhOn",
|
||||||
version="0.15.1",
|
version="0.15.7",
|
||||||
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,
|
||||||
@ -21,7 +21,7 @@ setup(
|
|||||||
packages=find_packages(),
|
packages=find_packages(),
|
||||||
include_package_data=True,
|
include_package_data=True,
|
||||||
python_requires=">=3.10",
|
python_requires=">=3.10",
|
||||||
install_requires=["aiohttp==3.8.5", "typing-extensions==4.7.1"],
|
install_requires=["aiohttp~=3.8.5", "typing-extensions~=4.7.1", "yarl~=1.9.2"],
|
||||||
classifiers=[
|
classifiers=[
|
||||||
"Development Status :: 4 - Beta",
|
"Development Status :: 4 - Beta",
|
||||||
"Environment :: Console",
|
"Environment :: Console",
|
||||||
|
Reference in New Issue
Block a user