Skip to content

Commit

Permalink
Plugin stopping working within some time fixed.
Browse files Browse the repository at this point in the history
- Threading temporarily removed,
- heartbeat counter minor fixes.
  • Loading branch information
majki09 committed Jun 25, 2023
1 parent 292c2d8 commit 59d40e8
Showing 1 changed file with 46 additions and 51 deletions.
97 changes: 46 additions & 51 deletions plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Author: majki
#
"""
<plugin key="LG_ThinQ" name="LG ThinQ" author="majki" version="2.1.4" externallink="https://github.com/majki09/domoticz_lg_thinq_plugin">
<plugin key="LG_ThinQ" name="LG ThinQ" author="majki" version="2.2.1" externallink="https://github.com/majki09/domoticz_lg_thinq_plugin">
<description>
<h2>LG ThinQ domoticz plugin</h2><br/>
Plugin uses LG API v2. All API interface (with some mods) comes from <a href="https://github.com/no2chem/wideq"> github.com/no2chem/wideq</a>.<br/><br/>
Expand Down Expand Up @@ -49,7 +49,7 @@
import Domoticz
import json
import os.path
from threading import Thread

import wideq


Expand Down Expand Up @@ -82,7 +82,6 @@ def __init__(self):

self.lg_device = None
self.state = {}
self.hbtActive = False

def onStart(self):
# these variables definitions has to be here (onStart)
Expand Down Expand Up @@ -329,63 +328,59 @@ def onDisconnect(self, Connection):
Domoticz.Log("onDisconnect called")

# every 10 seconds
# +heartbeat_counter 6 times which gives polling every 60 seconds.
def onHeartbeat(self):
# Domoticz.Log("onHeartbeat called: "+str(self.heartbeat_counter))
if self.heartbeat_counter == 0:
# Domoticz.Log("onHeartbeat %6 called: "+str(self.heartbeat_counter))
# Domoticz.Log("heartbeat_counter: "+str(self.heartbeat_counter))
# import web_pdb; web_pdb.set_trace()
# to check if self.lg_device has been already read out from server
if self.lg_device is not None:
if not self.hbtActive:
Thread(target=self.heartbeatThread, args=None)

try:
self.lg_device_status = self.lg_device.get_status()

# AC part
if self.DEVICE_TYPE == "type_ac":
self.operation = self.lg_device_status.is_on
if self.operation:
self.operation = 1
else:
self.operation = 0

self.op_mode = self.lg_device_status.mode.name
self.target_temp = str(self.lg_device_status.temp_cfg_c)
self.room_temp = str(self.lg_device_status.temp_cur_c)
self.wind_strength = self.lg_device_status.fan_speed.name
self.h_step = self.lg_device_status.horz_swing.name
self.v_step = self.lg_device_status.vert_swing.name
# self.power = str(self.lg_device_status.energy_on_current)

# AWHP part
if self.DEVICE_TYPE == "type_awhp":
self.operation = self.lg_device_status.is_on
if self.operation:
self.operation = 1
else:
self.operation = 0

self.op_mode = self.lg_device_status.mode.name
self.target_temp = str(self.lg_device_status.temp_cfg_c)
self.hot_water_temp = str(self.lg_device_status.temp_hot_water_cfg_c)
self.in_water_temp = str(self.lg_device_status.in_water_cur_c)
self.out_water_temp = str(self.lg_device_status.out_water_cur_c)

self.update_domoticz()

except wideq.NotLoggedInError:

# read AC parameters and Client state
self.lg_device = self.wideq_object.operate_device(device_id=self.DEVICE_ID)

self.heartbeat_counter = self.heartbeat_counter + 1
if self.heartbeat_counter > 9:
if self.heartbeat_counter > 5:
self.heartbeat_counter = 0

def heartbeatThread(self):
self.hbtActive = True
try:
self.lg_device_status = self.lg_device.get_status()

# AC part
if self.DEVICE_TYPE == "type_ac":
self.operation = self.lg_device_status.is_on
if self.operation:
self.operation = 1
else:
self.operation = 0

self.op_mode = self.lg_device_status.mode.name
self.target_temp = str(self.lg_device_status.temp_cfg_c)
self.room_temp = str(self.lg_device_status.temp_cur_c)
self.wind_strength = self.lg_device_status.fan_speed.name
self.h_step = self.lg_device_status.horz_swing.name
self.v_step = self.lg_device_status.vert_swing.name
# self.power = str(self.lg_device_status.energy_on_current)

# AWHP part
if self.DEVICE_TYPE == "type_awhp":
self.operation = self.lg_device_status.is_on
if self.operation:
self.operation = 1
else:
self.operation = 0

self.op_mode = self.lg_device_status.mode.name
self.target_temp = str(self.lg_device_status.temp_cfg_c)
self.hot_water_temp = str(self.lg_device_status.temp_hot_water_cfg_c)
self.in_water_temp = str(self.lg_device_status.in_water_cur_c)
self.out_water_temp = str(self.lg_device_status.out_water_cur_c)

self.update_domoticz()

except wideq.NotLoggedInError:

# read AC parameters and Client state
self.lg_device = self.wideq_object.operate_device(device_id=self.DEVICE_ID)
self.hbtActive = False


def update_domoticz(self):
# import web_pdb; web_pdb.set_trace()
# AC part
Expand Down

0 comments on commit 59d40e8

Please sign in to comment.