mclarkk / lifxlan

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

[Example request] The most basic way to turn an individual, specific light on and off #185

Closed Kommynct closed 7 months ago

Kommynct commented 7 months ago

I've been struggling with this for hours, i'm not a python dev, i'm just trying to control my lights with my linux pc

#!/usr/bin/env python

import sys

from lifxlan import LifxLAN

def main ():

    lan = LifxLAN()
    light = Light("bettersafethansorrymacaddress", "withprivacyipaddress")
    light.set_power(65535, 0.2)
if __name__=="__main__":
    main()
Traceback (most recent call last):
  File "/home/communist/.config/tofi/scripts/fromscratch.py", line 13, in <module>
    main()
  File "/home/communist/.config/tofi/scripts/fromscratch.py", line 10, in main
    light = Light("privacy", "sostillremoved")
            ^^^^^
NameError: name 'Light' is not defined. Did you mean: 'light'?

I have no idea why this doesn't work, it says light isn't defined, i'm sure i'm doing a number of things wrong, but a very basic on/off switch example for a specific light using the specific device example would be extremely helpful for me.

The closest things in the examples that I see affect random lights, so, I just really don't know how to work with this.

edit:

I HAVE SOLVED IT ON MY OWN IT WAS A MISSING IMPORT THANK YOU ME

#!/usr/bin/env python

import sys
from lifxlan import LifxLAN, Light

def main ():

    computer = Light("mac", "ip")
    computer.set_power(65535, 0.2)
if __name__=="__main__":
    main()