0

I am using the Kasa smart plug library. However, when i run

asyncio.run(self.device.update())

I get an error

kasa.exceptions.SmartDeviceException: You need to await update() to access the data

Therefore, I changed my code to

await asyncio.run(self.device.update())

However, this hasn't helped. Any help is appreciated

This is my code

import asyncio
from kasa import SmartPlug


class TpLinkHandler():
    def __init__(self, address):
        self.device = SmartPlug(address)
        self.details = self.device.hw_info

    def update(self):
        await asyncio.run(self.device.update())

    def shutdown(self):
        asyncio.run(self.device.turn_off())
        return "shutdown"

    def turnOn(self):
        asyncio.run(self.device.turn_on())
        return "Turning on"

    def __repr__(self):
        return self.details

if __name__ == "__main__":
    device = TpLinkHandler("192.168.0.41")
    device.update()
    device.turnOn()

Thanks.

1 Answer 1

0

So to solve this error you need to change the update function to

    async def update(self):
        await self.device.update()
Sign up to request clarification or add additional context in comments.

2 Comments

This change alone isn’t sufficient since it changes how update would need to be called.
Correct, it needs to be called when an async task is already in operation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.