Google Calendar custom widget

you didnt need httplib2 and oauth2client, because they are part of the google-api-client.
adding those could lead to incompatible versions.

and i am not sure that a path like that would work.
i always use full path.
the app is in apps so a partial path would be just / i guess.

Error log is empty. So i guess apps work ok ?

2018-06-03 23:50:59.536192 INFO AppDaemon Version 3.0.1 starting
2018-06-03 23:50:59.537314 INFO Configuration read from: /home/homeassistant/.homeassistant/appdaemon/appdaemon.yaml
2018-06-03 23:50:59.542848 INFO AppDaemon: Starting Apps
2018-06-03 23:50:59.545085 WARNING config_dir: /home exists, but is not writeable, owner: root
2018-06-03 23:50:59.553854 INFO AppDaemon: Loading Plugin HASS using class HassPlugin from module hassplugin
2018-06-03 23:50:59.592000 INFO AppDaemon: HASS: HASS Plugin Initializing
2018-06-03 23:50:59.593589 INFO AppDaemon: HASS: HASS Plugin initialization complete
2018-06-03 23:50:59.594912 INFO Starting Dashboards
2018-06-03 23:50:59.598679 WARNING css: /home exists, but is not writeable, owner: root
2018-06-03 23:50:59.602232 WARNING javascript: /home exists, but is not writeable, owner: root
2018-06-03 23:50:59.616618 INFO API is disabled
2018-06-03 23:50:59.633306 INFO AppDaemon: HASS: Connected to Home Assistant 0.70.0
2018-06-03 23:50:59.683066 INFO AppDaemon: Got initial state from namespace default
2018-06-03 23:51:01.851362 INFO AppDaemon: Reading config
2018-06-03 23:51:01.858667 INFO AppDaemon: /home/homeassistant/.homeassistant/appdaemon/apps/test.yaml added or modified
2018-06-03 23:51:01.859335 INFO AppDaemon: /home/homeassistant/.homeassistant/appdaemon/apps/test.yaml added or modified
2018-06-03 23:51:01.859880 INFO AppDaemon: App 'test' added
2018-06-03 23:51:01.860637 INFO AppDaemon: Adding /home/homeassistant/.homeassistant/appdaemon/apps to module import path
2018-06-03 23:51:01.861737 INFO AppDaemon: Loading App Module: /home/homeassistant/.homeassistant/appdaemon/apps/test.py
2018-06-03 23:51:01.884947 INFO AppDaemon: Initializing app test using class test from module test
2018-06-03 23:51:02.090036 INFO test: test app initialised ok
2018-06-03 23:51:02.092013 INFO AppDaemon: App initialization complete

appdaemon.yaml is as follows,

log:
  logfile: /home/homeassistant/.homeassistant/appdaemon/log.log
  errorfile: /home/homeassistant/.homeassistant/appdaemon/error.log
appdaemon:
  disable_apps: 0
  threads: 10
  app_dir: /home/homeassistant/.homeassistant/appdaemon/apps
  plugins:
    HASS:
      type: hass
      ha_url: http://192.168.1.13:8123
      ha_key: 
hadashboard:
  dash_compile_on_start: 1
  dash_url: http://192.168.1.13:5050
  dash_dir: /home/homeassistant/.homeassistant/appdaemon/dashboards

oke, at least we are sure that AD is working oke.
did you create custom_css in your appdaemon dir?
and a subdir html?

and then you need to set:

  htmlfile: /home/homeassistant/.homeassistant/appdaemon/custom_css/html/google-calendar-app/calendar.html                                # the file that you show in the dashboard

in the calendar.yaml

and you did

pip3 install google-api-python-client

in the same environment that you run appdaemon in?
and that gave no errors?

edit: and you can leave the test app when you place the 2 files in again.

I hadn’t done this, no, but I did just now, but it didn’t make any difference, still same error about formatyear

Installing collected packages: cachetools, six, pyasn1, rsa, pyasn1-modules, google-auth, uritemplate, httplib2, google-auth-httplib2, google-api-python-client
Successfully installed cachetools-2.1.0 google-api-python-client-1.7.1 google-auth-1.5.0 google-auth-httplib2-0.0.3 httplib2-0.11.3 pyasn1-0.4.3 pyasn1-modules-0.2.1 rsa-3.4.2 six-1.11.0 uritemplate-3.0.0

Yup, seemed to install all ok.

Just still the same,

2018-06-04 00:10:34.925390 WARNING AppDaemon: ------------------------------------------------------------
2018-06-04 00:13:34.821315 WARNING AppDaemon: ------------------------------------------------------------
2018-06-04 00:13:34.822580 WARNING AppDaemon: Unexpected error initializing app: hoofdagenda:
2018-06-04 00:13:34.823876 WARNING AppDaemon: ------------------------------------------------------------
2018-06-04 00:13:34.825892 WARNING AppDaemon: Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/appdaemon/appdaemon.py", line 2040, in check_app_updates
    self.init_object(app)
  File "/usr/local/lib/python3.5/dist-packages/appdaemon/appdaemon.py", line 1565, in init_object
    self, name, self.logger, self.error, app_args, self.config, self.app_config, self.global_vars
TypeError: formatyear() takes from 2 to 6 positional arguments but 9 were given

2018-06-04 00:13:34.828310 WARNING AppDaemon: ------------------------------------------------------------

this really bugs me.
i can nowhere find any formatyear() in AD or in google client.

because i get no debug info at all i need to conclude that the error comes from the first part from the app somehow.

please delete these 2 files and edit test.py to

from __future__ import print_function
import httplib2
import os

from apiclient import discovery
from oauth2client import client
from oauth2client import tools
from oauth2client.file import Storage

import appdaemon.plugins.hass.hassapi as hass
import datetime
import time

class test(hass.Hass):


  def initialize(self):
    self.log("imports dont give the error")
    runtime = datetime.datetime.now() + datetime.timedelta(seconds=5)
    self.log("datetime does also not give an error")

and sorry that this is getting way more difficult and annoying then i expected it to be.

edit: please restart AD after that with clear logs.

Log File:

2018-06-04 00:46:04.597988 INFO AppDaemon Version 3.0.1 starting
2018-06-04 00:46:04.599059 INFO Configuration read from: /home/homeassistant/.homeassistant/appdaemon/appdaemon.yaml
2018-06-04 00:46:04.604615 INFO AppDaemon: Starting Apps
2018-06-04 00:46:04.606798 WARNING config_dir: /home exists, but is not writeable, owner: root
2018-06-04 00:46:04.615694 INFO AppDaemon: Loading Plugin HASS using class HassPlugin from module hassplugin
2018-06-04 00:46:04.654375 INFO AppDaemon: HASS: HASS Plugin Initializing
2018-06-04 00:46:04.655810 INFO AppDaemon: HASS: HASS Plugin initialization complete
2018-06-04 00:46:04.657075 INFO Starting Dashboards
2018-06-04 00:46:04.660863 WARNING css: /home exists, but is not writeable, owner: root
2018-06-04 00:46:04.664420 WARNING javascript: /home exists, but is not writeable, owner: root
2018-06-04 00:46:04.679452 INFO API is disabled
2018-06-04 00:46:04.696165 INFO AppDaemon: HASS: Connected to Home Assistant 0.70.0
2018-06-04 00:46:04.742513 INFO AppDaemon: Got initial state from namespace default
2018-06-04 00:46:06.898522 INFO AppDaemon: Reading config
2018-06-04 00:46:06.905667 INFO AppDaemon: /home/homeassistant/.homeassistant/appdaemon/apps/test.yaml added or modified
2018-06-04 00:46:06.906334 INFO AppDaemon: /home/homeassistant/.homeassistant/appdaemon/apps/test.yaml added or modified
2018-06-04 00:46:06.906857 INFO AppDaemon: App 'test' added
2018-06-04 00:46:06.907542 INFO AppDaemon: Adding /home/homeassistant/.homeassistant/appdaemon/apps to module import path
2018-06-04 00:46:06.908611 INFO AppDaemon: Loading App Module: /home/homeassistant/.homeassistant/appdaemon/apps/test.py
2018-06-04 00:46:06.948452 WARNING AppDaemon: Removing associated apps:
2018-06-04 00:46:06.948948 WARNING AppDaemon: test
2018-06-04 00:46:06.950882 INFO AppDaemon: App initialization complete

Error File:

2018-06-04 00:46:06.940627 WARNING AppDaemon: ------------------------------------------------------------
2018-06-04 00:46:06.941329 WARNING AppDaemon: Unexpected error loading module: /home/homeassistant/.homeassistant/appdaemon/apps/test.py:
2018-06-04 00:46:06.941843 WARNING AppDaemon: ------------------------------------------------------------
2018-06-04 00:46:06.947298 WARNING AppDaemon: Traceback (most recent call last):
  File "/home/pi/.local/lib/python3.5/site-packages/apiclient/__init__.py", line 8, in <module>
    import oauth2client
ImportError: No module named 'oauth2client'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/appdaemon/appdaemon.py", line 2015, in check_app_updates
    self.read_app(mod["name"], mod["reload"])
  File "/usr/local/lib/python3.5/dist-packages/appdaemon/appdaemon.py", line 1802, in read_app
    self.modules[module_name] = importlib.import_module(module_name)
  File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 673, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/home/homeassistant/.homeassistant/appdaemon/apps/test.py", line 5, in <module>
    from apiclient import discovery
  File "/home/pi/.local/lib/python3.5/site-packages/apiclient/__init__.py", line 11, in <module>
    'Previous version of google-api-python-client detected; due to a '
RuntimeError: Previous version of google-api-python-client detected; due to a packaging issue, we cannot perform an in-place upgrade. To repair, remove and reinstall this package, along with oauth2client and uritemplate. One can do this with pip via
  pip install -I google-api-python-client

2018-06-04 00:46:06.947944 WARNING AppDaemon: ------------------------------------------------------------

at least we get somewhere.

do you have appdaemon and home assistant in the same environment installed or is appdaemon in a seperate venv?

so I did

pip3 install oauth2client

and then restarted appdaemon, and am now back to the same

2018-06-04 00:48:59.419474 WARNING AppDaemon: ------------------------------------------------------------
2018-06-04 00:48:59.420168 WARNING AppDaemon: Unexpected error initializing app: hoofdagenda:
2018-06-04 00:48:59.420804 WARNING AppDaemon: ------------------------------------------------------------
2018-06-04 00:48:59.421928 WARNING AppDaemon: Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/appdaemon/appdaemon.py", line 2040, in check_app_updates
    self.init_object(app)
  File "/usr/local/lib/python3.5/dist-packages/appdaemon/appdaemon.py", line 1565, in init_object
    self, name, self.logger, self.error, app_args, self.config, self.app_config, self.global_vars
TypeError: formatyear() takes from 2 to 6 positional arguments but 9 were given

2018-06-04 00:48:59.422687 WARNING AppDaemon: ------------------------------------------------------------

Hmmm, this is where I am not sure and linux gets bit above my head. I think they are going to be in different ones. I am running Hassbian install, and then did the appdaemon install as per the docs on the website using

sudo pip3 install --pre appdaemon

logged in as the pi user.

oke i looked at hasbian and it seems they use a venv.
and when you were logged on as pi i guess you didnt install it in the same venv.

the --pre was only needed because of the beta release. but you have the right AD now.
so its probably a problem with google client.

this error:

RuntimeError: Previous version of google-api-python-client detected; due to a packaging issue, we cannot perform an in-place upgrade. To repair, remove and reinstall this package, along with oauth2client and uritemplate. One can do this with pip via
  pip install -I google-api-python-client

so i suggest you run that command (but use pip3 instead of pip.

If I don’t install oauth2client I get the same error as @Cee

2018-06-03 20:45:37.455222 WARNING AppDaemon: ------------------------------------------------------------
2018-06-03 20:45:37.455351 WARNING AppDaemon: Unexpected error loading module: /config/appdaemon/apps/calendar.py:
2018-06-03 20:45:37.455442 WARNING AppDaemon: ------------------------------------------------------------
2018-06-03 20:45:37.456073 WARNING AppDaemon: Traceback (most recent call last):
File “/usr/lib/python3.6/site-packages/apiclient/init.py”, line 8, in
import oauth2client
ModuleNotFoundError: No module named ‘oauth2client’

Using relative path is ok inside AppDaemon (at least in Addon mode) since all log files appear with relative paths. And also I have other .py with relative paths that work fine

oauthclient should be a part from the package google-api-python-client
i only installed that one.

i hope that you are right about the relative paths. i have no way of testing that here.
but then istill have no clue why you get that other error, other then incompatible parts with google client.

Installing collected packages: httplib2, cachetools, pyasn1, rsa, six, pyasn1-modules, google-auth, google-auth-httplib2, uritemplate, google-api-python-client
Successfully installed cachetools-2.1.0 google-api-python-client-1.7.1 google-auth-1.5.0 google-auth-httplib2-0.0.3 httplib2-0.11.3 pyasn1-0.4.3 pyasn1-modules-0.2.1 rsa-3.4.2 six-1.11.0 uritemplate-3.0.0

But still the same error. I am guessing its something to do with the venv.

I have a synology nas that I have just installed docker on, but I know about as much as using that as using linux :laughing:

hmm, i hacked the connection to google over a year ago.
i had none of this and use it all the time
i had AD without a venv working
and recently i installed AD new into a venv.

i have python 3.6 but that shouldnt be different because i had it running in 3.4 also.

i am going to read on the google developers site what can be the issue.

Maybe your .json has another format and the new ones don’t work with that approach?

i just checked but it seems the same.
i am reading now, but its 3:00 here so i need to move it to tommorow :wink:

I got past the credentials error by not using the path,ie just passing the json file that I have in the same folder :

store = Storage(self.args[“client_secret_file”])

but then I got

2018-06-03 22:40:07.912559 WARNING AppDaemon: Traceback (most recent call last):
File “/usr/lib/python3.6/site-packages/appdaemon/appdaemon.py”, line 1575, in init_object
init()
File “/config/appdaemon/apps/calendar.py”, line 35, in initialize
self.controleer_agenda(self)
File “/config/appdaemon/apps/calendar.py”, line 44, in controleer_agenda
credentials = self.get_credentials()
File “/config/appdaemon/apps/calendar.py”, line 257, in get_credentials
credentials = tools.run_flow(flow, store, flags)
NameError: name ‘flags’ is not defined

so, I searched that and added empty flags:

    flags = tools.argparser.parse_args(args=[])

and now I get:

018-06-03 22:41:03.074904 INFO hoofdagenda: no valid credentials, so get them

Your browser has been opened to visit:

https://accounts.google.com/o/oauth2/auth?client_id=xxxxxxxx.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2F&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcalendar.readonly&access_type=offline&response_type=code

If your browser is on a different machine then exit and re-run this
application with the command-line parameter

–noauth_local_webserver

I open that in the browser authorize HA, but finally it returns to localhost:8080 that doesn’t exist.

Strange thing is that I had already authorized HA to view my calendar when I installed the calendar component directly in HA and that worked.

I am lost with this … see you tomorrow, good night!

thanks for this.
now i know again how i did it in the past.

its a problem with argparser.
the google client api uses that and appdaemon uses it also.
i got around that by adding the line that you also added, but it requires that you use a browser on the device.
and obviously that wont work.
so i need to find a way to startup the app seperatly, when AD is not running, so we can use the noauth_local_webserver option.

i got it working twice now with different files, but i got browser access.
so i will get there. :wink:

1 Like

its not something easy.
i cant find out how to unauthorise my app, so i cant test it.

i found a way to add the noauth arg as a workaround in the hope that works.
in the yaml i added a new_auth argument, that when its set to True tries to get a new authorisation
but it throws an error because of double use from argparser. (that happens when you try to combine 2 programs from other people :wink: )
but when the authorisation is done and you set the new option to False the program wont try to authorise anymore and there is no error.


so to conclude:

load the new files from github (when AD isnt running)
edit the yaml to your need
start AD and keep your fingers crossed. :wink:

1 Like

Still the same error I am afraid :frowning:

2018-06-04 16:43:41.160108 WARNING AppDaemon: ------------------------------------------------------------
2018-06-04 16:43:41.160885 WARNING AppDaemon: Unexpected error initializing app: hoofdagenda:
2018-06-04 16:43:41.161579 WARNING AppDaemon: ------------------------------------------------------------
2018-06-04 16:43:41.165411 WARNING AppDaemon: Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/appdaemon/appdaemon.py", line 2040, in check_app_updates
    self.init_object(app)
  File "/usr/local/lib/python3.5/dist-packages/appdaemon/appdaemon.py", line 1565, in init_object
    self, name, self.logger, self.error, app_args, self.config, self.app_config, self.global_vars
TypeError: formatyear() takes from 2 to 6 positional arguments but 9 were given

2018-06-04 16:43:41.166437 WARNING AppDaemon: ------------------------------------------------------------