eslavnov / pylips

Control Philips TVs (2015+) and Ambilight (+ Hue) through their reverse-engineered API (+ MQTT support!)
MIT License
342 stars 60 forks source link

[BUG] Exits immediately although mqtt is configured #27

Closed timbru31 closed 5 years ago

timbru31 commented 5 years ago

Describe the bug Pylips does not listen to MQTT packages because it exits right after the user invoked the script.

To Reproduce Configure MQTT support:

[DEFAULT]
mqtt_listen = True
mqtt_update = False
[...]
[MQTT]
topic_pylips = pylips
topic_status = pylibs_status
  1. Launch pylips with python3.7 pylips.py
  2. Process starts and immediately exits again, no listening for mqtt is happening.

Expected behavior Have pylips running in the foreground (or even better background) listening to mqtt packages and running the commands.

Screenshots n/a

Additional context n/a

eslavnov commented 5 years ago

Hey @timbru31, that's weird, I am literally running it right now with no issues... Could you please share the full settings.ini you are using? (replace the sensitive data with something like XXXX) It could be that there is a flaw in the way I handle the settings...

timbru31 commented 5 years ago

Sure:

[DEFAULT]
verbose = True
mqtt_listen = True
mqtt_update = False
num_retries = 3
update_interval = 3

[TV]
host = 192.168.178.46
port = 1926
apiv = 6
user = XXXX
pass = XXXX
protocol = https://

[MQTT]
host = rasp.bee
port = 8883
user = pylips
pass = XXXXXX
tls = True
topic_pylips = pylips
topic_status = pylibs_status

I'm not that good with Python, but from my understanding it seems that the mqtt loop is not respected, so the script just finished. Like that a while(true) loop is missing.

Some extra info:

eslavnov commented 5 years ago

Thanks, man! I'll investigate and will report back later today

eslavnov commented 5 years ago

Thanks for reporting, I think I've fixed it. I've indeed missed an edge case where you run mqtt_listen = True with mqtt_update = False, since the while loop was present only in the mqtt_update :) Silly mistake, but easy to fix, thanks again for your help!

I've pushed a new version with a fix + you can now also specify the path to your certificate in the settings.ini. Let me know if it works for you! Thanks!

timbru31 commented 5 years ago

Works, thanks for the quick fix!

timbru31 commented 5 years ago

I have to revert my comment. While it does work, it goes to 100% CPU now. Could this be due to the

        if self.config["DEFAULT"]["mqtt_listen"] == "True" and self.config["DEFAULT"]["mqtt_update"] == "False":
           while True:
               pass

?

eslavnov commented 5 years ago

Haha, sorry about that - I knew that it was a bad idea...

I've made a proper fix and tested it, seems to be working fine on my machine. I've just pushed it, thanks again for the feedback!

eslavnov commented 5 years ago

Closing for now, feel free to reopen if the issue is not solved.