-
Notifications
You must be signed in to change notification settings - Fork 97
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
Async vesync #294
base: dev-2.0
Are you sure you want to change the base?
Async vesync #294
Conversation
Fix bug that prevented stale devices from being removed and new devices from being added.
Asynchronous API call with aiohttp Replace native JSON with orjson in anticipation of mashumaro Move `call_api` to manager
|
I am open to suggestions here, let me know what you think |
I think it is okay to not raise an exception. The One other idea I had was to return the error message for the last operation as a separate property e.g. lastErrorMessage... something like windows GetLastError. |
If returning false we also need an error code to know why, the is the issue for the re-auth flow. Ideally good to know if general error or username/password failed. As for the debug detail - yes would be great to allow the default logger commands to work. Leaving the debug=true override only when listed keeps backward computability. |
Maybe create a DeviceError dataclass with error code and message if the device is on and connected but has an error. This way you can test for |
Should the new async methods be prefixed with async_ like the HA methods? |
I'm thinking of returning a dataclass or other simple data structure when updating devices and calling methods, sort of like the API to indicate the device specific issue - water empty, door open, voltage error, device offline. This way the return value will allow you to handle the various scenarios appropriately. I don't want to get too granular, just indicating device offline or there is an issue preventing the device from operating. Exceptions will be raised for API errors, reponse parsing issues, rate limit, server errors, etc. I'll detail it in the next validation PR. |
I ran a quick test - not actions on my two devices. It appears to populate data, I haven't walked through each value no exceptions. One item I received was:
However, I think that is correct since I haven't unloaded the session? Does a new method have to be added to close sessions? |
It depends, if you passed a session in, it does not close it. Like if HA session is passed, the library should not close it, it has to be done manually. If you did not pass in a session, it should have closed. |
I didn't pass a session in. |
Can you post your script, this is mine without any error on exit: async def main():
async with VeSync(USERNAME, PASSWORD, debug=True) as manager:
await manager.login()
await manager.update()
for dev in manager.outlets:
print(dev)
if dev.connection_status == 'offline':
continue
await dev.turn_on()
await dev.turn_off()
await dev.get_monthly_energy()
await dev.get_weekly_energy()
await dev.get_config()
print(dev.power)
print(dev.voltage)
if __name__ == "__main__":
asyncio.run(main()) I just pushed a new commit with debug output on exit, let me know what is logged. |
|
Where is |
It was above this section. However wasn't with the async command. Adding that solves it. Editing the block above to show that. |
If you don't want to use manager = VeSync(user, pass)
await manager.__aenter__()
...
await manager.__aexit__(None, None, None) |
Migrate to aiohttp from requests.
pyvesync.VeSync(user,pass)
is an asynchronous generator:call_api()
method is moved to theVeSync
class. A session can be passed toVeSync
or it will generate a new session.Added Vesync response codes to raise correct errors and not raise errors when there is a device issue (open door, empyt water tank, etc.). Raises
aiohttp.ClientError
(aiohttp errors except >400 status code, this is handled by VeSyncServerError),VeSyncRateLimit
(rate limit return code) ,VeSyncServerError
(server code error, such as network busy) andVeSyncAPIParseError
for invalid api responses. Invalid API responses will be handled by validation.Add and remove device methods in
VeSync
class fixed. Used "hack" to avoid usingmanager._dev_list()
for device modifications. I believe this is creating a copy of the device type attributes and not updating.Fixed incorrect configuration dictionary passed to
__build_config_dict()
method