ewelink-api-python icon indicating copy to clipboard operation
ewelink-api-python copied to clipboard

Wont run?

Open barelylit opened this issue 3 years ago • 6 comments

Exception has occurred: TypeError unsupported operand type(s) for |: 'types.GenericAlias' and 'type' File "C:\Utils\repository\ewelink-monitor\ewelink\models\enumerations.py", line 65, in Power def getitem(self, channels: tuple[int, ...] | int): File "C:\Utils\repository\ewelink-monitor\ewelink\models\enumerations.py", line 57, in class Power(Enum):

As soon as I try to run it ?

barelylit avatar Jul 12 '22 20:07 barelylit

you need to run on Python 3.10+

aamiel1 avatar Aug 23 '22 19:08 aamiel1

try this example I wrote . it's basicaly a refactor without using the login decorator. Region is important so change it to match yours

https://github.com/dantimofte/ewelink-api-python/blob/master/main.py

import ewelink


async def main():
    client: ewelink.Client = ewelink.Client("your_password", "email_or_phone", region="eu")
    await client.login()
    print(f"client version {client.region}")
    print(f"client user info: {client.user.info}")
    print(f"client devices {client.devices}")

    device = client.get_device('1000ce120a')

    print(f"device params {device.params}")
    # Raw device specific properties
    # can be accessed easily like: device.params.switch or device.params['startup'] (a subclass of dict)

    print(f"device state : {device.state}")
    print(f"device created_at: {device.created_at}")
    print("Brand Name: ", device.brand.name, "Logo URL: ", device.brand.logo.url)
    print("Device online? ", device.online)

    try:
        await device.on()
    except Exception as e:
        print("Device is offline!")
    await client.http.session.close()

if __name__ == '__main__':
    asyncio.run(main())

dantimofte avatar Jan 01 '24 05:01 dantimofte

client: ewelink.Client = ewelink.Client("your_username", "email_or_phone", region="eu"), first parameter is actually the password. Otherwise works.

agravet avatar Jan 03 '24 16:01 agravet

client: ewelink.Client = ewelink.Client("your_username", "email_or_phone", region="eu"), first parameter is actually the password. Otherwise works.

yeah, for some reason they are reversed and couldn't fight the instinct , I edited the code in my comment to reflect your correction.

Thank you

dantimofte avatar Jan 03 '24 16:01 dantimofte

For me there is some issue getting device type:

line 67, in __init__
    self.type: DeviceType = DeviceType.__dict__['_value2member_map_'].get(int(data.get('type', 0)), 0)
                                                                          ^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: 'a4'
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x0000024D793F8050>
Unclosed connector
connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x0000024D795FE040>, 23984.203)]', '[(<aiohttp.client_proto.ResponseHandler object at 0x0000024D795FD630>, 23985.218)]']
connector: <aiohttp.connector.TCPConnector object at 0x0000024D7962D910>

A quick dirty fix for my unrecognized thermostats:

if data.get('type', 0) == 'a4':
    self.type: DeviceType = DeviceType.__dict__['_value2member_map_'].get(15, 0)
else:
    self.type: DeviceType = DeviceType.__dict__['_value2member_map_'].get(int(data.get('type', 0)), 0)

activatedtmx avatar Jan 31 '24 12:01 activatedtmx

import ewelink from ewelink import Client, DeviceOffline, Power import asyncio import time

@ewelink.login('password', 'eamail') async def main(client: Client):

    device = client.get_device('xxxxxx')
    print(device.params) 
    await device.edit(Power.on)

when I run this code I'm able to print the params but when it comes to device.edit an exception is thrown: The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "c:\Users\ElioChedid\Desktop\tuya\sonoffff\ewelink-api-python\test.py", line 7, in async def main(client: Client): File "c:\Users\ElioChedid\Desktop\tuya\sonoffff\ewelink-api-python\ewelink\client.py", line 94, in decorator result = asyncio.get_event_loop().run_until_complete(f(client)) File "C:\Users\ElioChedid\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 641, in run_until_complete return future.result() File "c:\Users\ElioChedid\Desktop\tuya\sonoffff\ewelink-api-python\test.py", line 20, in main await device.edit(Power.on) File "c:\Users\ElioChedid\Desktop\tuya\sonoffff\ewelink-api-python\ewelink\models\device.py", line 86, in edit await self._state.ws.update_device_status(self.id, **params) File "c:\Users\ElioChedid\Desktop\tuya\sonoffff\ewelink-api-python\ewelink\ws.py", line 82, in update_device_status result = await asyncio.wait_for(fut, timeout = 10) File "C:\Users\ElioChedid\AppData\Local\Programs\Python\Python310\lib\asyncio\tasks.py", line 458, in wait_for raise exceptions.TimeoutError() from exc asyncio.exceptions.TimeoutError

anybody knows how to fix it?

Elio-Chedid avatar Mar 29 '24 22:03 Elio-Chedid