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
GoogleApiClient
Moderator: leecollings
-
zak45
- Posts: 954
- Joined: Sunday 22 January 2017 11:37
- Target OS: Windows
- Domoticz version: V2024.4
- Contact:
Re: GoogleApiClient
-
Filip
- Posts: 135
- Joined: Thursday 03 November 2016 10:12
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: GoogleApiClient
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...
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...
-
Filip
- Posts: 135
- Joined: Thursday 03 November 2016 10:12
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: GoogleApiClient
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.")
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.")