Comments (4)
I've included here the output from those two print statements so that you can identify the hardware.
Hardware: {'dev_name': 'Smart Wi-Fi Plug Mini',
'fwId': '00000000000000000000000000000000',
'hwId': 'redacted',
'hw_ver': '1.0',
'mac': 'redacted',
'oemId': 'redacted',
'sw_ver': '1.5.6 Build 191114 Rel.104204',
'type': 'IOT.SMARTPLUGSWITCH'}
Full sysinfo: {'active_mode': 'none',
'alias': 'Charger',
'dev_name': 'Smart Wi-Fi Plug Mini',
'deviceId': 'redacted',
'err_code': 0,
'feature': 'TIM',
'fwId': '00000000000000000000000000000000',
'hwId': 'redacted',
'hw_ver': '1.0',
'icon_hash': '',
'latitude_i': redacted,
'led_off': 0,
'longitude_i': redacted,
'mac': 'redacted',
'model': 'HS105(US)',
'next_action': {'type': -1},
'oemId': 'redacted',
'on_time': 0,
'relay_state': 0,
'rssi': -65,
'sw_ver': '1.5.6 Build 191114 Rel.104204',
'type': 'IOT.SMARTPLUGSWITCH',
'updating': 0}
from python-kasa.
You have to run all I/O (i.e., commands that communicate with the device, accessing properties like hw_info
do not cause any I/O) inside the same event loop due to how the library is designed, and each individual call to asyncio.run()
creates a new event loop which breaks the connection.
The simplest way to fix this it to wrap your code inside a separate async function you execute using asyncio.run()
, and use await
inside of it to call coroutines. Try this:
import asyncio
from kasa import SmartPlug
from pprint import pformat as pf
async def main():
charger = "192.168.11.65"
plug = SmartPlug(charger)
# plug.timeout = 20
await plug.update()
# print("Hardware: %s" % pf(plug.hw_info))
# print("Full sysinfo: %s" % pf(plug.sys_info))
if (plug.is_on):
await plug.turn_off()
else:
print("Plug was already OFF")
if __name__ == "__main__":
asyncio.run(main())
from python-kasa.
You have to run all I/O (i.e., commands that communicate with the device, accessing properties like
hw_info
do not cause any I/O) inside the same event loop due to how the library is designed, and each individual call toasyncio.run()
creates a new event loop which breaks the connection.The simplest way to fix this it to wrap your code inside a separate async function you execute using
asyncio.run()
, and useawait
inside of it to call coroutines. Try this:
Thank you. I wonder why none of the documentation shows a simple wrapping method like this? Here's the README I'm referring to. Click on the "Plugs" link and there's essentially a stub for the (deprecated) kasa.SmartPlug class. Select the Library Usage -> Getting Started menu item on the left. There is some REPL-related activities for discovering. Move on to the How-to Guides and look at the "Connect without discovery" option. I wouldn't call that a useful example. Visit the API Reference -> Device. Again, not very helpful.
See, the problem I see as someone with more than four decades of experience is that everything worked just great about ten years ago coding to my TP-Link devices. I decided to use some code this week to remote control things on my solar system and suddenly everything has changed in that period of time. That is to be expected. I'm reasonably certain that the async
was added in this timeframe. It would be lost on the user of this library that the connection is lost in this circumstance.
I would suggest minimally including an actual python script example for directing a single, known device to toggle ON or OFF. I'd also suggest to the coder in the README that the entire async
session must happen in concert rather than individually-wrapped. I have read countless pseudo-tutorials online today and nobody has actually provided a working script. Mostly what they're doing is parroting snippets from your documentation. I rather doubt that they've actually controlled their own SmartPlugs, for example.
Thanks. I'll close this issue. I'm hoping that the docs get some McLovin.
from python-kasa.
Related Issues (20)
- Allow exposing extra feature metadata HOT 1
- Error when connecting P110 to wi-fi HOT 3
- Support for T300 and T110 HOT 26
- Credentials hash does not work for H100 HOT 6
- Fix --help on subcommands
- S505d invalid authentication HOT 8
- Module queries in dump_devinfo
- Question: Remote control devices from external servers? HOT 1
- Return correct unit for temperature sensor
- Improve typing of Feature HOT 1
- Simplify instance creation API HOT 1
- Cleanup TODO comments
- dumping HTTP POST Body for Tapo Vacuum (RV30 Plus) HOT 10
- New HS220 require authentication HOT 5
- from kasa import Device fails HOT 1
- DeviceConfig dict must always be serializable
- 0.7.0 Release Summary HOT 1
- KP200 factory resets [Using a BASH script with python-kasa to auto repair] HOT 6
- SMART.TAPOHUB does not work with 0.7.0 dev2 HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-kasa.