KenV99 / script.service.kodi.callbacks

Callbacks for Kodi Helix or later
Other
14 stars 20 forks source link

Add Return From Idle Event #1

Closed simonbuehler closed 8 years ago

simonbuehler commented 8 years ago

hi,

it would be very useful to have a event when idle state is left (e.g: GlobalIdletime < 5 when idle state is true)

KenV99 commented 8 years ago

I can implement an event to five once an idle of > x secs occurs and then idle ends. Is this what you mean?

I am asking to be sure because the way the addon tracks idle time and Kodi's globalidletime are not the same. Kodi's Global idle time includes time when the player is playing audio or video, while this addon only counts idle time when there is no user input AND the player is not playing.

simonbuehler commented 8 years ago

yes thats what i mean: an event when user input or playing anything cancles idle. i think the addon defines idle time in the correct way: no activity at all. so global idle time can be ignored imo

KenV99 commented 8 years ago

OK, I just pushed an update with an event 'on Resume after Idle'. Please download and let me know if it's working as you expect.

simonbuehler commented 8 years ago

think the debug flags was left on ...# changed it but got

ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
                                             - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
                                            Error Type: <type 'exceptions.TypeError'>
                                            Error Contents: not all arguments converted during string formatting
                                            Traceback (most recent call last):
                                              File "/home/kodi/.kodi/addons/service.kodi.callbacks/default.py", line 314, in <module>
                                                main()
                                              File "/home/kodi/.kodi/addons/service.kodi.callbacks/default.py", line 196, in main
                                                xbmc.log(msg=_('$$$ [kodi.callbacks] Staring kodi.callbacks ver: %s') % str(xbmcaddon.Addon().getAddonInfo('version')), level=xbmc.LOGNOTICE)
                                            TypeError: not all arguments converted during string formatting
                                            -->End of Python script error report<--
KenV99 commented 8 years ago

Damn. Bane of my existence. I pushed a fix for the debug. Will look into the other error.

simonbuehler commented 8 years ago

ok now i could test the event but it triggers repeatedly , also shutdown is triggered when there was no shutdown at all:

17:36:35 T:140203538654976  NOTICE: $$$ [kodi.callbacks] - Command for Task T1, Event afterIdle:E2 completed succesfully!
17:36:35 T:140203521345280 WARNING: CPythonInvoker(9): Script invoked without an addon. Adding all addon modules installed to python path as fallback. This behaviour will be removed in future version.
17:36:38 T:140203538654976  NOTICE: $$$ [kodi.callbacks] - Command for Task T1, Event afterIdle:E2 completed succesfully!
17:36:38 T:140203521345280 WARNING: CPythonInvoker(10): Script invoked without an addon. Adding all addon modules installed to python path as fallback. This behaviour will be removed in future version.
17:36:39 T:140203538654976  NOTICE: $$$ [kodi.callbacks] - Command for Task T1, Event afterIdle:E2 completed succesfully!
17:36:39 T:140203521345280 WARNING: CPythonInvoker(11): Script invoked without an addon. Adding all addon modules installed to python path as fallback. This behaviour will be removed in future version.
17:36:42 T:140205004662528  NOTICE: $$$ [kodi.callbacks] - Shutdown started
17:36:43 T:140205004662528  NOTICE: $$$ [kodi.callbacks] - Shutdown complete
17:36:52 T:140205711648704  NOTICE: PVRManager - ResetDatabase - clearing the PVR database
17:36:52 T:140205711648704  NOTICE: PVRManager - stopping
KenV99 commented 8 years ago

Hmmm. I am not having that happen on my end. It is only triggering once and only after it has entered idle and not shutting down. There is not code to trigger a shutdown directly in the addon. Can you turn on debug and replicate the conditions and post a full log to pastebin and post the link here? Also if you can put a copy of your settings.xml from the userdata/addon_data/service.kodi.callbacks up on pastebin as well?

simonbuehler commented 8 years ago

ok herethe reöevant a part of the huge (epg updates due to pvrStart/stop on idle/leave) debug log http://pastebin.com/eGMqevih

settings xml : http://pastebin.com/avAnmCw1 you can see that the return from idle command is executed twice after 2 seconds or so

KenV99 commented 8 years ago

I really need the whole log. The addon initialization routine when the addon starts is missing and I'd like to get more info about your system that is listed at the very top of the log.

I did extensive testing on my Windows system a few hours ago and it all seems to work as intended. So I need info like what OS you are on.

You realize you have the afterIdle time set to 1 second right? So if you don't do anything for one second, the program thinks it's in idle and then as soon as you move the cursor, press a button, etc, it fires an afterIdle event.

KenV99 commented 8 years ago

The onIdle event and afterIdle events are completely independent of each other and have separate timers. So I think what you really want is an onIdle event to occur after x seconds and then only fire an afterIdle event after x+1 seconds.

simonbuehler commented 8 years ago

Ok this explains the bahaviour - the afterIdle should be no Timer that triggers X Seconds after entering Idle but trigger when the Idle State is left by either user activity or a playback starting (plus optionally wait X seconds). A working (but limited to idle/leaveIdle events) addon is https://github.com/4lb3rtO/service.idle.actions maybe you can have a look there

KenV99 commented 8 years ago

The architecture in your link is not compatible with Kodi Callbacks architecture of having multiple independent events and tasks. It would require setting one global idle time for all events.

The architecture currently in use provides additional flexibility not available in the linked addon. For instance in Kodi Callbacks, a user could configure a task, such as dimming the lights to occur after 10 minutes of idle. And then after 30 minutes of idle to turn the lights off and turn off an amplifier and display. With the addition of the afterIdle event, the user could configure the lights to come back on if there is user input after 10m 1s. And also configure to turn on the amplifier and display after 30m 1s if there is user activity.

Are you not able to achieve what you want by setting your onIdle event to occur at 300 secs (as found in your settings.xml) and then set your afterIdle event to occur after user input at 301 secs?

simonbuehler commented 8 years ago

ok, i'll try it out if it works this way, setting the afterIdle time to idletime + x . This should be really noticed in the docs as probably most people think afterIdle starts wheneever user activity appears after kodi went into Idle state.

Maybe a good idea is to make sure users can't enter a afteridletime < idletime ?

KenV99 commented 8 years ago

I'll edit the wiki.

Again, since the timers are completely independent, users can create an afterIdle event that has no associated onIdle event. This is the desired behavior IMHO. Having one depend on the other creates inter dependency which I want to avoid. And since there can be multiple onIdle events set with different definitions of what the idle time is, having afterIdle events linked to them creates unneeded complexity and limits flexibility.

simonbuehler commented 8 years ago

ok, works for me, thanks for the clarification!