Indigo – Python documentation

Posted on
Tue Feb 23, 2016 8:33 pm
canalrun offline
Posts: 80
Joined: Jan 17, 2016

Indigo – Python documentation

Hello,

I'm writing a few very simple Python scripts. I've searched through the documentation, IOM, examples, and Python beginner websites.

I'm wondering where I could find documentation for some of the functions that seem to be available to Indigo scripts?

For example, I was writing a script to email a trigger notice with date and time if the Smoke Alarm went off. I found the examples for sending an email – those are almost enough.

One thing I want to do is append the date and time. I came up with (almost by luck):
theBody = "Indigo Smoke Alarm Trigger\n" + str(indigo.server.getTime().date()) + "\n" + str(indigo.server.getTime().time())

I see in the IOM documentation where indigo.server.getTime() is documented, But I don't see where .date() or .time() is documented. Where would these be documented? Are these two actually part of the Python language?

I'm sure there has got to be a better way to append the date and time to a string. Again, would that actually be part of Python rather than Indigo?

Thanks,
Barry.

Posted on
Tue Feb 23, 2016 8:52 pm
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Indigo – Python documentation

Date and time stuff you should just use the standard Python libraries. I think those functions you're using are for getting the time from Indigo, which is not necessary.

For general Python docs, you want https://docs.python.org/2/

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

Posted on
Wed Feb 24, 2016 11:01 am
jay (support) offline
Site Admin
User avatar
Posts: 18200
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Indigo – Python documentation

In fact, the indigo.server.getTime() method returns a standard Python datetime object - so you would use the standard Python datetime module to manipulate it.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Feb 24, 2016 11:18 am
DaveL17 offline
User avatar
Posts: 6744
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Indigo – Python documentation

canalrun wrote:
I'm sure there has got to be a better way to append the date and time to a string. Again, would that actually be part of Python rather than Indigo?

I think that the prevailing opinion when it comes to Python is that there is no "best way" to do anything. Python's favorite things are simplicity and readability. Beyond that, whatever works for you rules the roost (frankly, if you're coding only for yourself, you can effectively do whatever you want.)

In this example, you're dealing with (at least) two different kinds of objects--a string object and a datetime object. You can't combine two different kinds of objects, so you need to do a bit of conversion. In this case, you're converting a datetime object to a string object in order to combine them with your other string objects. There's no "better way" that I know of; just preference.

This would be probably be my preference for readability:
Code: Select all
theDate = "\n" + str(indigo.server.getTime().date())
theTime = "\n" + str(indigo.server.getTime().time())

theBody = u"Indigo Smoke Alarm Trigger %s %s" % (theDate, theTime)

And you could even break it down further:
Code: Select all
theDate = indigo.server.getTime().date()
theDateStr = "\n" + str(theDate)

theTime = indigo.server.getTime().time()
theTimeStr = "\n" + str(theTime)

theBody = u"Indigo Smoke Alarm Trigger %s %s" % (theDateStr, theTimeStr)

There. I've probably confused you more! :D
Dave

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest