Replies: 10 comments 13 replies
-
I've created a separate discussion, as others might stumble across the same issues. You should be able to use the asnyc code with very little changes, basically you only need to wrap IO-bound functions using Please try if the following: # You have to import asyncio in your own code as well
import asyncio
# Could be ConnectedDriveAccount, but that will throw Deprecationwarnings
from bimmer_connected.account import MyBMWAccount
from bimmer_connected.api.regions import get_region_from_name
USERNAME = "email"
PASSWORD = "pw"
REGION = "rest_of_world"
# Corresponds to https://github.com/FilipDem/Domoticz-BMW-plugin/blob/main/plugin.py#L224
# Only creates an object with your login information, does not login yet
myBMW = MyBMWAccount(USERNAME, PASSWORD, get_region_from_name(REGION))
# MyBMW doesn't get the vehicles directly, so you'll have to call it separately.
# This can be done everytime you want to update the vehicle state (e.g. every 5 minutes or so)
# No need to login or refresh tokens, it will be done automatically.
# get_vehicles() is IO-bound and requires asyncio handling.
# If return value is a `coroutine`, use asyncio handling.
# No return value here, but asyncio.run() would return the return value of the called coroutine.
asyncio.run(myBMW.get_vehicles())
# not IO-bound, as data has been loaded
vehicle = myBMW.get_vehicle("SOME_VIN")
# IO-bound with return value
status = asyncio.run(vehicle.remote_services.trigger_remote_air_conditioning()) If that doesn't solve your issues, are you able to provide a full stacktrace on where the error is occuring? |
Beta Was this translation helpful? Give feedback.
-
I know. No worry... |
Beta Was this translation helpful? Give feedback.
-
Hi again,
|
Beta Was this translation helpful? Give feedback.
-
Problem in general is that a plugin for Domoticz is running in a Thread (managed by Domoticz --> I cannot change this). And it is possible to stop or restart a plugin... That's why I am putting it on None when stopping the plugin or when something goes wrong with the "get_vehicles()". |
Beta Was this translation helpful? Give feedback.
-
Hi, at least this problem is indeed solved. Now I still have frequent crashes in the plugin, however I haven't yet identified whether the problem is in Domoticz itself or cause by the threading combined with asyncio. |
Beta Was this translation helpful? Give feedback.
-
The problem with the crash it solved. It was a problem in domoticz. When restarting Domoticz, all goes well... However when restarting just the plugin (equivalent of the The code: plugin.py.txt
These run in a thread Whatever it means for you, you can find the logging below:
|
Beta Was this translation helpful? Give feedback.
-
Thanks for the hint... I add also the status that I got from 2022-03-06 19:34:22.368 Status: TestBmw: Stop directive received. 2022-03-06 19:34:23.037 TestBmw: Got 13 devices: 2022-03-06 19:34:25.329 TestBmw: Login error: 'NoneType' object is not callable 2022-03-06 19:35:22.062 TestBmw: Handling task: Login. |
Beta Was this translation helpful? Give feedback.
-
I understand the concern, however I tested and it doesn't make any difference.
|
Beta Was this translation helpful? Give feedback.
-
Hi Filip, sorry for being quiet so long... I just pushed 0.9.0.0b6 which should include the |
Beta Was this translation helpful? Give feedback.
-
Top! Seems OK now. I updated by Domoticz plugin and use the beta version now... I will let it run for a while now. But first impression is OK! |
Beta Was this translation helpful? Give feedback.
-
Hi,
I just tried to update my Domoticz plugin with the breaking changes. I am using threading mechanism inside Domoticz as recommended for the Domoticz plugin development.
However when calling the
MyBMWAccount(USERNAME, PASSWORD, Regions.REST_OF_WORLD)
inside the thread, I receive the errorThere is no current event loop inside the thread
. I suppose it has something to do with the asyncio...Any hint how to get this solved?
See https://github.com/FilipDem/Domoticz-BMW-plugin/blob/main/plugin.py, function
handleTasks
(line 210).Thanks,
F
Originally posted by @FilipDem in #420 (comment)
Beta Was this translation helpful? Give feedback.
All reactions