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

Error in getting devices

Open mabner1996 opened this issue 3 years ago • 2 comments

So I tried to connect my ewelink device via the example in the documentation which is import ewelink from ewelink import Client, DeviceOffline

@ewelink.login('password', '[email protected]') async def main(client: Client): print(client.region) print(client.user.info) print(client.devices)

device = client.get_device('10008ecfd9') #single channel device
device2 = client.get_device('10007fgah9') #four channel device

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

print(device.state)
print(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 DeviceOffline:
    print("Device is offline!")
    

However, I got error telling my device become NoneType Here is the error log:

Region.AS ClientInfo(version='4.23.0', imei='ECCD89A0-A5AE-4756-8A31-71FEC4305BDB', model='iPhone_iPhone12,8', os='iOS', rom_version='15.5') [<Device name=Deviceede5e3 id=1000ede5e3 switch=Power.off online?=True type=DeviceType.OSPF network=Network(ssid=None, sta_mac='C8:2B:96:61:6D:31')>] Traceback (most recent call last): File "D:\AUTOSAFE\AUTOSAFE_WARNING_LIGHT\ewelink-api-python-master\test.py", line 5, in async def main(client: Client): File "D:\AUTOSAFE\AUTOSAFE_WARNING_LIGHT\ewelink-api-python-master\ewelink\client.py", line 94, in decorator result = asyncio.get_event_loop().run_until_complete(f(client)) File "D:\Users\Michael Abner\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 646, in run_until_complete return future.result() File "D:\AUTOSAFE\AUTOSAFE_WARNING_LIGHT\ewelink-api-python-master\test.py", line 14, in main print(device.params) AttributeError: 'NoneType' object has no attribute 'params'

Would like to ask whats the meaning of the error and how to solve them, Thanks!!

mabner1996 avatar Jul 11 '22 09:07 mabner1996

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_username", "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

the "your_username" is actually the "password".

agravet avatar Jan 03 '24 16:01 agravet