-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[gcal] Add io and persistence feature to OH2 #4891
Conversation
Signed-off-by: Mark Hilbush <mark@hilbush.com>
watou
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @mhilbush! In addition to my review comments, could you add an ESH-INF/config/config.xml like the JDBC persistence bundle does, so users can configure the io.gcal service without having to edit the gcal.cfg file at all? If you add this, also change GCalEventDownloader.java to replace constructs like (String) config.get("X") with ObjectUtils.toString(config.get("X"), null) since configuring from Paper UI might put non-String objects in the configuration?
|
|
||
| <feature name="openhab-persistence-gcal" description="GCal Persistence" version="${project.version}"> | ||
| <feature>openhab-runtime-base</feature> | ||
| <feature>openhab-runtime-compat1x</feature> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
openhab-persistence-gcal depends on openhab-io-gcal1 (it imports the org.openhab.io.gcal.auth package)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Dependency added.
| <feature>openhab-runtime-base</feature> | ||
| <feature>openhab-runtime-compat1x</feature> | ||
| <bundle start-level="80">mvn:org.openhab.io/org.openhab.io.gcal/${project.version}</bundle> | ||
| </feature> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a default gcal.cfg file similar to what is done on line 667?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The binding currently expects the config info in openhab.cfg. I'm not quite sure what needs to be done here besides adding the line to feature.xml.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The binding itself actually doesn't know where its configuration comes from. The 1.x runtime used openhab.cfg, but it's refactored in OH2 to have a .cfg per service, gcal.cfg in this case, for text file configuration. Or via Paper UI so no config file has to be used.
To add gcal.cfg, just take the GCal section from openhab_default.cfg into features/openhab-addons-external/src/main/resources/conf/gcal.cfg (but remove the gcal: prefixes in it). Modify features/openhab-addons-external/pom.xml like in #4814.
To allow GCal to be configured from the Paper UI, add bundles/io/org.openhab.io.gcal/ESH-INF/config/config.xml similar to #4049, and see this documentation.
|
I made the changes for gcal.cfg. openhab_default.cfg contained the old (pre-OAuth) config parameters, so I just added client_id, client_secret, and calendar_name to gcal.cfg. I didn't do the config.xml change, as I'd prefer to get this part right first. :-) |
| #client_secret= | ||
|
|
||
| # The name of the Google Calendar that GCal should use | ||
| #calendar_name= |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, but I worry that users might not know which are required or optional. So a bit more information as described here might avoid head scratching or hair pulling. Also, when you've updated the helpfulness of the comments a bit, could you also fix openhab_default.cfg to match (adding back the gcal: prefixes in that version)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. Good point. I didn't want to repeat what was in the Wiki, but I certainly can add more to the comments.
As for openhab_default.cfg, I'm not sure what you're asking as I didn't change that file. It still contains the gcal: prefixes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
openhab_default.cfg contained the old (pre-OAuth) config parameters
I was hoping this PR would be a good opportunity for consistency between the now two .cfg files, seeing as you report that we missed updating openhab_default.cfg file with @SirAd's big refresh.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see now. :-/
I wasn't sure if that file was supposed to be updated. I can do that. Note that there also are some gcal-persistence parameters in openhab_default.cfg. Can those be added to gcal.cfg (in a separate section of the file explaining their use for the persistence feature), or is a separate gcal-persistence.cfg needed?
#gcal-persistence:offset=
#gcal-persistence:executescript=
What about the Wiki? It still references openhab.cfg and gcal: prefixes?
And, I see there are some log messages in the code that reference openhab.cfg...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, looking at this more closely, GCal Persistence has it's own calendar_name parameter, which may dictate a separate cfg file to avoid conflicting with GCal's calendar_name parameter. WDYT?
#gcal-persistence:calendar_name=
#gcal-persistence:offset=
#gcal-persistence:executescript=
Fair enough. Allowing GCal to be configured from Paper UI could be left to another PR if you prefer. So I only would like to see the .cfg files made more "idiot-proof" for this PR. Thanks, Mark! |
|
Latest commit has the following changes:
|
| # The filter criteria by which calendar events are searched. The Google Calendar | ||
| # API will do a text search to find calendar events that match the supplied terms. | ||
| # All calendar event fields are searched, except for extended properties (optional) | ||
| #filter= |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prepend gcal:?
| # Refresh interval (in milliseconds) is the frequency with which the | ||
| # Google calendar will be checked for calendar events (optional, defaults | ||
| # to 900000 [15 minutes]) | ||
| #refresh= |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prepend gcal:?
|
|
||
| # the url of the calendar feed | ||
| #gcal-persistence:url= | ||
| # The following parameters are used to configure the GCal Persistence binding. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"service", not "binding"
| # represents the State (optional, defaults to | ||
| # '> if (PresenceSimulation.state == ON) sendCommand(%s,%s)') | ||
| # represents the State (optional, defaults to 'send %s %s') | ||
| #gcal-persistence:executescript= |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feature doesn't exist any more, does it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left it in because it's still pulled from the config on line 116, and is used on line 166, in GCalPersistenceService.java
| # the GCal-based presence simulation. It must contain two format markers '%s'. | ||
| # The first marker represents the Item to send the command to and the second | ||
| # represents the State (optional, defaults to 'send %s %s') | ||
| #executescript= |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feature doesn't exist any more, does it?
| # Copied from Credentials page on console.developers.google.com | ||
| ################################### GCal Binding ################################### | ||
| # | ||
| # Before using the GCal bindings in openHAB2, you need to have a Google API |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not "bindings," more like "services." Yes, it's a bit confusing. ;-)
|
I've corrected everything except for Sorry for all the revisions... |
|
Sorry for my mistake, @mhilbush. The name |
|
No worries. Then I think I've incorporated all your feedback so far. However... I just tried to install gcal-persistence in OH2 and I got the below error. Looks like gcal-persistence imports a bunch of ch.qos.logback.* packages. Not familiar with that, but I can look into it. |
| #gcal:url= | ||
| # This is the name you gave to your Google Calendar. GCal will download calendar | ||
| # events from this calendar (required) | ||
| #gcal:calendar_name= |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code says:
String urlString = (String) config.get("calendar_name");
if (!StringUtils.isBlank(urlString)) {
calendar_name = urlString;
} else {
logger.error(
"gcal:calendar_name must be configured in openhab.cfg. Calendar name or word \"primary\" MUST be specified");
throw new ConfigurationException("calendar_name",
"gcal:calendar_name must be configured in openhab.cfg. Calendar name or word \"primary\" MUST be specified");
}
but the member calendar_name defaults to "primary" as well. So the code might allow this to be optional. For this PR, could you add that the special keyword primary" can be used? Ideally it would be verified that specifying calendar_name is optional and defaults to primary and the code changed to allow it to be optional (and tested!). 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've confirmed the following:
- both
gcalandgcal-persistencerequire a calendar name in the cfg. If not supplied, it doesn't default to anything. It does log errors in the log file, however. - using the keyword
primarydoes use your default Google calendar. My default calendar is now full of presence simulation events. :-(
Therefore, I'm not sure it's a good idea to default to primary if no calendar_name is specified (at least for gcal-presence), unless one wants to discover a bunch of presence simulation events in their default Google calendar.
I would propose that I update the cfg comments (gcal, gcal-persistence, and openhab_default) to reflect the usage of the keyword primary, but leave calendar_name required.
Also, in order to get gcal-persistence to run in OH2, I needed to remove these imported packages from MANIFEST.MF. Should I include an updated MANIFEST.MF in this PR?
ch.qos.logback.classic,
ch.qos.logback.classic.encoder,
ch.qos.logback.classic.spi,
ch.qos.logback.core,
ch.qos.logback.core.encoder,
ch.qos.logback.core.pattern,
ch.qos.logback.core.spi,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
both gcal and gcal-persistence require a calendar name in the cfg. If not supplied, it doesn't default to anything. It does log errors in the log file, however.
The code does log the error and throw the exception, but the calendar_name is initialized to "primary" in the class so it didn't make sense -- either have no default for the member, or allow it to be optional. In any case, I'm fine with requiring the user to explicitly set the calendar, for the reasons you gave. Yes, please update the .cfg files to make it clear, and thanks!
Should I include an updated MANIFEST.MF in this PR?
Beat you to it! #4899 😄
|
Confirmed that version works. Thanks, @watou. Are you ok with the above approach for updating the cfg file comments wrt primary keyword? [[Nm. I saw your other comment above.]] |
|
Just pushed the changes re: primary keyword. Anything else you think needs to be done on this? |
|
LGTM! Anything else from your side before I merge? |
|
Nope. I'm good. |
|
BTW, thanks for your help and feedback. |
|
Thanks for your contribution! It's great to see GCal up and usable again with the group effort! 😄 |
|
It looks like there are some minor edits needed to the GCal Wiki page. Any issue with me making those changes? |
|
Please go right ahead! Having all questions answered by clear documentation is really the most important thing of all! |
|
Big thanks again to @SirAd for making it possible with the OAuth2 update. |
|
@watou I must've done something wrong in feature.xml. gcal-persistence is showing up in PaperUI, but not gcal. This is the feature name I gave it.
Should it be |
|
Is the service not showing up under the Misc. Tab? |
|
Correct. Not showing under any tab (including misc). |
|
In several hours I will be able to have a look. |
|
From what I can see, currently the only features showing in Misc are from OH2. Do we need a misc section in the openhab feature.xml, then change the gcal entry to: And change gcal-persistence to: |
|
My understanding is that it's done by convention, so your change makes sense. I will delve deeper to find out for sure. |
|
But if you expose it to the UI, you should think of a slighly longer name than "GCal" for it, please! |
I was just about to suggest that its name be changed to a name that makes it clear 1) what is being integrated into openHAB, and 2) what function it performs. Something like "Google Calendar Scheduler" or "Google Calendar Connector". |
|
I like Google Calendar Scheduler. Since OH1 users already know it by GCal, could it be this, as there appears to be precedent for having a parenthetical in the name: And, for gcal-persistence, it could be one of these, which is more descriptive of what it actually does: |
|
Or, to be a bit more consistent with Scheduler... |
|
I don't see a need for (GCal) but I like your suggestions. |
|
Alright, if there are no objections, I'll do: |
* [gcal] Add io and persistence feature to OH2 Signed-off-by: Mark Hilbush <mark@hilbush.com> * Additional changes for OH2 distro * Additional changes for OH2 distro * Correction and comment revision. * Clarify usage of primary keyword for calendar_name
Signed-off-by: Mark Hilbush mark@hilbush.com