Page 1 of 1

GoogleApiClient

Posted: Tuesday 25 December 2018 22:52
by Filip
I am trying to make a plugin to connect to my calendar. I try to import the googleapiclient in my plugin (see extract code below). I don't use any function of the googleapiclient in the code (I only do the import). All works well, no error messages are shown... However, other plugins started up afterwards do NOT start anymore... If I put the line "from googleapiclient import sample_tools" in comments, then all plugins are working fine.
Has somebody already experience with this?

#IMPORTS
import Domoticz
import subprocess
import sys
sys.path.append('/usr/local/lib/python3.5/dist-packages')
from googleapiclient import sample_tools
from datetime import datetime

Re: GoogleApiClient

Posted: Wednesday 26 December 2018 0:02
by zak45
Filip wrote: Tuesday 25 December 2018 22:52 I am trying to make a plugin to connect to my calendar.
Or you can try this :
https://www.domoticz.com/wiki/Plugins/iCal.html

Re: GoogleApiClient

Posted: Wednesday 26 December 2018 0:15
by Filip
Mmmm... not really the intention... I have a python script working with CRON, but wanted to convert to a plugin...
Seems like the plugin system stopped (and heartbeat not called anymore) after the import.
Seems something crashes, but I don't get logs... Already tried the loglevel and debuglevel, but this does not give the right information...

Re: GoogleApiClient

Posted: Sunday 20 January 2019 11:02
by Filip
Finally I have solved it with a dedicated python script called from the plugin (see code below; call to external python script in bold). Not 100% happy seen the python script uses web access and is blocking for the plugin. Would prefer to use the callback mechanism of the plugin.
If somebody has still an idea how to import the GoogleApiClient in the plugin, don't hesitate.

def onHeartbeat(self):
Domoticz.Debug("onHeartbeat called")
if self.run:
self.runAgain -= 1
if self.runAgain <= 0:

# Start the command to read the Google Calendar
Domoticz.Debug("Start ")
command = "python /home/pi/domoticz/plugins/GoogleCalendar/google-calendar.py '%s' '%s'" % (self.name, self.location)
response = subprocess.check_output(command, shell=True)
response = response.decode('utf-8')
Domoticz.Debug(response)
if 'Enter verification code' in response:
http = response[response.find('http'):response.find('Enter')-2]
Domoticz.Error('The credentials have been revoked or expired, please re-run the application to re-authorize.')
Domoticz.Error('Go to \'%s\' and copy the authorisation code in the hardware setup of the GoogleCalendar.' % http)
auth_code = u'%s' % Parameters["Mode4"]
subprocess.run(command, shell=True, universal_newlines=True, input=auth_code)
elif 'ERROR' in response:
Domoticz.Error(response)
else:
events = response.splitlines()
Domoticz.Debug(str(len(events)))
if len(events) > 0:
data = events[0].split('--')
UpdateDevice(_UNIT_APPOINTMENT, nValue=1, sValue='%s: %s\n%s'%(data[0].replace("T", " "), data[1], data[2]), AlwaysUpdate=False)
UpdateDevice(_UNIT_TIMELEFT, nValue=int(data[3])*24+int(data[4]), sValue=str(int(data[3])*24+int(data[4])), AlwaysUpdate=False)
else:
UpdateDevice(_UNIT_APPOINTMENT, nValue=0, sValue='(NONE)\n', AlwaysUpdate=False)
UpdateDevice(_UNIT_TIMELEFT, nValue=0, sValue=0, AlwaysUpdate=False)

# Run again following the period in the settings
self.runAgain = _MINUTE*int(Parameters["Mode3"])
else:
Domoticz.Debug("onHeartbeat called, run again in "+str(self.runAgain)+" heartbeats.")