martenjacobs / py-otgw-mqtt

Python OTGW MQTT bridge
MIT License
9 stars 16 forks source link

IndentationError #13

Closed anybody84 closed 5 years ago

anybody84 commented 5 years ago

I'm not able to run this tool. I've cloned tcp branch instead of master, but I'm getting IndentationError:

pi@hassbian:/usr/lib/py-otgw-mqtt $ journalctl -u py-otgw-mqtt.service -f
-- Logs begin at Tue 2019-02-26 07:02:41 CET. --
Feb 26 08:58:48 hassbian python[11989]:     }[settings['otgw']['type']]()
Feb 26 08:58:48 hassbian python[11989]:   File "/usr/lib/py-otgw-mqtt/__main__.py", line 134, in <lambda>
Feb 26 08:58:48 hassbian python[11989]:     globals(), locals(), ['OTGWTcpClient'], 0) \
Feb 26 08:58:48 hassbian python[11989]:   File "./opentherm_tcp.py", line 48
Feb 26 08:58:48 hassbian python[11989]:     raise ConnectionException(e.message)
Feb 26 08:58:48 hassbian python[11989]:     ^
Feb 26 08:58:48 hassbian python[11989]: IndentationError: unexpected indent
Feb 26 08:58:48 hassbian systemd[1]: py-otgw-mqtt.service: Main process exited, code=exited, status=1/FAILURE
Feb 26 08:58:48 hassbian systemd[1]: py-otgw-mqtt.service: Unit entered failed state.
Feb 26 08:58:48 hassbian systemd[1]: py-otgw-mqtt.service: Failed with result 'exit-code'.
anybody84 commented 5 years ago

Ok, I've managed to fix all the indentation errors, but now I'm getting this:

pi@hassbian:/usr/lib/py-otgw-mqtt $ journalctl -u py-otgw-mqtt.service -f
-- Logs begin at Tue 2019-02-26 07:02:41 CET. --
Feb 26 09:44:54 hassbian python[13915]:   File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
Feb 26 09:44:54 hassbian python[13915]:     exec code in run_globals
Feb 26 09:44:54 hassbian python[13915]:   File "/usr/lib/py-otgw-mqtt/__main__.py", line 141, in <module>
Feb 26 09:44:54 hassbian python[13915]:     otgw_client = otgw_type(on_otgw_message, **settings['otgw'])
Feb 26 09:44:54 hassbian python[13915]:   File "./opentherm_tcp.py", line 15, in __init__
Feb 26 09:44:54 hassbian python[13915]:     self._host = kwargs['host']
Feb 26 09:44:54 hassbian python[13915]: KeyError: 'host'
Feb 26 09:44:54 hassbian systemd[1]: py-otgw-mqtt.service: Main process exited, code=exited, status=1/FAILURE
Feb 26 09:44:54 hassbian systemd[1]: py-otgw-mqtt.service: Unit entered failed state.
Feb 26 09:44:54 hassbian systemd[1]: py-otgw-mqtt.service: Failed with result 'exit-code'.

This is my config:

{
    "otgw" : {
        "type": "tcp",
        "ipadress": "172.168.0.206",
        "port": 6638
    },
    "mqtt" : {
        "client_id": "otgw",
        "host": "172.168.0.100",
        "port": 1883,
        "keepalive": 60,
        "bind_address": "",
        "username": null,
        "password": null,
        "qos": 0,
        "pub_topic_namespace": "otgw/value",
        "sub_topic_namespace": "otgw/set",
        "retain": false
    }
}
martenjacobs commented 5 years ago

the tcp branch is not being maintained, as I don't have a device to test with, but from the error it seems that you should change ipaddress in your config to host

anybody84 commented 5 years ago

Yes, you were right, it helped, but it's still not working, And this is what I'm getting now:

pi@hassbian:/usr/lib/py-otgw-mqtt $ journalctl -u py-otgw-mqtt.service -f
-- Logs begin at Tue 2019-02-26 07:13:19 CET. --
Feb 26 11:58:37 hassbian python[19475]:   File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
Feb 26 11:58:37 hassbian python[19475]:     self.run()
Feb 26 11:58:37 hassbian python[19475]:   File "/usr/lib/python2.7/threading.py", line 754, in run
Feb 26 11:58:37 hassbian python[19475]:     self.__target(*self.__args, **self.__kwargs)
Feb 26 11:58:37 hassbian python[19475]:   File "./opentherm.py", line 233, in _worker
Feb 26 11:58:37 hassbian python[19475]:     data += self.read(timeout=0.5)
Feb 26 11:58:37 hassbian python[19475]:   File "./opentherm_tcp.py", line 57, in read
Feb 26 11:58:37 hassbian python[19475]:     ready = select.select([self._socket], [], [], timeout)
Feb 26 11:58:37 hassbian python[19475]: NameError: global name 'select' is not defined
Feb 26 11:58:38 hassbian python[19475]: INFO:__main__:Done

Is this issue with opentherm_tcp.py? Or am I missing some dependencies?

Considering that I have no possibility to connect my OTGW directly to my RPi, it would be very helpful to be able to connect via TCP.

martenjacobs commented 5 years ago

That looks like a missed import. Could you try adding import select to the top of opentherm_tcp.py?

martenjacobs commented 5 years ago

And could you let me know if it works? 😬

anybody84 commented 5 years ago

Now, it works! Thanks for help.

pi@hassbian:/usr/lib/py-otgw-mqtt $ journalctl -u py-otgw-mqtt.service -f
-- Logs begin at Tue 2019-02-26 20:53:40 CET. --
Feb 26 21:10:20 hassbian python[7054]:     self.__target(*self.__args, **self.__kwargs)
Feb 26 21:10:20 hassbian python[7054]:   File "./opentherm.py", line 233, in _worker
Feb 26 21:10:20 hassbian python[7054]:     data += self.read(timeout=0.5)
Feb 26 21:10:20 hassbian python[7054]: TypeError: cannot concatenate 'str' and 'NoneType' objects
Feb 26 21:10:20 hassbian python[7054]: INFO:__main__:Done
Feb 26 21:12:39 hassbian systemd[1]: Started Python OTGW MQTT bridge.
Feb 26 21:12:39 hassbian python[7079]: INFO:__main__:Initializing MQTT
Feb 26 21:12:39 hassbian python[7079]: INFO:__main__:Initializing OTGW
Feb 26 21:12:39 hassbian python[7079]: INFO:__main__:Running
Feb 26 21:12:39 hassbian python[7079]: INFO:__main__:Connected with result code 0

As you can see, there was 1 more issue, but it was easy to fix using str()