Thank you for your help waltervl! below I answer your questions and report another bug that also seems related to "def
What happens if you change this
Code: Select all
def data_meteo(name):
return list(map(float,re.findall("(\d+\.?\d+);(\d+);(\d+)",DE.Devices[name].s_value)[0]))
Into this
Code: Select all
def data_meteo(name):
testvalue = list(map(float,re.findall("(\d+\.?\d+);(\d+);(\d+)",DE.Devices[name].s_value)[0]))
return testvalue
It does not change anything and the output is still
Code: Select all
2023-01-24 13:27:23.932 Python:[16.2, 64.0, 3.0]
2023-01-24 13:27:23.933 Error: Traceback (most recent call last):
2023-01-24 13:27:23.933 Error: File "Script #1", line 11, in <module>
2023-01-24 13:27:23.933 Error: File "Script #1", line 8, in data_meteo
2023-01-24 13:27:23.933 Error: NameError: name 're' is not defined
what I also remembered from another issue was to import the module in the def again to prevent errors.
So
Code: Select all
def data_meteo(name):
import re
return list(map(float,re.findall("(\d+\.?\d+);(\d+);(\d+)",DE.Devices[name].s_value)[0]))
The error is still present but interestingly it change the type of error (name 'DE' is not defined)
Code: Select all
2023-01-24 13:40:17.540 Python:[15.9, 65.0, 3.0]
2023-01-24 13:40:17.541 Error: Traceback (most recent call last):
2023-01-24 13:40:17.541 Error: File "Script #1", line 11, in <module>
2023-01-24 13:40:17.541 Error: File "Script #1", line 9, in data_meteo
2023-01-24 13:40:17.541 Error: NameError: name 'DE' is not defined
Perhaps remove the def from the code completely and see if it works. Not optimal but if it works it could be a workaround. Then it could be a issue in python event scripts (rewritten in 2022 due to incompatibility for newer python versions)
In this code it is already working without the def. I could remove all def however as you mention it is not optimal at all: my actual code is much more complex with more than 20 def. This simple example was chosen only for illustration.
Finally this bug with "def " and "re" is not the only one I have in my code (that was perfectly working for years): I can report at least another bug which is not related to "re". This is the code
Code: Select all
import DomoticzEvents as DE
import datetime,time
time1=datetime.datetime.now() # heure actuelle
date_retour=datetime.datetime(2023,1,2,15)
DE.Log("Python:"+str(date_retour))
def thermostat_chauffage_chambre():
duree=date_retour-time1
seuil_temperature_chambre=12
return seuil_temperature_chambre
thermostat_chauffage_chambre()
and the output shows that even if "date_retour" is known it gives an error when called inside the def
Code: Select all
2023-01-24 13:45:34.404 Python:2023-01-02 15:00:00
2023-01-24 13:45:34.406 Error: Traceback (most recent call last):
2023-01-24 13:45:34.406 Error: File "Script #2", line 13, in <module>
2023-01-24 13:45:34.406 Error: File "Script #2", line 9, in thermostat_chauffage_chambre
2023-01-24 13:45:34.406 Error: NameError: name 'date_retour' is not defined
Nothing seems to work inside a def, this is crazy