Cynical Calendars - Trigger Indigo activity from iCal events

Posted on
Tue Jul 30, 2013 5:30 pm
Dewster35 offline
Posts: 1030
Joined: Jul 06, 2010
Location: Petoskey, MI

Re: Cynical Calendars - Trigger Indigo activity from iCal ev

Perry The Cynic wrote:
Dewster35 wrote:
Perhaps I'm thinking too narrow mindedly, but wouldn't you want the event end and event deleted to have the same function? I get that ical probably calls out these two things differently, but I would think... assume :/ that most people have an event start something and an event switch something back? And they would want the trigger to change it back to be the same whether it ended naturally or if it ended by someone deleting it? Same thing goes for the start of an event or a new event that is occurring now.

Roughly, Calendar Event events report time passing, while Calendar Change events report editing of the calendar itself. They are very different things. Consider the case of a repeating event. Ending it means the current instance has ended. Deleting it means they're all disappearing and the event will never happen again.

I agree that deletion of an active event should signal termination as if a currently active event had ended. I can do that fairly straight-forwardly. But that's not the whole answer. What should happen if the calendar event gets edited and moved away from now? What should happen if a new calendar event is created straddling the current time? For that matter, what should happen for multiple overlapping calendar events that happen to both match your criterion? Some responsibility, in general, will have to lie with the user... which is why they are two different events, one specifically reporting editing activity.

Cheers
-- perry


All good points... understood. I figured I was just looking at it too narrow mindedly.

I guess I was speaking more to the deletion of the event signaling the same as an event had ended naturally. I would also say that if a new event is created straddling the current time that it should treat the moment the new event is created as a start time... but perhaps that is just me in my use.

I agree that there does need to be multiple types... I guess I just think some bits in the second type are the same as the first and should perhaps trigger as such? Giving the flexibility to the user to do anything they would like also keyholes me to cover myself with double the amount of triggers in case those two events above occur. That that I'm averse to triggers, a quick look shows I've got 559 of them, but I do try to be efficient whenever possible.

Posted on
Tue Jul 30, 2013 6:06 pm
Perry The Cynic offline
Posts: 836
Joined: Apr 07, 2008

Re: Cynical Calendars - Trigger Indigo activity from iCal ev

Dewster35 wrote:
I guess I was speaking more to the deletion of the event signaling the same as an event had ended naturally. I would also say that if a new event is created straddling the current time that it should treat the moment the new event is created as a start time... but perhaps that is just me in my use.

Your point is well taken, and I'll try to cover the more common case of creation and deletion at least. It's not quite as easy as it sounds...
... That that I'm averse to triggers, a quick look shows I've got 559 of them, but I do try to be efficient whenever possible

Out of curiosity, how many of those could reasonable be described as linking a button to some device? I've got a plugin in the oven for that...

Cheers
-- perry

Posted on
Tue Jul 30, 2013 7:07 pm
Dewster35 offline
Posts: 1030
Joined: Jul 06, 2010
Location: Petoskey, MI

Re: Cynical Calendars - Trigger Indigo activity from iCal ev

Perry The Cynic wrote:
Dewster35 wrote:
I guess I was speaking more to the deletion of the event signaling the same as an event had ended naturally. I would also say that if a new event is created straddling the current time that it should treat the moment the new event is created as a start time... but perhaps that is just me in my use.

Your point is well taken, and I'll try to cover the more common case of creation and deletion at least. It's not quite as easy as it sounds...
... That that I'm averse to triggers, a quick look shows I've got 559 of them, but I do try to be efficient whenever possible

Out of curiosity, how many of those could reasonable be described as linking a button to some device? I've got a plugin in the oven for that...

Cheers
-- perry


Didn't think it was easy... just thought it was cumbersome the way it was ;)

Hundreds of triggers like that if I am understanding your definition of a "device" as something with a state.

Update: A quick look shows I've got 50 triggers for just music related things that are related to whether an audio zone is active or the server is playing music or not. These are relayed to KPL scene buttons and can also be controlled from those buttons if that help to paint a picture.

Posted on
Tue Jul 30, 2013 8:54 pm
ckeyes888 offline
Posts: 2417
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Cynical Calendars - Trigger Indigo activity from iCal ev

Thanks for the info and updated plugin Perry. No more errors :-)
I've been using an AS to populate a variable from current date events
and was curious if that would be possible using the plugin?

Also I'm gathering it's not possible to enter new Calendar events in any way?

Thanks,

Carl

Posted on
Tue Jul 30, 2013 9:11 pm
Perry The Cynic offline
Posts: 836
Joined: Apr 07, 2008

Re: Cynical Calendars - Trigger Indigo activity from iCal ev

ckeyes888 wrote:
Thanks for the info and updated plugin Perry. No more errors :-)
I've been using an AS to populate a variable from current date events
and was curious if that would be possible using the plugin?

You certainly can populate an Indigo variable from current events through Python (I showed that earlier in this thread, I think).

If you want to run AppleScripts, you'll have to relay through variables and trigger actions. Though I generally recommend getting away from AS these days. Python is not that scary...

Also I'm gathering it's not possible to enter new Calendar events in any way?

Not currently. The underlying Python machinery knows how; I just haven't found a way to express that through a plugin action without it getting implausibly obtuse. Sadly, there's no way to pass dictionaries or even arrays to actions, other than through Python code. (There's a way, but it would take some Pythonic mongering that isn't documented.)

Of course, any other way to create a calendar event would work fine, and the plugin would automatically pick up the change and react to it. You could even do it through AppleScript, I suppose. :-)

Cheers
-- perry

Posted on
Wed Jul 31, 2013 12:09 pm
macpro offline
User avatar
Posts: 765
Joined: Dec 29, 2005
Location: Third byte on the right

Re: Cynical Calendars - Trigger Indigo activity from iCal ev

Perry The Cynic wrote:
Those of you who want your calendar events to have access to the various fields of the event, here's a hint: If you check the Execute event notes as a Python script checkbox for a calendar event, anything you enter into the Notes part of a calendar event will be, well, executed as Python code. This is cool because inside that script, you have a variable called event that is the calendar event that triggered the Indigo event, and it has a bunch of useful attributes. In particular, the title, location, and calendar can be directly accessed:
Code: Select all
log("Event", event.title, "at", event.location, "in", event.calendar.title, "type", event.type)

Depending on your needs, you can use Python code in the Notes to directly tell Indigo to do stuff, or set Indigo variables as needed to trigger further actions:
Code: Select all
indigo.variables.updateValue("CurrentTitle", event.title)

These days, I like this better than directly setting Indigo variables from plugin event triggers because that's inherently racy - I have no way to keep multiple events firing simultaneously from stomping on each other's variable settings.

Let me know if I need to elaborate on this...

I do like the posibility of getting access to the iCall data. But the drawback of the Notes approach is that I need to put Python code into every iCal even that needs to be processed by CynCal.
That's why I modified your plugin to put the data into Indigo Variables. A quick & dirty solution that works, but definitely has it own drawbacks.

But here's another option: I have some AppleScript scripts that respond to Indigo events. Like the Security script.
It starts with this piece of code:
Code: Select all
using terms from application "IndigoServer"
   on receive security event of eventType with code devID
      bla bla bla
   end receive security event
end using terms from


Could it be possible in some way to let CynCal do the same?
Something like
Code: Select all
using terms from application "IndigoServer"
   on receive cynical_calendar event of eventType with title ccTitle, notes ccNotes, location ccLocation
      bla bla bla
   end receive cynical_calendar event
end using terms from

Posted on
Wed Jul 31, 2013 1:24 pm
Perry The Cynic offline
Posts: 836
Joined: Apr 07, 2008

Re: Cynical Calendars - Trigger Indigo activity from iCal ev

I do like the posibility of getting access to the iCall data. But the drawback of the Notes approach is that I need to put Python code into every iCal even that needs to be processed by CynCal.

We're running into a limitation of the Indigo plugin model here. There is no way to pass Python data from a trigger to an action attached to the trigger. It all has to pass through Indigo variables, with all the attendant problems. On the other hand, Python code directly attached to the trigger can be written to have direct access to the trigger data.

I could give the trigger a "put your script right here" field (instead of using the Calendar event Notes field), but the Indigo ConfigUI facility does not allow for multi-line editing fields, and thus it's very, very inconvenient to enter script text into such a field. (Essentially you must write it in a text editor and then paste it into the field, which shows only the first line.) Would you put up with this?

(Yes, I'm using the Notes field essentially because it's better at editing script text than Indigo's own UI. Sad, I know.)
on receive cynical_calendar event of eventType with title ccTitle, notes ccNotes, location ccLocation

I know of no way to invoke Applescript attached scripts from a plugin. I think the Indigo folks pretty much think of plugins as Python creatures, and don't want to entangle it with Applescript lore... not that I blame them for that.

Cheers
-- perry

Posted on
Wed Aug 07, 2013 6:10 am
Dewster35 offline
Posts: 1030
Joined: Jul 06, 2010
Location: Petoskey, MI

Re: Cynical Calendars - Trigger Indigo activity from iCal ev

This morning, I got this error message and the trigger never worked. Is it something I'm doing or something with the plugin? If you want more specific details on the trigger, let me know.


Cynical Calendars Error in runConcurrentThread: Traceback (most recent call last):
File ".../Server Plugin/cyin/debugging.py", line 46, in diagnostic_log
yield
File ".../Server Plugin/cyin/debugging.py", line 56, in diagnose_call
return method(*args, **kwargs)
File ".../Server Plugin/cyin/asynplugin.py", line 52, in runConcurrentThread
self.run()
File ".../Server Plugin/asyn/inject.py", line 49, in run
asyn.Controller.run(self)
File ".../Server Plugin/asyn/controller.py", line 91, in run
item._can_read()
File ".../Server Plugin/asyn/selectable.py", line 212, in _can_read
self._scan(input)
File ".../Server Plugin/asyn/scan.py", line 53, in _scan
result = self.scan.scan(self._rbuf, self.callout)
File ".../Server Plugin/asyn/scan.py", line 108, in scan
callout(ctx, *m.groups())
File ".../Server Plugin/asyn/core.py", line 140, in callout
results = [cb(ctx, *args) for cb in list(self._callbacks)] # latch callback list
File ".../Server Plugin/asyn/dsmonitor.py", line 80, in _event
self.callout(asyn.Context('notify', time=when), name, data)
File ".../Server Plugin/asyn/core.py", line 140, in callout
results = [cb(ctx, *args) for cb in list(self._callbacks)] # latch callback list
File ".../Server Plugin/ical/proc.py", line 83, in _core_event
self._notify_event(*it)
File ".../Server Plugin/ical/proc.py", line 97, in _notify_event
self.pre_update((removed_uids, inserted_uids, changed_uids))
File ".../Server Plugin/ical/proc.py", line 151, in pre_update
super(Monitor, self).pre_update(changes)
File ".../Server Plugin/ical/proc.py", line 213, in pre_update
self._drain()
File ".../Server Plugin/ical/proc.py", line 223, in _drain
self.callout('event', moment)
File ".../Server Plugin/asyn/core.py", line 140, in callout
results = [cb(ctx, *args) for cb in list(self._callbacks)] # latch callback list
File "plugin.py", line 163, in _calev
CalEvent.trigger(data)
File ".../Server Plugin/cyin/iom.py", line 540, in trigger
for event in cls.all_matching(*args, **kwargs):
File ".../Server Plugin/cyin/iom.py", line 534, in all_matching
if event.matches(*args, **kwargs):
File "plugin.py", line 67, in matches
if not self.match(moment):
File "plugin.py", line 45, in match
if self.re_title and not self.re_title.search(ev.title):
File ".../Server Plugin/cyin/attr.py", line 250, in __get__
obj._cached[self] = (calc(obj), obj._config_level)
File ".../Server Plugin/cyin/attr.py", line 267, in fetch
return func(value) if value else value
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/re.py", line 188, in compile
return _compile(pattern, flags)
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/re.py", line 241, in _compile
raise error, v # invalid expression
error: nothing to repeat

Cynical Calendars Error plugin runConcurrentThread function returned or failed (will attempt again in 10 seconds)

Posted on
Wed Aug 07, 2013 9:11 am
Perry The Cynic offline
Posts: 836
Joined: Apr 07, 2008

Re: Cynical Calendars - Trigger Indigo activity from iCal ev

error: nothing to repeat

You have a malformed regular expression - you're using the repetition operators * or + or {} following something that can't be repeated. If you're used to shell globs, note that "any number of characters" in a regex is .*, with a dot ("any one character") preceding the * (any number of the previous thing).

Let me know what regular expressions you've entered into which fields. You should be getting a reasonable complaint, not a dump like this, so I'd like to reproduce this so I can improve it.

Cheers
-- perry

Posted on
Wed Aug 07, 2013 9:22 am
Dewster35 offline
Posts: 1030
Joined: Jul 06, 2010
Location: Petoskey, MI

Re: Cynical Calendars - Trigger Indigo activity from iCal ev

Screen shots of the ical event and the indigo trigger. I would think this is pretty straightforward?

Strange also... this happened nearly 25 minutes AFTER the event started. Time stamp and first line of error that I posted above listed below.

Aug 7, 2013 7:54:19 AM
Trigger Norah Away for Daycare
Attachments
Trigger.tiff
Trigger.tiff (142.54 KiB) Viewed 4017 times
ical.tiff
ical.tiff (6.02 KiB) Viewed 4017 times

Posted on
Wed Aug 07, 2013 9:55 am
Perry The Cynic offline
Posts: 836
Joined: Apr 07, 2008

Re: Cynical Calendars - Trigger Indigo activity from iCal ev

Dewster35 wrote:
Screen shots of the ical event and the indigo trigger. I would think this is pretty straightforward?

Indeed, not a funny character in (plain) sight. I have no idea what's happening there; the Python regex layer complains about the title field, which looks perfectly fine. Try to re-enter the title (you just might have an invisible character in there).
Strange also... this happened nearly 25 minutes AFTER the event started. Time stamp and first line of error that I posted above listed below.

The regex will be evaluated every time an event starts or ends. The code is supposed to cache the expression until it gets changed (via the event's ConfigUI), so it looks like the code thinks you changed the title somehow...

Cheers
-- perry

Posted on
Wed Aug 07, 2013 10:55 am
Dewster35 offline
Posts: 1030
Joined: Jul 06, 2010
Location: Petoskey, MI

Re: Cynical Calendars - Trigger Indigo activity from iCal ev

Perry The Cynic wrote:
Dewster35 wrote:
Screen shots of the ical event and the indigo trigger. I would think this is pretty straightforward?

Indeed, not a funny character in (plain) sight. I have no idea what's happening there; the Python regex layer complains about the title field, which looks perfectly fine. Try to re-enter the title (you just might have an invisible character in there).
Strange also... this happened nearly 25 minutes AFTER the event started. Time stamp and first line of error that I posted above listed below.

The regex will be evaluated every time an event starts or ends. The code is supposed to cache the expression until it gets changed (via the event's ConfigUI), so it looks like the code thinks you changed the title somehow...

Cheers
-- perry


Could the invisible character be in the indigo trigger, the calendar or both?

Posted on
Wed Aug 07, 2013 11:30 am
Perry The Cynic offline
Posts: 836
Joined: Apr 07, 2008

Re: Cynical Calendars - Trigger Indigo activity from iCal ev

Could the invisible character be in the indigo trigger, the calendar or both?

From the traceback you posted, it seems specific to the Title field of the trigger. The code flow basically says, "I'll need to match the trigger title field against this calendar event that just happened. Oh look, the event title field seems to have changed since I last used it, so let's recompile that regular expression. Oops, there's a (regex) syntax error in there..." It doesn't look like the problem has anything to do with your calendar.

Cheers
-- perry

Posted on
Wed Aug 07, 2013 11:38 am
Dewster35 offline
Posts: 1030
Joined: Jul 06, 2010
Location: Petoskey, MI

Re: Cynical Calendars - Trigger Indigo activity from iCal ev

Perry The Cynic wrote:
Could the invisible character be in the indigo trigger, the calendar or both?

From the traceback you posted, it seems specific to the Title field of the trigger. The code flow basically says, "I'll need to match the trigger title field against this calendar event that just happened. Oh look, the event title field seems to have changed since I last used it, so let's recompile that regular expression. Oops, there's a (regex) syntax error in there..." It doesn't look like the problem has anything to do with your calendar.

Cheers
-- perry

OK

Retyped both triggers so I'll let you know if I see the error again.

Posted on
Wed Aug 07, 2013 1:42 pm
Dewster35 offline
Posts: 1030
Joined: Jul 06, 2010
Location: Petoskey, MI

Re: Cynical Calendars - Trigger Indigo activity from iCal ev

Upon the event ending, I get the following error message in the event log.


Cynical Calendars Error in runConcurrentThread: Traceback (most recent call last):
File ".../Server Plugin/cyin/debugging.py", line 46, in diagnostic_log
yield
File ".../Server Plugin/cyin/debugging.py", line 56, in diagnose_call
return method(*args, **kwargs)
File ".../Server Plugin/cyin/asynplugin.py", line 52, in runConcurrentThread
self.run()
File ".../Server Plugin/asyn/inject.py", line 49, in run
asyn.Controller.run(self)
File ".../Server Plugin/asyn/controller.py", line 95, in run
self._dispatch()
File ".../Server Plugin/asyn/controller.py", line 227, in _dispatch
top.callout(Ctx('TIMER', sched=top, control=self, when=top.when, now=now))
File ".../Server Plugin/asyn/core.py", line 140, in callout
results = [cb(ctx, *args) for cb in list(self._callbacks)] # latch callback list
File ".../Server Plugin/ical/proc.py", line 206, in _timer_event
self._drain()
File ".../Server Plugin/ical/proc.py", line 223, in _drain
self.callout('event', moment)
File ".../Server Plugin/asyn/core.py", line 140, in callout
results = [cb(ctx, *args) for cb in list(self._callbacks)] # latch callback list
File "plugin.py", line 163, in _calev
CalEvent.trigger(data)
File ".../Server Plugin/cyin/iom.py", line 540, in trigger
for event in cls.all_matching(*args, **kwargs):
File ".../Server Plugin/cyin/iom.py", line 534, in all_matching
if event.matches(*args, **kwargs):
File "plugin.py", line 67, in matches
if not self.match(moment):
File "plugin.py", line 45, in match
if self.re_title and not self.re_title.search(ev.title):
File ".../Server Plugin/cyin/attr.py", line 250, in __get__
obj._cached[self] = (calc(obj), obj._config_level)
File ".../Server Plugin/cyin/attr.py", line 267, in fetch
return func(value) if value else value
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/re.py", line 188, in compile
return _compile(pattern, flags)
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/re.py", line 241, in _compile
raise error, v # invalid expression
error: nothing to repeat

Cynical Calendars Error plugin runConcurrentThread function returned or failed (will attempt again in 10 seconds)

Who is online

Users browsing this forum: No registered users and 4 guests