Skip to content
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

Wont run? #6

Open
barelylit opened this issue Jul 12, 2022 · 6 comments
Open

Wont run? #6

barelylit opened this issue Jul 12, 2022 · 6 comments

Comments

@barelylit
Copy link

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 ?
@aamiel1
Copy link

aamiel1 commented Aug 23, 2022

you need to run on Python 3.10+

@dantimofte
Copy link

dantimofte commented Jan 1, 2024

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())

@agravet
Copy link

agravet commented Jan 3, 2024

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

@dantimofte
Copy link

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

@activatedtmx
Copy link

activatedtmx commented Jan 31, 2024

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)

@Elio-Chedid
Copy link

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?

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

6 participants