Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with sync_command #16

Merged
merged 20 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions pyhon/appliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,12 @@ def sync_params_to_command(self, command_name: str) -> None:
_LOGGER.info("Can't set %s - %s", key, error)
continue

def sync_command(self, main: str, target: Optional[List[str] | str] = None) -> None:
def sync_command(
self,
main: str,
target: Optional[List[str] | str] = None,
to_sync: Optional[List[str] | bool] = None,
) -> None:
base: Optional[HonCommand] = self.commands.get(main)
if not base:
return
Expand All @@ -287,7 +292,12 @@ def sync_command(self, main: str, target: Optional[List[str] | str] = None) -> N

for name, target_param in data.parameters.items():
if not (base_param := base.parameters.get(name)):
return
continue
if to_sync and (
(isinstance(to_sync, list) and name not in to_sync)
or not base_param.mandatory
):
continue
self.sync_parameter(base_param, target_param)

def sync_parameter(self, main: Parameter, target: Parameter) -> None:
Expand Down
9 changes: 7 additions & 2 deletions pyhon/appliances/wh.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
from typing import Any, Dict

from pyhon.appliances.base import ApplianceBase
from pyhon.parameter.base import HonParameter


class Appliance(ApplianceBase):
def attributes(self, data: Dict[str, Any]) -> Dict[str, Any]:
data = super().attributes(data)
data["active"] = data["parameters"]["onOffStatus"] == "1"

parameter = data["parameters"]["onOffStatus"]
is_class = isinstance(parameter, HonParameter)
data["active"] = parameter.value == 1 if is_class else parameter == 1
return data

def settings(self, settings: Dict[str, Any]) -> Dict[str, Any]:
return settings
2 changes: 1 addition & 1 deletion pyhon/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ async def send(self, only_mandatory: bool = False) -> bool:
async def send_specific(self, param_names: List[str]) -> bool:
params: Dict[str, str | float] = {}
for key, parameter in self._parameters.items():
if key in param_names:
if key in param_names or parameter.mandatory:
params[key] = parameter.value
return await self.send_parameters(params)

Expand Down