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

Error in getting devices #5

Open
mabner1996 opened this issue Jul 11, 2022 · 2 comments
Open

Error in getting devices #5

mabner1996 opened this issue Jul 11, 2022 · 2 comments

Comments

@mabner1996
Copy link

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', 'user.address@email.com')
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!!

@dantimofte
Copy link

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

@agravet
Copy link

agravet commented Jan 3, 2024

the "your_username" is actually the "password".

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

3 participants