Baikal
Baikal copied to clipboard
baikal not working with homeassistant caldav calendar component: unauthorized access etc.
The problem
I can't get my calendar running in home assistant... Works perfect in Thunderbird but not in home assistant.
Environment
Home Assistant Version: 0.115.6 Ubuntu Server 20.04 Linux homeautomation 5.4.0-47-generic #51-Ubuntu SMP Fri Sep 4 19:50:52 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux baikal v. 0.7.1
Problem-relevant configs:
This is my config: part of configuration.yaml:
calendar:
- platform: caldav
username: !secret caldav_user
password: !secret caldav_password
url: http://192.168.10.4:8018/cal.php/calendars/homeassistant/tasks
calendars: tasks
apache config:
<VirtualHost 0.0.0.0:8018>
ServerName baikalserver
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/baikal/html
RewriteEngine on
RewriteRule /.well-known/carddav /dav.php [R=308,L]
RewriteRule /.well-known/caldav /dav.php [R=308,L]
LogLevel info
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory "/var/www/baikal/html">
Options None
AllowOverride None
Require all granted
</Directory>
<IfModule mod_expires.c>
ExpiresActive Off
</IfModule>
</VirtualHost>
baikal config /var/www/html/baikal/config/baikal.yaml:
system:
configured_version: 0.7.1
timezone: Europe/Paris
card_enabled: false
cal_enabled: true
dav_auth_type: Basic
admin_passwordhash: *CUT*
auth_realm: BaikalDAV
base_uri: ''
invite_from: ''
database:
sqlite_file: /var/www/html/baikal/Specific/db/db.sqlite
mysql: true
mysql_host: localhost
mysql_dbname: baikal
mysql_username: baikal
mysql_password: baikal
encryption_key: *CUT*
configured_version: ''
Traceback/Error logs
As stated thunderbird works fine, home assistant tells me:
2020-10-02 19:36:48 ERROR (MainThread) [homeassistant.components.calendar] caldav: Error on device update! Traceback (most recent call last): File "/usr/local/lib/python3.8/dist-packages/homeassistant/helpers/entity_platform.py", line 346, in _async_add_entity await entity.async_device_update(warning=False) File "/usr/local/lib/python3.8/dist-packages/homeassistant/helpers/entity.py", line 471, in async_device_update await self.hass.async_add_executor_job(self.update) # type: ignore File "/usr/lib/python3.8/concurrent/futures/thread.py", line 57, in run result = self.fn(*self.args, **self.kwargs) File "/usr/local/lib/python3.8/dist-packages/homeassistant/components/caldav/calendar.py", line 146, in update self.data.update() File "/usr/local/lib/python3.8/dist-packages/homeassistant/util/init.py", line 239, in wrapper result = method(*args, **kwargs) File "/usr/local/lib/python3.8/dist-packages/homeassistant/components/caldav/calendar.py", line 203, in update results = self.calendar.date_search(start_of_today, start_of_tomorrow) File "/home/homeassistant/.homeassistant/deps/lib/python3.8/site-packages/caldav/objects.py", line 594, in date_search response = self._query(root, 1, 'report') File "/home/homeassistant/.homeassistant/deps/lib/python3.8/site-packages/caldav/objects.py", line 167, in _query raise error.exception_by_methodquery_method caldav.lib.error.ReportError: 500 Internal Server Error
b'\n<d:error xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">\n <s:sabredav-version>4.1.0</s:sabredav-version>\n <s:exception>Sabre\VObject\ParseException</s:exception>\n <s:message>This parser only supports VCARD and VCALENDAR files</s:message>\n</d:error>\n'
and apache2 error and access log tells me this:
==> /var/log/apache2/access.log <== 192.168.10.4 - - [02/Oct/2020:19:51:32 +0200] "PROPFIND /cal.php/calendars/homeassistant/tasks/ HTTP/1.1" 401 1141 "-" "Mozilla/5.0" 192.168.10.4 - homeassistant [02/Oct/2020:19:51:32 +0200] "PROPFIND /cal.php/calendars/homeassistant/tasks/ HTTP/1.1" 207 1098 "-" "Mozilla/5.0" 192.168.10.4 - homeassistant [02/Oct/2020:19:51:32 +0200] "PROPFIND /cal.php/principals/homeassistant/ HTTP/1.1" 207 1086 "-" "Mozilla/5.0" 192.168.10.4 - homeassistant [02/Oct/2020:19:51:32 +0200] "PROPFIND /cal.php/calendars/homeassistant/ HTTP/1.1" 207 2363 "-" "Mozilla/5.0"
==> /var/log/apache2/error.log <==
[Fri Oct 02 19:51:33.785481 2020] [php7:notice] [pid 331104] [client 192.168.10.4:58680] Sabre\VObject\ParseException: This parser only supports VCARD and VCALENDAR files in /var/www/html/baikal/vendor/sabre/vobject/lib/Parser/MimeDir.php:163\nStack trace:\n#0 /var/www/html/baikal/vendor/sabre/vobject/lib/Parser/MimeDir.php(90): Sabre\VObject\Parser\MimeDir->parseDocument()\n#1 /var/www/html/baikal/vendor/sabre/vobject/lib/Reader.php(47): Sabre\VObject\Parser\MimeDir->parse()\n#2 /var/www/html/baikal/vendor/sabre/dav/lib/CalDAV/Plugin.php(513): Sabre\VObject\Reader::read()\n#3 /var/www/html/baikal/vendor/sabre/dav/lib/CalDAV/Plugin.php(258): Sabre\CalDAV\Plugin->calendarQueryReport()\n#4 /var/www/html/baikal/vendor/sabre/event/lib/WildcardEmitterTrait.php(89): Sabre\CalDAV\Plugin->report()\n#5 /var/www/html/baikal/vendor/sabre/dav/lib/DAV/CorePlugin.php(685): Sabre\DAV\Server->emit()\n#6 /var/www/html/baikal/vendor/sabre/event/lib/WildcardEmitterTrait.php(89): Sabre\DAV\CorePlugin->httpReport()\n#7 /var/www/html/baikal/vendor/sabre/dav/lib/DAV/Server.php(470): Sabre\DAV\Server->emit()\n#8 /var/www/html/baikal/vendor/sabre/dav/lib/DAV/Server.php(251): Sabre\DAV\Server->invokeMethod()\n#9 /var/www/html/baikal/vendor/sabre/dav/lib/DAV/Server.php(319): Sabre\DAV\Server->start()\n#10 /var/www/html/baikal/Core/Frameworks/Baikal/Core/Server.php(119): Sabre\DAV\Server->exec()\n#11 /var/www/html/baikal/html/cal.php(74): Baikal\Core\Server->start()\n#12 {main}
and after this:
==> /var/log/apache2/access.log <== 192.168.10.4 - homeassistant [02/Oct/2020:19:51:33 +0200] "REPORT /cal.php/calendars/homeassistant/tasks/ HTTP/1.1" 500 687 "-" "Mozilla/5.0"
First apache gives me a 401 (unauthorized), and later a internal server error 500... baikal seems to work just fine with thunderbird, but not with home assistant...
Additional information
Community Topic: https://community.home-assistant.io/t/correct-config-for-calendar-component-caldac-baikal-apache2/232055 homeassistant core issue: https://github.com/home-assistant/core/issues/41222
Using some of the info found here https://github.com/sabre-io/Baikal/issues/695
Adding the debugging statement to the thrown error in MimeDir.php and did indeed get my designated timezone printed out. Apparently the timezone is being sent instead of the string "BEGIN:VCARD" or "BEGIN:VCALENDAR". I assume this is some old broken behavior in setting up the calendar, sending the TZ instead of the BEGIN statement.
I put a print statement in the python3.8/site-packages/caldav/objects.py just above line 167 and the following XML is triggering this issue:
<?xml version='1.0' encoding='utf-8'?> <C:calendar-query xmlns:D="DAV" xmlns:C="urn:ietf:params:xml:ns:caldav" xmlns:I="http://apple.com/ns/ical/"><ns0:prop xmlns:ns0="DAV:"><C:calendar-data><C:expand start="20210107T080000Z" end="20210114T080000Z"/></C:calendar-data></ns0:prop><C:filter><C:comp-filter name="VCALENDAR"><C:comp-filter name="VEVENT"><C:time-range start="20210107T080000Z" end="20210114T080000Z"/></C:comp-filter></C:comp-filter></C:filter></C:calendar-query>
So it appears that the python caldav request issued by homeassistant are using an iCal namespace and possibly a method that baikal no longer accepts: https://github.com/sabre-io/Baikal/issues/695#issuecomment-309304378 I removed my Baikal calendar and created a new one with a very different TZ than I use and that new TZ appears to be what is requested, not the TZ from homeassistant.
I'll look into it more, since I have to head to my dayjob. Issue 695 above attributes the problem to a bad iCal entry, but this issue might be how homeassistant is using the data it gathers from Baikal to query VEVENTs or it maybe an issue with how caldav/objects.py handles homeassistant's request. Hopefully I'll have time to look at this more later tonight.
@linuxlurak see my "fix" at the end of https://github.com/sabre-io/dav/issues/1318
This is possibly something that should be fixed in the python caldav library?
The problem still exists in HA 2024.3.2.
So it appears that the python caldav request issued by homeassistant are using an iCal namespace
Oh. I've been wondering a bit about that. The link to Apple has been broken probably for a decade, and the namespace seems not to be documented anywhere - but quite some calendars supports the calendar-color
and calendar-order
attributes that apparently belongs to this namespace.
There is a comment in caldav.lib.namespace
indicating that it should not be sent in requests where it's not needed. I'll try to investigate it, possibly later today.
The git commit message reads: Ref https://github.com/python-caldav/caldav/issues/98 - only send the invalid namespace URL http://apple.com/ns/ical
if this namespace is actually used.
This is probably not related to the passing of the invalid namespace anyway. If I understand it correctly, the incompability here is between homeassistant and baikal, and hence unrelated to "my" caldav library.