Spanni26 / pyHPSU

Python Script to read and send commands to a Rotex HPSU
26 stars 15 forks source link

pyHPSU and openHAB 3.0 #34

Open martinbischofff opened 3 years ago

martinbischofff commented 3 years ago

Hi all.

I'm just migrating to OH 3.0 and found the following issue: When trying to send values to openHAB the log files fills with errors like 2021-02-06 21:16:38.810 [ERROR] [rg.apache.cxf.jaxrs.utils.JAXRSUtils] - No message body reader has been found for class java.lang.String, ContentType: application/octet-stream

Appearently this is caused by a missing header. Changing openhab.py like this seems to resolve that issue:

        url = "http://%s:%s/rest/items/%s%s/state" % (self.openhabhost, str(self.openhabport), self.openhabitemprefix, item)
        try:
            headers = {"Content-Type": "text/plain"}
            r = requests.put(url, data=str(value), headers=headers)
        except requests.exceptions.RequestException as e:
            rc = "ko"
            self.hpsu.printd("exception", "Error " + str(e.code) + ": " + str(e.reason))

A quick test didn't show any problems with openHAB 2.5, so this might work for both versions.

Anyone who can verify this?

Regards Martin