Improve update performance
This commit is contained in:
parent
38d09e2ef5
commit
7b51caecca
10 changed files with 63 additions and 49 deletions
|
@ -242,15 +242,20 @@ class HonAppliance:
|
||||||
self._attributes = await self.api.load_attributes(self)
|
self._attributes = await self.api.load_attributes(self)
|
||||||
for name, values in self._attributes.pop("shadow").get("parameters").items():
|
for name, values in self._attributes.pop("shadow").get("parameters").items():
|
||||||
self._attributes.setdefault("parameters", {})[name] = values["parNewVal"]
|
self._attributes.setdefault("parameters", {})[name] = values["parNewVal"]
|
||||||
|
if self._extra:
|
||||||
|
self._attributes = self._extra.attributes(self._attributes)
|
||||||
|
|
||||||
async def load_statistics(self):
|
async def load_statistics(self):
|
||||||
self._statistics = await self.api.load_statistics(self)
|
self._statistics = await self.api.load_statistics(self)
|
||||||
self._statistics |= await self.api.load_maintenance(self)
|
self._statistics |= await self.api.load_maintenance(self)
|
||||||
|
|
||||||
async def update(self):
|
async def update(self, force=False):
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
if not self._last_update or self._last_update < now - timedelta(
|
if (
|
||||||
seconds=self._MINIMAL_UPDATE_INTERVAL
|
force
|
||||||
|
or not self._last_update
|
||||||
|
or self._last_update
|
||||||
|
< now - timedelta(seconds=self._MINIMAL_UPDATE_INTERVAL)
|
||||||
):
|
):
|
||||||
self._last_update = now
|
self._last_update = now
|
||||||
await self.load_attributes()
|
await self.load_attributes()
|
||||||
|
@ -286,9 +291,8 @@ class HonAppliance:
|
||||||
"statistics": self.statistics,
|
"statistics": self.statistics,
|
||||||
"additional_data": self._additional_data,
|
"additional_data": self._additional_data,
|
||||||
**self.command_parameters,
|
**self.command_parameters,
|
||||||
|
**self.attributes,
|
||||||
}
|
}
|
||||||
if self._extra:
|
|
||||||
return self._extra.data(result)
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def diagnose(self, whitespace=" ", command_only=False):
|
def diagnose(self, whitespace=" ", command_only=False):
|
||||||
|
@ -320,6 +324,12 @@ class HonAppliance:
|
||||||
)
|
)
|
||||||
return result.replace(self.mac_address, "xx-xx-xx-xx-xx-xx")
|
return result.replace(self.mac_address, "xx-xx-xx-xx-xx-xx")
|
||||||
|
|
||||||
|
def sync_to_params(self, command_name):
|
||||||
|
command: HonCommand = self.commands.get(command_name)
|
||||||
|
for key, value in self.attributes.get("parameters", {}).items():
|
||||||
|
if isinstance(value, str) and (new := command.parameters.get(key)):
|
||||||
|
self.attributes["parameters"][key] = str(new.intern_value)
|
||||||
|
|
||||||
def sync_command(self, main, target=None) -> None:
|
def sync_command(self, main, target=None) -> None:
|
||||||
base: HonCommand = self.commands.get(main)
|
base: HonCommand = self.commands.get(main)
|
||||||
for command, data in self.commands.items():
|
for command, data in self.commands.items():
|
||||||
|
@ -345,6 +355,7 @@ class HonApplianceTest(HonAppliance):
|
||||||
super().__init__(None, {})
|
super().__init__(None, {})
|
||||||
self._name = name
|
self._name = name
|
||||||
self.load_commands()
|
self.load_commands()
|
||||||
|
self.load_attributes()
|
||||||
self._info = self._appliance_model
|
self._info = self._appliance_model
|
||||||
|
|
||||||
def load_commands(self):
|
def load_commands(self):
|
||||||
|
|
|
@ -2,12 +2,14 @@ class ApplianceBase:
|
||||||
def __init__(self, appliance):
|
def __init__(self, appliance):
|
||||||
self.parent = appliance
|
self.parent = appliance
|
||||||
|
|
||||||
def data(self, data):
|
def attributes(self, data):
|
||||||
program_name = "No Program"
|
program_name = "No Program"
|
||||||
if program := int(data["attributes"]["parameters"].get("prCode", "0")):
|
if program := int(data["parameters"].get("prCode", "0")):
|
||||||
if ids := self.parent.settings["startProgram.program"].ids:
|
if start_cmd := self.parent.settings.get("startProgram.program"):
|
||||||
program_name = ids.get(program, program_name)
|
if ids := start_cmd.ids:
|
||||||
|
program_name = ids.get(program, program_name)
|
||||||
data["programName"] = program_name
|
data["programName"] = program_name
|
||||||
|
return data
|
||||||
|
|
||||||
def settings(self, settings):
|
def settings(self, settings):
|
||||||
return settings
|
return settings
|
||||||
|
|
|
@ -2,9 +2,9 @@ from pyhon.appliances.base import ApplianceBase
|
||||||
|
|
||||||
|
|
||||||
class Appliance(ApplianceBase):
|
class Appliance(ApplianceBase):
|
||||||
def data(self, data):
|
def attributes(self, data):
|
||||||
super().data(data)
|
data = super().attributes(data)
|
||||||
if data["attributes"]["lastConnEvent"]["category"] == "DISCONNECTED":
|
if data["lastConnEvent"]["category"] == "DISCONNECTED":
|
||||||
data["attributes"]["parameters"]["machMode"] = "0"
|
data["parameters"]["machMode"] = "0"
|
||||||
data["active"] = bool(data.get("attributes", {}).get("activity"))
|
data["active"] = bool(data.get("activity"))
|
||||||
return data
|
return data
|
||||||
|
|
|
@ -2,17 +2,17 @@ from pyhon.appliances.base import ApplianceBase
|
||||||
|
|
||||||
|
|
||||||
class Appliance(ApplianceBase):
|
class Appliance(ApplianceBase):
|
||||||
def data(self, data):
|
def attributes(self, data):
|
||||||
super().data(data)
|
data = super().attributes(data)
|
||||||
if data["attributes"]["lastConnEvent"]["category"] == "DISCONNECTED":
|
if data["lastConnEvent"]["category"] == "DISCONNECTED":
|
||||||
data["attributes"]["parameters"]["temp"] = "0"
|
data["parameters"]["temp"] = "0"
|
||||||
data["attributes"]["parameters"]["onOffStatus"] = "0"
|
data["parameters"]["onOffStatus"] = "0"
|
||||||
data["attributes"]["parameters"]["remoteCtrValid"] = "0"
|
data["parameters"]["remoteCtrValid"] = "0"
|
||||||
data["attributes"]["parameters"]["remainingTimeMM"] = "0"
|
data["parameters"]["remainingTimeMM"] = "0"
|
||||||
|
|
||||||
data["active"] = data["attributes"]["parameters"]["onOffStatus"] == "1"
|
data["active"] = data["parameters"]["onOffStatus"] == "1"
|
||||||
|
|
||||||
if program := int(data["attributes"]["parameters"]["prCode"]):
|
if program := int(data["parameters"]["prCode"]):
|
||||||
ids = self.parent.settings["startProgram.program"].ids
|
ids = self.parent.settings["startProgram.program"].ids
|
||||||
data["programName"] = ids.get(program, "")
|
data["programName"] = ids.get(program, "")
|
||||||
|
|
||||||
|
|
|
@ -2,20 +2,20 @@ from pyhon.appliances.base import ApplianceBase
|
||||||
|
|
||||||
|
|
||||||
class Appliance(ApplianceBase):
|
class Appliance(ApplianceBase):
|
||||||
def data(self, data):
|
def attributes(self, data):
|
||||||
super().data(data)
|
data = super().attributes(data)
|
||||||
if data["attributes"]["parameters"]["holidayMode"] == "1":
|
if data["parameters"]["holidayMode"] == "1":
|
||||||
data["modeZ1"] = "holiday"
|
data["modeZ1"] = "holiday"
|
||||||
elif data["attributes"]["parameters"]["intelligenceMode"] == "1":
|
elif data["parameters"]["intelligenceMode"] == "1":
|
||||||
data["modeZ1"] = "auto_set"
|
data["modeZ1"] = "auto_set"
|
||||||
elif data["attributes"]["parameters"]["quickModeZ1"] == "1":
|
elif data["parameters"]["quickModeZ1"] == "1":
|
||||||
data["modeZ1"] = "super_cool"
|
data["modeZ1"] = "super_cool"
|
||||||
else:
|
else:
|
||||||
data["modeZ1"] = "no_mode"
|
data["modeZ1"] = "no_mode"
|
||||||
|
|
||||||
if data["attributes"]["parameters"]["quickModeZ2"] == "1":
|
if data["parameters"]["quickModeZ2"] == "1":
|
||||||
data["modeZ2"] = "super_freeze"
|
data["modeZ2"] = "super_freeze"
|
||||||
elif data["attributes"]["parameters"]["intelligenceMode"] == "1":
|
elif data["parameters"]["intelligenceMode"] == "1":
|
||||||
data["modeZ2"] = "auto_set"
|
data["modeZ2"] = "auto_set"
|
||||||
else:
|
else:
|
||||||
data["modeZ2"] = "no_mode"
|
data["modeZ2"] = "no_mode"
|
||||||
|
|
|
@ -3,12 +3,12 @@ from pyhon.parameter.fixed import HonParameterFixed
|
||||||
|
|
||||||
|
|
||||||
class Appliance(ApplianceBase):
|
class Appliance(ApplianceBase):
|
||||||
def data(self, data):
|
def attributes(self, data):
|
||||||
super().data(data)
|
data = super().attributes(data)
|
||||||
if data["attributes"]["lastConnEvent"]["category"] == "DISCONNECTED":
|
if data["lastConnEvent"]["category"] == "DISCONNECTED":
|
||||||
data["attributes"]["parameters"]["machMode"] = "0"
|
data["parameters"]["machMode"] = "0"
|
||||||
data["active"] = bool(data.get("attributes", {}).get("activity"))
|
data["active"] = bool(data.get("activity"))
|
||||||
data["pause"] = data["attributes"]["parameters"]["machMode"] == "3"
|
data["pause"] = data["parameters"]["machMode"] == "3"
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def settings(self, settings):
|
def settings(self, settings):
|
||||||
|
|
|
@ -2,12 +2,12 @@ from pyhon.appliances.base import ApplianceBase
|
||||||
|
|
||||||
|
|
||||||
class Appliance(ApplianceBase):
|
class Appliance(ApplianceBase):
|
||||||
def data(self, data):
|
def attributes(self, data):
|
||||||
super().data(data)
|
data = super().attributes(data)
|
||||||
if data["attributes"]["lastConnEvent"]["category"] == "DISCONNECTED":
|
if data["lastConnEvent"]["category"] == "DISCONNECTED":
|
||||||
data["attributes"]["parameters"]["machMode"] = "0"
|
data["parameters"]["machMode"] = "0"
|
||||||
data["active"] = bool(data.get("attributes", {}).get("activity"))
|
data["active"] = bool(data.get("activity"))
|
||||||
data["pause"] = data["attributes"]["parameters"]["machMode"] == "3"
|
data["pause"] = data["parameters"]["machMode"] == "3"
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def settings(self, settings):
|
def settings(self, settings):
|
||||||
|
|
|
@ -2,12 +2,12 @@ from pyhon.appliances.base import ApplianceBase
|
||||||
|
|
||||||
|
|
||||||
class Appliance(ApplianceBase):
|
class Appliance(ApplianceBase):
|
||||||
def data(self, data):
|
def attributes(self, data):
|
||||||
super().data(data)
|
data = super().attributes(data)
|
||||||
if data["attributes"]["lastConnEvent"]["category"] == "DISCONNECTED":
|
if data["lastConnEvent"]["category"] == "DISCONNECTED":
|
||||||
data["attributes"]["parameters"]["machMode"] = "0"
|
data["parameters"]["machMode"] = "0"
|
||||||
data["active"] = bool(data.get("attributes", {}).get("activity"))
|
data["active"] = bool(data.get("activity"))
|
||||||
data["pause"] = data["attributes"]["parameters"]["machMode"] == "3"
|
data["pause"] = data["parameters"]["machMode"] == "3"
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def settings(self, settings):
|
def settings(self, settings):
|
||||||
|
|
|
@ -110,6 +110,7 @@ class HonCommand:
|
||||||
async def send(self) -> bool:
|
async def send(self) -> bool:
|
||||||
params = self.parameter_groups.get("parameters", {})
|
params = self.parameter_groups.get("parameters", {})
|
||||||
ancillary_params = self.parameter_groups.get("ancillaryParameters", {})
|
ancillary_params = self.parameter_groups.get("ancillaryParameters", {})
|
||||||
|
self.appliance.sync_to_params(self.name)
|
||||||
return await self.api.send_command(
|
return await self.api.send_command(
|
||||||
self._appliance, self._name, params, ancillary_params
|
self._appliance, self._name, params, ancillary_params
|
||||||
)
|
)
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -7,7 +7,7 @@ with open("README.md", "r") as f:
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="pyhOn",
|
name="pyhOn",
|
||||||
version="0.12.1",
|
version="0.12.2",
|
||||||
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,
|
||||||
|
|
Loading…
Reference in a new issue