From 80fa67176fe2cfd238224f72795f2afd0d8c48af Mon Sep 17 00:00:00 2001 From: majki09 Date: Fri, 30 Dec 2022 20:47:22 +0100 Subject: [PATCH] state returning in operate_device removed - checking for V2 devices in operate_device removed. --- plugin.py | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/plugin.py b/plugin.py index de65152..05e08fd 100644 --- a/plugin.py +++ b/plugin.py @@ -5,7 +5,7 @@ # Author: majki # """ - +

LG ThinQ domoticz plugin


Plugin uses LG API v2. All API interface (with some mods) comes from github.com/no2chem/wideq.

@@ -104,7 +104,7 @@ def onStart(self): try: # read AC parameters and Client state - self.lg_device, self.state = self.wideq_object.operate_device(device_id=self.DEVICE_ID) + self.lg_device = self.wideq_object.operate_device(device_id=self.DEVICE_ID) except UserWarning: Domoticz.Error("Device not found on your LG account. Check your device ID.") @@ -375,7 +375,7 @@ def onHeartbeat(self): # read AC parameters and Client state Domoticz.Log("Session expired, refreshing...") - self.lg_device, self.state = self.wideq_object.operate_device(device_id=self.DEVICE_ID) + self.lg_device = self.wideq_object.operate_device(device_id=self.DEVICE_ID) self.heartbeat_counter = self.heartbeat_counter + 1 if self.heartbeat_counter > 6: @@ -730,7 +730,7 @@ def _force_device(self, client, device_id): raise CompatibilityError(f'Sorry, device "{device_id}" is V1 LG API and will NOT work with this domoticz plugin.') return device - def operate_device(self, device_id: str="") -> (wideq.ACDevice, dict): + def operate_device(self, device_id: str = ""): lg_device = None client = wideq.Client.load(self.state) @@ -762,17 +762,14 @@ def operate_device(self, device_id: str="") -> (wideq.ACDevice, dict): except CompatibilityError as exc: Domoticz.Error(exc.args[0]) Domoticz.Error("You don't have any compatible (LG API V2) devices.") - return lg_device, self.state + return None - thinq2_devices = [dev for dev in client.devices if dev.platform_type == "thinq2"] - if len(thinq2_devices) > 0: - current_state = client.dump() - # Save the updated state. - if self.state != current_state: - with open(self.state_file, "w") as f: - json.dump(current_state, f) - Domoticz.Log(f"State written to state file '{os.path.abspath(self.state_file)}'") + current_state = client.dump() + # Save the updated state. + if self.state != current_state: + self.state = current_state + with open(self.state_file, "w") as f: + json.dump(current_state, f) + Domoticz.Log(f"State written to state file '{os.path.abspath(self.state_file)}'") - dict_for_domoticz = {"gateway": current_state["gateway"], "auth": current_state["auth"]} - - return lg_device, dict_for_domoticz + return lg_device