ewelink-api-python
ewelink-api-python copied to clipboard
Wont run?
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
As soon as I try to run it ?
you need to run on Python 3.10+
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())
client: ewelink.Client = ewelink.Client("your_username", "email_or_phone", region="eu"), first parameter is actually the password. Otherwise works.
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
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)
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
anybody knows how to fix it?