Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
eeb458cb1b | |||
2764700bc7 | |||
e6c796e822 | |||
454f2d8916 | |||
59ca8b6caf | |||
44c55c681d | |||
cfee10df5f | |||
e0774677eb | |||
fc60d15e60 | |||
8ef8c0405d |
31
mypy.ini
31
mypy.ini
@ -1,9 +1,24 @@
|
||||
[mypy]
|
||||
check_untyped_defs = True
|
||||
disallow_any_generics = True
|
||||
disallow_untyped_defs = True
|
||||
disallow_any_unimported = True
|
||||
no_implicit_optional = True
|
||||
warn_return_any = True
|
||||
show_error_codes = True
|
||||
warn_unused_ignores = True
|
||||
check_untyped_defs = true
|
||||
disallow_any_generics = true
|
||||
disallow_any_unimported = true
|
||||
disallow_incomplete_defs = true
|
||||
disallow_subclassing_any = true
|
||||
disallow_untyped_calls = true
|
||||
disallow_untyped_decorators = true
|
||||
disallow_untyped_defs = true
|
||||
disable_error_code = annotation-unchecked
|
||||
enable_error_code = ignore-without-code, redundant-self, truthy-iterable
|
||||
follow_imports = silent
|
||||
local_partial_types = true
|
||||
no_implicit_optional = true
|
||||
no_implicit_reexport = true
|
||||
show_error_codes = true
|
||||
strict_concatenate = false
|
||||
strict_equality = true
|
||||
warn_incomplete_stub = true
|
||||
warn_redundant_casts = true
|
||||
warn_return_any = true
|
||||
warn_unreachable = true
|
||||
warn_unused_configs = true
|
||||
warn_unused_ignores = true
|
||||
|
@ -3,7 +3,7 @@ import logging
|
||||
import re
|
||||
from datetime import datetime, timedelta
|
||||
from pathlib import Path
|
||||
from typing import Optional, Dict, Any, TYPE_CHECKING, List
|
||||
from typing import Optional, Dict, Any, TYPE_CHECKING, List, TypeVar, overload
|
||||
|
||||
from pyhon import diagnose, exceptions
|
||||
from pyhon.appliances.base import ApplianceBase
|
||||
@ -20,6 +20,8 @@ if TYPE_CHECKING:
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
T = TypeVar('T')
|
||||
|
||||
|
||||
# pylint: disable=too-many-public-methods,too-many-instance-attributes
|
||||
class HonAppliance:
|
||||
@ -49,24 +51,35 @@ class HonAppliance:
|
||||
except ModuleNotFoundError:
|
||||
self._extra = None
|
||||
|
||||
def _get_nested_item(self, item: str) -> Any:
|
||||
result: List[Any] | Dict[str, Any] = self.data
|
||||
for key in item.split("."):
|
||||
if all(k in "0123456789" for k in key) and isinstance(result, list):
|
||||
result = result[int(key)]
|
||||
elif isinstance(result, dict):
|
||||
result = result[key]
|
||||
return result
|
||||
|
||||
def __getitem__(self, item: str) -> Any:
|
||||
if self._zone:
|
||||
item += f"Z{self._zone}"
|
||||
if "." in item:
|
||||
result = self.data
|
||||
for key in item.split("."):
|
||||
if all(k in "0123456789" for k in key) and isinstance(result, list):
|
||||
result = result[int(key)]
|
||||
else:
|
||||
result = result[key]
|
||||
return result
|
||||
return self._get_nested_item(item)
|
||||
if item in self.data:
|
||||
return self.data[item]
|
||||
if item in self.attributes["parameters"]:
|
||||
return self.attributes["parameters"][item].value
|
||||
return self.info[item]
|
||||
|
||||
def get(self, item: str, default: Any = None) -> Any:
|
||||
@overload
|
||||
def get(self, item: str, default: None = None) -> Any:
|
||||
...
|
||||
|
||||
@overload
|
||||
def get(self, item: str, default: T) -> T:
|
||||
...
|
||||
|
||||
def get(self, item: str, default: Optional[T] = None) -> Any:
|
||||
try:
|
||||
return self[item]
|
||||
except (KeyError, IndexError):
|
||||
@ -250,7 +263,9 @@ class HonAppliance:
|
||||
if not (command := self.commands.get(command_name)):
|
||||
return
|
||||
for key in command.setting_keys:
|
||||
if (new := self.attributes.get("parameters", {}).get(key)) is None:
|
||||
if (
|
||||
new := self.attributes.get("parameters", {}).get(key)
|
||||
) is None or new.value == "":
|
||||
continue
|
||||
setting = command.settings[key]
|
||||
try:
|
||||
|
@ -10,12 +10,12 @@ class Appliance(ApplianceBase):
|
||||
data["modeZ1"] = "holiday"
|
||||
elif data["parameters"]["intelligenceMode"] == "1":
|
||||
data["modeZ1"] = "auto_set"
|
||||
elif data["parameters"]["quickModeZ1"] == "1":
|
||||
elif data["parameters"].get("quickModeZ1") == "1":
|
||||
data["modeZ1"] = "super_cool"
|
||||
else:
|
||||
data["modeZ1"] = "no_mode"
|
||||
|
||||
if data["parameters"]["quickModeZ2"] == "1":
|
||||
if data["parameters"].get("quickModeZ2") == "1":
|
||||
data["modeZ2"] = "super_freeze"
|
||||
elif data["parameters"]["intelligenceMode"] == "1":
|
||||
data["modeZ2"] = "auto_set"
|
||||
|
@ -188,18 +188,19 @@ class HonCommandLoader:
|
||||
command = favourite.get("command", {})
|
||||
command_name = command.get("commandName", "")
|
||||
program_name = self._clean_name(command.get("programName", ""))
|
||||
base: HonCommand = copy(
|
||||
self.commands[command_name].categories[program_name]
|
||||
)
|
||||
if not (base := self.commands[command_name].categories.get(program_name)):
|
||||
continue
|
||||
base_command: HonCommand = copy(base)
|
||||
for data in command.values():
|
||||
if isinstance(data, str):
|
||||
continue
|
||||
for key, value in data.items():
|
||||
if parameter := base.parameters.get(key):
|
||||
if parameter := base_command.parameters.get(key):
|
||||
with suppress(ValueError):
|
||||
parameter.value = value
|
||||
extra_param = HonParameterFixed("favourite", {"fixedValue": "1"}, "custom")
|
||||
base.parameters.update(favourite=extra_param)
|
||||
if isinstance(program := base.parameters["program"], HonParameterProgram):
|
||||
base_command.parameters.update(favourite=extra_param)
|
||||
program = base_command.parameters["program"]
|
||||
if isinstance(program, HonParameterProgram):
|
||||
program.set_value(name)
|
||||
self.commands[command_name].categories[name] = base
|
||||
self.commands[command_name].categories[name] = base_command
|
||||
|
@ -278,10 +278,12 @@ class TestAPI(HonAPI):
|
||||
async def load_appliances(self) -> List[Dict[str, Any]]:
|
||||
result = []
|
||||
for appliance in self._path.glob("*/"):
|
||||
with open(
|
||||
appliance / "appliance_data.json", "r", encoding="utf-8"
|
||||
) as json_file:
|
||||
file = appliance / "appliance_data.json"
|
||||
with open(file, "r", encoding="utf-8") as json_file:
|
||||
try:
|
||||
result.append(json.loads(json_file.read()))
|
||||
except json.decoder.JSONDecodeError as error:
|
||||
_LOGGER.error("%s - %s", str(file), error)
|
||||
return result
|
||||
|
||||
async def load_commands(self, appliance: HonAppliance) -> Dict[str, Any]:
|
||||
@ -318,4 +320,5 @@ class TestAPI(HonAPI):
|
||||
parameters: Dict[str, Any],
|
||||
ancillary_parameters: Dict[str, Any],
|
||||
) -> bool:
|
||||
_LOGGER.info("%s - %s", str(parameters), str(ancillary_parameters))
|
||||
return True
|
||||
|
0
pyhon/py.typed
Normal file
0
pyhon/py.typed
Normal file
@ -1,3 +1,3 @@
|
||||
aiohttp==3.8.4
|
||||
yarl==1.8.2
|
||||
aiohttp==3.8.5
|
||||
yarl==1.9.2
|
||||
typing-extensions==4.7.1
|
||||
|
5
setup.py
5
setup.py
@ -7,7 +7,7 @@ with open("README.md", "r", encoding="utf-8") as f:
|
||||
|
||||
setup(
|
||||
name="pyhOn",
|
||||
version="0.15.0",
|
||||
version="0.15.2",
|
||||
author="Andre Basche",
|
||||
description="Control hOn devices with python",
|
||||
long_description=long_description,
|
||||
@ -20,8 +20,9 @@ setup(
|
||||
platforms="any",
|
||||
packages=find_packages(),
|
||||
include_package_data=True,
|
||||
package_data={"pyhOn": ["py.typed"]},
|
||||
python_requires=">=3.10",
|
||||
install_requires=["aiohttp==3.8.4", "typing-extensions==4.7.1"],
|
||||
install_requires=["aiohttp==3.8.5", "typing-extensions==4.7.1"],
|
||||
classifiers=[
|
||||
"Development Status :: 4 - Beta",
|
||||
"Environment :: Console",
|
||||
|
Reference in New Issue
Block a user