mclarkk / lifxlan

Python library for accessing LIFX devices locally using the official LIFX LAN protocol.
MIT License
507 stars 116 forks source link

Getting no bulbs, trying to use with ambience #160

Closed Arndorferd closed 3 years ago

Arndorferd commented 3 years ago

Im getting the issue listed here, https://github.com/LukaJankovic/Ambience/issues/3 if I put this in terminal $ python3 Python 3.9.2 (default, Feb 20 2021, 00:00:00) from lifxlan import * print(LifxLAN().get_lights())

I get []

My lifx bulbs are on the same network.

mclarkk commented 3 years ago

What OS are you on? Are you also on Fedora like the original poster of that issue? Is your network setup pretty normal? What is the prefix of your network's local address? (e.g., 192.168.1.x, 10.0.0.x)

There was a recent pull request that changed the way that the library gets the local network address for broadcasting the discovery message. Historically that functionality has had a lot of problems working consistently on every operating system. The code finally got to a place where it was working fine, but it required a third-party library called netifaces that was annoying for people to install, so I recently accepted a pull request to change the code (#129). It's hard to know right now what is causing your issue given the lack of output, but I have my suspicions and I would definitely start by seeing what the output of get_broadcast_addrs() is (in device.py).

Sorry I can't be of better help right now -- finishing up my dissertation over the next week. I can only provide high-level guidance about where the problem might be until the dissertation is filed. Let me know what you find and I'll try to follow up.

Arndorferd commented 3 years ago

I am on Pop!_Os which is an ubuntu fork. My bulbs are on 192.168.1.x. Not sure how to get the output of get_broadcast_addrs(), would I have to put it in an IDE?

mclarkk commented 3 years ago

Run this code however you'd prefer:

from lifxlan import *
print(device.get_broadcast_addrs())

What does it print out?

Arndorferd commented 3 years ago

it prints out ['192.168.1.255']

mclarkk commented 3 years ago

Great! So that's not the issue. What does this print out?

from lifxlan import *
lan = LifxLAN()
print(lan.get_devices())
print("---")
print(lan.lights)
print("---")
print(lan.devices)
Arndorferd commented 3 years ago

print(lan.get_devices()) [<lifxlan.device.Device object at 0x7ff28d397f10>, <lifxlan.device.Device object at 0x7ff28d397d90>, <lifxlan.device.Device object at 0x7ff28d397ee0>, <lifxlan.device.Device object at 0x7ff28d397f70>, <lifxlan.device.Device object at 0x7ff28d32d130>, <lifxlan.device.Device object at 0x7ff28d32d220>, <lifxlan.device.Device object at 0x7ff28d32d1c0>, <lifxlan.device.Device object at 0x7ff28d32d100>] print("---") '---' print(lan.lights) [] print("---") '---' print(lan.devices) [<lifxlan.device.Device object at 0x7ff28d397f10>, <lifxlan.device.Device object at 0x7ff28d397d90>, <lifxlan.device.Device object at 0x7ff28d397ee0>, <lifxlan.device.Device object at 0x7ff28d397f70>, <lifxlan.device.Device object at 0x7ff28d32d130>, <lifxlan.device.Device object at 0x7ff28d32d220>, <lifxlan.device.Device object at 0x7ff28d32d1c0>, <lifxlan.device.Device object at 0x7ff28d32d100>]

I put quotes around --- to prevent github from putting a line

Arndorferd commented 3 years ago

Is it recognizing my lights as devices?

mclarkk commented 3 years ago

Ah ha! That's great, so the network-based discovery is working, whew!

In lifxlan, everything that gets discovered is labeled a device by default. A device only gets tagged as a light as well if its product ID shows up in the light_products list in this file: https://github.com/mclarkk/lifxlan/blob/master/lifxlan/products.py

(You can see the product ID when you print out the device, e.g. with print(lan.get_devices()[0]). I would be interested in knowing the product IDs for the devices that aren't being recognized as lights!)

That products.py file was updated recently. If your version of lifxlan is older than 1.2.6, it would be a good idea to upgrade or reinstall it now. If you installed via pip, pip show lifxlan will print out the version info. If it's not 1.2.6, there's a good chance the products.py file is out of date and upgrading/reinstalling lifxlan will fix your problem.

Arndorferd commented 3 years ago

No its 1.2.6, I also dont know why it wouldn't show its just A19 bulbs. When I use this print(lan.get_devices()[0]) it says Product: 93 (Unknown product) and Version: 67305733

Arndorferd commented 3 years ago

Your list on products.py is missing 93? I have A19 lifx color bulbs.

Arndorferd commented 3 years ago

I put lifx white bulbs in that I had that I was going to return and that shows up in ambience although only with the on off function, no dimming or anything, so the program is working just not with my a19 bulbs

ceboxsell commented 3 years ago

As a suggestion I find it best to download the code from GitHub and install locally. It ensures the latest is installed. I then use the Hello world script to test. From my limited knowledge I think this would be best for you.

mclarkk commented 3 years ago

Wow yeah, product 93 is missing somehow. That shouldn't happen, especially since we switched to generating products.py directly from LIFX's products.json using an automatic script! I'll look into it.

mclarkk commented 3 years ago

All right, I updated both the source on Github and also the version on pip, so however you installed lifxlan, upgrade it and let me know if it works now @Arndorferd!

Arndorferd commented 3 years ago

I cant seem to upgrade it, I installed by source. I cant really find a way to uninstall the old one either.

mclarkk commented 3 years ago

To upgrade from source, navigate into the root lifxlan folder and do git pull to get the latest source. To install the newly updated code, run python setup.py install in that same root folder.

Arndorferd commented 3 years ago

Idk what you mean by root lifxlan folder, I tried just downloading the file off of here and doing python setup.py install in it. Its still the same issue but, pip show lifxlan shows 1.2.6 and not 1.2.7 so not sure if it updated.

mclarkk commented 3 years ago

Did you ever install lifxlan via pip, perhaps when following the instructions for Ambience? Ambience may also have installed lifxlan through pip automatically.

If lifxlan was ever installed by pip, then Python will still be using the pip version. You should upgrade the pip version by running pip3 install --upgrade lifxlan. If you really want to install from source for some reason let me know and I can help you uninstall the pip version, but I suspect that just upgrading the pip-installed one is going to be easier.

Arndorferd commented 3 years ago

This is working at least in that its showing up as lights with,

from lifxlan import * lan = LifxLAN() print(lan.get_devices()) print("---") print(lan.lights) print("---") print(lan.devices)

however ambience is still not showing them, perhaps the issue is still an issue with Ambience.

mclarkk commented 3 years ago

Great! Glad to have helped.

If Ambience isn't working there could be a number of reasons why. I would recommend uninstalling it and reinstalling it fresh first, and if that still doesn't work post an issue on their repo.