8000 LB100 unable to turn on or off the lights · Issue #68 · python-kasa/python-kasa · GitHub
[go: up one dir, main page]

Skip to content

LB100 unable to turn on or off the lights #68

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
shnkreddy98 opened this issue Jun 6, 2020 · 4 comments
Closed

LB100 unable to turn on or off the lights #68

shnkreddy98 opened this issue Jun 6, 2020 · 4 comments

Comments

@shnkreddy98
Copy link
shnkreddy98 commented Jun 6, 2020

I have installed all the required libraries, it's maybe because i don't know how the async and await works.. so first thing

import asyncio
from kasa import SmartPlug
from pprint import pformat as pf

plug = SmartPlug("ip of the device")
asyncio.run(plug.update())
await plug.turn_on()

if i do this it says await outside async

if i do this

import asyncio
from kasa import SmartPlug
from pprint import pformat as pf


async def main():
    plug = SmartPlug("ip of the device")
    asyncio.run(plug.update())
    await plug.turn_on()

asyncio.run(main())

it says this

Traceback (most recent call last):
  File "d:/Documents/8sem/Project Phase II/new/let's do this/demo.py", line 11, in <module>
    asyncio.run(main())
  File "C:\Users\ReNew\AppData\Local\Programs\Python\Python38-32\lib\asyncio\runners.py", line 43, in run
    return loop.run_until_complete(main)
  File "C:\Users\ReNew\AppData\Local\Programs\Python\Python38-32\lib\asyncio\base_events.py", line 612, in run_until_complete
    return future.result()
  File "d:/Documents/8sem/Project Phase II/new/let's do this/demo.py", line 8, in main
    asyncio.run(plug.update())
  File "C:\Users\ReNew\AppData\Local\Programs\Python\Python38-32\lib\asyncio\runners.py", line 33, in run
    raise RuntimeError(
RuntimeError: asyncio.run() cannot be called from a running event loop
sys:1: RuntimeWarning: coroutine 'SmartDevice.update' was never awaited

can someone help me on how to move forward

@rytilahti
Copy link
Member

That RuntimeError informs you that you cannot use asyncio.run in already running eventloop (which you started in the last line of your code), so simply replace that inside your main() with await plug.update() and it will work. Note, that you don't necessarily need to do an update if you want to use any of the coroutines (like that turn_on), it is only necessary for reading the properties.

@shnkreddy98
Copy link
Author
raise SmartDeviceException(f"Error on {target} {cmd}: {result}")
kasa.exceptions.SmartDeviceException: Error on system set_relay_state: {'err_code': -2000, 'err_msg': 'Method not support'}

i got his error on doing so...

import asyncio
from kasa import SmartPlug
from pprint import pformat as pf


async def main():
    plug = SmartPlug("ip")
    await plug.turn_on()

asyncio.run(main())

@shnkreddy98
Copy link
Author
shnkreddy98 commented Jun 6, 2020

sorry, i was using a bulb and defined it as a plug.. my bad
appreciate the work, thanks mahn.... and if i could know more about how this library was created or how it works i would be glad...

@rytilahti
Copy link
Member
rytilahti commented Jun 6, 2020

The documentation needs definitely improvements, as some parts of it are shown how it can be used in synchronous manner. I'll try to keep your suggestions in mind when revising the readme!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0