'python QT, pysde2 how to pass correctly json values to QLabel

Would like to know best approach how to handle QLabel and other component update on json data refresh (capturing data from my heat pump).

def queryHeatpump(self):
    url = "http://xxx.xxx.xxx.xxx/json"
    res = requests.get(url)
    msg = res.json()
    #print(res.text)
    if res.status_code == 200:
        hzPower = msg["heatpump"][8]["Value"]
        temperature = msg["heatpump"][9]["Value"]
        ....
        ....
        ....

    else:

        print("Query fail, please try again later!")

For Json refresh use QTimer:

 self.timer = QTimer()
        self.timer.timeout.connect(lambda: Functions.queryHeatpump(self)) 
        self.timer.setInterval(6000)  # 1000ms = 1s
        self.timer.start()


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source