Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
ff8ae160bb | |||
658e80a8f4 | |||
ffba85bf0d | |||
10c8d961c4 | |||
61dd470588 | |||
1ed81c2a77 | |||
e4dc3cb1d0 |
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__)
|
||||
|
||||
T = TypeVar('T')
|
||||
T = TypeVar("T")
|
||||
|
||||
|
||||
# pylint: disable=too-many-public-methods,too-many-instance-attributes
|
||||
|
@ -184,22 +184,43 @@ class HonCommandLoader:
|
||||
def _add_favourites(self) -> None:
|
||||
"""Patch program categories with favourites"""
|
||||
for favourite in self._favourites:
|
||||
name = favourite.get("favouriteName", {})
|
||||
command = favourite.get("command", {})
|
||||
command_name = command.get("commandName", "")
|
||||
program_name = self._clean_name(command.get("programName", ""))
|
||||
if not (base := self.commands[command_name].categories.get(program_name)):
|
||||
name, command_name, base = self._get_favourite_info(favourite)
|
||||
if not base:
|
||||
continue
|
||||
base_command: HonCommand = copy(base)
|
||||
self._update_base_command_with_data(base_command, favourite)
|
||||
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 parameter := base_command.parameters.get(key):
|
||||
if not (parameter := base_command.parameters.get(key)):
|
||||
continue
|
||||
with suppress(ValueError):
|
||||
parameter.value = value
|
||||
|
||||
def _update_base_command_with_favourite(self, base_command: HonCommand) -> None:
|
||||
extra_param = HonParameterFixed("favourite", {"fixedValue": "1"}, "custom")
|
||||
base_command.parameters.update(favourite=extra_param)
|
||||
|
||||
def _update_program_categories(
|
||||
self, command_name: str, name: str, base_command: HonCommand
|
||||
) -> None:
|
||||
program = base_command.parameters["program"]
|
||||
if isinstance(program, HonParameterProgram):
|
||||
program.set_value(name)
|
||||
|
@ -102,10 +102,12 @@ class HonCommand:
|
||||
if name == "zoneMap" and self._appliance.zone:
|
||||
data["default"] = self._appliance.zone
|
||||
if data.get("category") == "rule":
|
||||
if "fixedValue" not in data:
|
||||
_LOGGER.error("Rule not supported: %s", data)
|
||||
else:
|
||||
if "fixedValue" in data:
|
||||
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"):
|
||||
case "range":
|
||||
self._parameters[name] = HonParameterRange(name, data, parameter)
|
||||
@ -137,6 +139,8 @@ class HonCommand:
|
||||
async def send_parameters(self, params: Dict[str, str | float]) -> bool:
|
||||
ancillary_params = self.parameter_groups.get("ancillaryParameters", {})
|
||||
ancillary_params.pop("programRules", None)
|
||||
if "prStr" in params:
|
||||
params["prStr"] = self._category_name.upper()
|
||||
self.appliance.sync_command_to_params(self.name)
|
||||
try:
|
||||
result = await self.api.send_command(
|
||||
|
@ -6,7 +6,7 @@ CLIENT_ID = (
|
||||
"3MVG9QDx8IX8nP5T2Ha8ofvlmjLZl5L_gvfbT9."
|
||||
"HJvpHGKoAS_dcMN8LYpTSYeVFCraUnV.2Ag1Ki7m4znVO6"
|
||||
)
|
||||
APP_VERSION = "2.1.2"
|
||||
APP_VERSION = "2.3.5"
|
||||
OS_VERSION = 31
|
||||
OS = "android"
|
||||
DEVICE_MODEL = "exynos9820"
|
||||
|
@ -68,8 +68,9 @@ class HonParameter:
|
||||
self._triggers.setdefault(value, []).append((func, data))
|
||||
|
||||
def check_trigger(self, value: str | float) -> None:
|
||||
if str(value) in self._triggers:
|
||||
for trigger in self._triggers[str(value)]:
|
||||
triggers = {str(k).lower(): v for k, v in self._triggers.items()}
|
||||
if str(value).lower() in triggers:
|
||||
for trigger in triggers[str(value)]:
|
||||
func, args = trigger
|
||||
func(args)
|
||||
|
||||
|
@ -18,7 +18,7 @@ class HonParameterFixed(HonParameter):
|
||||
|
||||
@property
|
||||
def value(self) -> str | float:
|
||||
return self._value if self._value is not None else "0"
|
||||
return self._value if self._value != "" else "0"
|
||||
|
||||
@value.setter
|
||||
def value(self, value: str | float) -> None:
|
||||
|
@ -56,6 +56,11 @@ class HonRuleSet:
|
||||
extra[trigger_key] = trigger_value
|
||||
for extra_key, extra_data in param_data.items():
|
||||
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(
|
||||
self,
|
||||
@ -102,6 +107,10 @@ class HonRuleSet:
|
||||
param.values = [str(value)]
|
||||
param.value = str(value)
|
||||
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)
|
||||
return
|
||||
param.value = str(value)
|
||||
|
@ -1,3 +1,3 @@
|
||||
aiohttp==3.8.5
|
||||
yarl==1.9.2
|
||||
typing-extensions==4.7.1
|
||||
aiohttp~=3.8
|
||||
yarl~=1.9
|
||||
typing-extensions~=4.7
|
||||
|
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.3",
|
||||
version="0.15.9",
|
||||
author="Andre Basche",
|
||||
description="Control hOn devices with python",
|
||||
long_description=long_description,
|
||||
@ -20,9 +20,8 @@ setup(
|
||||
platforms="any",
|
||||
packages=find_packages(),
|
||||
include_package_data=True,
|
||||
package_data={"pyhon": ["py.typed"]},
|
||||
python_requires=">=3.10",
|
||||
install_requires=["aiohttp==3.8.5", "typing-extensions==4.7.1"],
|
||||
install_requires=["aiohttp~=3.8", "typing-extensions~=4.7", "yarl~=1.9"],
|
||||
classifiers=[
|
||||
"Development Status :: 4 - Beta",
|
||||
"Environment :: Console",
|
||||
|
Reference in New Issue
Block a user