Writing a property to log (Stupid question I know!)

Posted on
Sun Dec 27, 2020 6:14 am
Bildhauer offline
Posts: 68
Joined: Sep 30, 2019
Location: 22113 Oststeinbek (near Hamburg), Germany

Writing a property to log (Stupid question I know!)

Hello,

I've written a script to optimze network of devices of a room. It's like this:

from time import sleep
var_Bereich=indigo.variables[1422766774] #Scan_Bereich einlesen
ScanFolderId = indigo.devices.folders.getId(var_Bereich.value)
indigo.server.log("Aktualisiere "+var_Bereich.value) # +" Wert ScanFolderId: "+ScanFolderId)
var_Wartezeit=indigo.variables[198746959] #Wartezeit einlesen
indigo.server.log("Warterzeit: "+ var_Wartezeit.value)
var_Wartezeit_Int=int(var_Wartezeit.value)
for dev in indigo.devices.iter("indigo.zwave"):
# indigo.server.log("überprüfte Adresse: "+dev.address)
if dev.enabled and dev.folderId == ScanFolderId:
LogMessage="Aktualisiere Adresse %s (%s [%s])" % (str(dev.address), dev.name, dev.model)
indigo.server.log(LogMessage)
indigo.zwave.startNetworkOptimize(dev.address)
sleep (var_Wartezeit_Int)


Now I'm failing to writer the neighbour devices to the log file. How can I get "zwNodeNeighborsStr" to the log file?

Thanks in advance for your help_

Best regards

Bildhauer

Posted on
Sun Dec 27, 2020 7:00 am
FlyingDiver offline
User avatar
Posts: 5321
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Writing a property to log (Stupid question I know!)

I don't see where zwNodeNeighborsStr is defined in your script, so I can't suggest how to write it out. But a couple of comments:

I suspect your device names and variables are unicode, not plain ascii. So you need to use unicode string handling everywhere. So use u"XX" instead of "XXX" anywhere you have a string literal.

Also, use the new Python string formatting, it's safer. Do:

Code: Select all
LogMessage=u"Aktualisiere Adresse {} ({} [{}])".format(unicode(dev.address), dev.name, dev.model)


instead of

Code: Select all
LogMessage="Aktualisiere Adresse %s (%s [%s])" % (str(dev.address), dev.name, dev.model)


And use the CODE tags when posting, not QUOTE.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Sun Dec 27, 2020 10:09 am
Bildhauer offline
Posts: 68
Joined: Sep 30, 2019
Location: 22113 Oststeinbek (near Hamburg), Germany

Re: Writing a property to log (Stupid question I know!)

Thx,

so this would work?

Code: Select all
LogMessage=u"Aktualisiere Adresse {} ({} [{}] ). Die neuen Nachbarn sind: {}".format(unicode(dev.address), dev.name, dev.model, dev.zwNodeNeighborsStr)


Thanking you for your support in advance!

Best regards

Bildhauer

Posted on
Sun Dec 27, 2020 10:21 am
FlyingDiver offline
User avatar
Posts: 5321
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Writing a property to log (Stupid question I know!)

No, that's not a property of the device. It's a key in one of the device dictionaries. You need:

Code: Select all
LogMessage=u"Aktualisiere Adresse {} ({} [{}] ). Die neuen Nachbarn sind: {}".format(unicode(dev.address), dev.name, dev.model, dev.ownerProps['zwNodeNeighborsStr'])

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Sun Dec 27, 2020 1:10 pm
Bildhauer offline
Posts: 68
Joined: Sep 30, 2019
Location: 22113 Oststeinbek (near Hamburg), Germany

Re: Writing a property to log (Stupid question I know!)

Great. Thank you!

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 2 guests