Leiaz / python-awox-mesh-light

Python package to control Awox mesh light bulbs.
MIT License
69 stars 15 forks source link

Python2 not working #2

Closed RandomNameNotUsed closed 6 years ago

RandomNameNotUsed commented 6 years ago

Hello, You did some awesome work. However, I have a question concerning the password. I haven't set up any password on the lightbulb, except the one from the account but it's linked to the awox website I guess (so, not related to the lightbulb connection). Which one do you use? When I use an empty one, I receive some error at the line: ([ a ^ b for (a,b) in zip(m_n, m_p) ])

Does anything (like 0000) works?

Leiaz commented 6 years ago

I haven't used the app. I didn't like the "mandatory cloud account" feature :) When the light is not set up (red light), it has a default name and password. In that case, you can set the name/password/key (any string, 16 bytes max) with :

mylight = light.AwoxMeshLight ("A4:C1:38:97:11:33")
mylight.connect ()
mylight.setMesh ('mesh_name', 'password', 'key')

You should be able to pass an empty string if that is your mesh password.

light = awoxmeshlight.AwoxMeshLight("A4:C1:38:97:11:33", "mesh_name", "")

What is the exact error ? If it is not the correct password, connect should return False, but it shouldn't crash.

RandomNameNotUsed commented 6 years ago

Error is during the connect in make_pair_packet name_pass = bytes([ a ^ b for (a,b) in zip(m_n, m_p) ]) unsupported operand type for ^: 'str' and 'str'

Concerning the cloud thing, I can only deeply agree with you.

Leiaz commented 6 years ago

The type of m_n and m_p should be bytes. Are you using Python 3 ? This error could come from using Python 2 instead of 3. I could try to make it compatible with both, but for now it only works with 3.

RandomNameNotUsed commented 6 years ago

Yeah, that's it! Can you give some info about what it should do so I can update it for python 2?

Leiaz commented 6 years ago

No it's xor. The problem is encode returns bytes in python 3 but str in python 2.

RandomNameNotUsed commented 6 years ago

Indeed, I just saw that. Seems that it can be passed using: name_pass = [ chr(ord(a) ^ ord(b)) for (a,b) in zip(m_n,m_p) ] name_pass = bytes(''.join(name_pass))

Leiaz commented 6 years ago

I updated it, now it should work with both Python 2 and 3.

RandomNameNotUsed commented 6 years ago

Sweet! Also, there was indeed an issue with the password. If you have already linked the light to an Awox account, it won't connect using the python library anymore. In that case, you need to reset the light (following the instructions given in the readme) before starting the python program.

Another thing is that after turning on, changing color, turning off, if I wait a few minutes, the light turn on (without using any command) and start doing some color changes (similar to some predefined sequence setup) by itself. Am I the only one having this behavior?

PS: As the python 2 issue is resolved, how do we close the issue topic?

Leiaz commented 6 years ago

If you have already linked the light to an Awox account, it won't connect using the python library anymore.

I'm a bit curious if it could be made to work... I'm not sure if the app show the actual password as it is sent... But I'll improve the readme.

Another thing is that after turning on, changing color, turning off, if I wait a few minutes, the light turn on (without using any command) and start doing some color changes (similar to some predefined sequence setup) by itself. Am I the only one having this behavior?

I haven't noticed this, but you used the app, so your light may have a newer firmware. Did you set a new name and password after resetting ? (The setMesh function hangs, but the light blinks on success, I don't know if it's bluepy or my code, it worked when I was using DBus directly.) With the default maybe it enters some demo mode ...

PS: As the python 2 issue is resolved, how do we close the issue topic?

As the issue author you should have a close button near the comment button. I'm closing this then.