cross-posted from: https://lemmy.ml/post/13397153

I’m just trying to control my smartlights with a script, it seems to be having a lot of problems, I really don’t know what I’m doing, i’d appreciate any help I can get

Once I have a script that can individually turn lights on/off i can edit the rest myself, I just can’t get the base functionality working.

  • Uriel_Copy@lemmy.world
    link
    fedilink
    arrow-up
    0
    ·
    8 months ago

    I don’t know the details, but I can tell you that you need to import Light from somewhere before you can instantiate it.

  • kryptonianCodeMonkey@lemmy.world
    link
    fedilink
    arrow-up
    0
    ·
    8 months ago

    I saw you already solved your own issue. Just want to make sure you understand what the actual issue was and why.

    In order to use a function, such as Light(), the interpreter running your script needs to know what that function does. To do that, either you need to have defined it in your code (like you did with your main function) or you need to have imported it from from a another source like lifxlan where it is defined. In your original script, you imported the function LifxLAN, though as you discovered, you forgot to import Light as well.

    Additionally, instead of importing each function, you could have also imported the entirety of the lifxlan library by changing your import statement to import lifxlan. I’m not recommending you do that. It’s not best practice to import more than you need and it can cause issues if what you’re importing is not just a library but also executes code. But, if you did import the whole library, that would have imported all of the functions in lifxlan including both LifexLAN and Light. You could then call those functions by prefixing the library name to the functions. For example, lifxlan.Light().

    • Communist@lemmy.mlOP
      link
      fedilink
      English
      arrow-up
      0
      ·
      8 months ago

      Yeah, my real issue was that I erroneously assumed

      from lifxlan import LifxLAN

      WOULD import the Light function, but of course, it does not, I didn’t realize that when you do a from import you’re just importing a single specific command and not the whole library, and just used it like it was in the examples they gave, but thank you for the comment and this community is awesome, just that you were willing to write that all that out just to help me understand is incredibly kind, thank you!