这是indexloc提供的服务,不要输入任何密码
Skip to content
This repository was archived by the owner on May 17, 2021. It is now read-only.

Conversation

@mhilbush
Copy link
Contributor

Signed-off-by: Mark Hilbush mark@hilbush.com

Signed-off-by: Mark Hilbush <mark@hilbush.com>
Copy link
Contributor

@watou watou left a 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>
Copy link
Contributor

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)

Copy link
Contributor Author

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>
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

@mhilbush
Copy link
Contributor Author

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=
Copy link
Contributor

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)?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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...

Copy link
Contributor Author

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=

@watou
Copy link
Contributor

watou commented Dec 13, 2016

I didn't do the config.xml change, as I'd prefer to get this part right first. :-)

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!

@mhilbush
Copy link
Contributor Author

Latest commit has the following changes:

  • updated gcal.cfg comments
  • added gcal-persistence.cfg
  • openhab_default.cfg now matches gcal.cfg and gcal-persistence.cfg

# 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=
Copy link
Contributor

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=
Copy link
Contributor

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.
Copy link
Contributor

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=
Copy link
Contributor

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?

Copy link
Contributor Author

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=
Copy link
Contributor

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
Copy link
Contributor

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. ;-)

@mhilbush
Copy link
Contributor Author

I've corrected everything except for gcal-persistence:executescript=. Since it was still used in the code, I left it in the config. WDYT?

Sorry for all the revisions...

@watou
Copy link
Contributor

watou commented Dec 15, 2016

Sorry for my mistake, @mhilbush. The name executescript is indeed still used, but it's not actually capable of being a script fragment any more so I got myself confused by the old name. Its only valid formats are now send %s %s or update %s %s.

@mhilbush
Copy link
Contributor Author

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.

2016-12-15 08:24:23.662 [WARN ] [org.apache.felix.fileinstall        ] - Error while starting bundle: file:/opt/openhab/addons/org.openhab.persistence.gcal-1.9.0-SNAPSHOT.jar
org.osgi.framework.BundleException: Could not resolve module: org.openhab.persistence.gcal [198]
  Unresolved requirement: Import-Package: ch.qos.logback.classic
        at org.eclipse.osgi.container.Module.start(Module.java:434)[org.eclipse.osgi-3.10.2.v20150203-1939.jar:]
        at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:393)[org.eclipse.osgi-3.10.2.v20150203-1939.jar:]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(DirectoryWatcher.java:1245)[8:org.apache.felix.fileinstall:3.5.0]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(DirectoryWatcher.java:1217)[8:org.apache.felix.fileinstall:3.5.0]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(DirectoryWatcher.java:509)[8:org.apache.felix.fileinstall:3.5.0]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:358)[8:org.apache.felix.fileinstall:3.5.0]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:310)[8:org.apache.felix.fileinstall:3.5.0]

#gcal:url=
# This is the name you gave to your Google Calendar. GCal will download calendar
# events from this calendar (required)
#gcal:calendar_name=
Copy link
Contributor

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!). 😄

Copy link
Contributor Author

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 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.
  • using the keyword primary does 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,

Copy link
Contributor

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 😄

@watou
Copy link
Contributor

watou commented Dec 15, 2016

Thanks for trying the persistence bundle on OH2, @mhilbush. I've submitted #4899 to fix the problem you saw. Consider replacing the bundle with this one if you have a chance to test again.

@mhilbush
Copy link
Contributor Author

mhilbush commented Dec 15, 2016

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.]]

@mhilbush
Copy link
Contributor Author

mhilbush commented Dec 15, 2016

Just pushed the changes re: primary keyword. Anything else you think needs to be done on this?

@watou
Copy link
Contributor

watou commented Dec 15, 2016

LGTM! Anything else from your side before I merge?

@mhilbush
Copy link
Contributor Author

Nope. I'm good.

@watou watou merged commit b2f779c into openhab:master Dec 15, 2016
@mhilbush
Copy link
Contributor Author

BTW, thanks for your help and feedback.

@mhilbush mhilbush deleted the gcal-feature branch December 15, 2016 16:35
@watou
Copy link
Contributor

watou commented Dec 15, 2016

Thanks for your contribution! It's great to see GCal up and usable again with the group effort! 😄

@mhilbush
Copy link
Contributor Author

It looks like there are some minor edits needed to the GCal Wiki page. Any issue with me making those changes?

@watou
Copy link
Contributor

watou commented Dec 15, 2016

Please go right ahead! Having all questions answered by clear documentation is really the most important thing of all!

@watou
Copy link
Contributor

watou commented Dec 15, 2016

Big thanks again to @SirAd for making it possible with the OAuth2 update.

@mhilbush
Copy link
Contributor Author

@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.

<feature name="openhab-io-gcal1" description="GCal" version="${project.version}">

Should it be openhab-binding-gcal1, and should it be up in the binding section?

@watou
Copy link
Contributor

watou commented Dec 16, 2016

Is the service not showing up under the Misc. Tab?

@mhilbush
Copy link
Contributor Author

Correct. Not showing under any tab (including misc).

@watou
Copy link
Contributor

watou commented Dec 16, 2016

In several hours I will be able to have a look.

@mhilbush
Copy link
Contributor Author

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:

<feature name="openhab-misc-gcal1" description="GCal" version="${project.version}">
    <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>
    <configfile finalname="${openhab.conf}/services/gcal.cfg" override="false">mvn:${project.groupId}/openhab-addons-external/${project.version}/cfg/gcal</configfile>
</feature>

And change gcal-persistence to:

<feature name="openhab-persistence-gcal" description="GCal Persistence" version="${project.version}">
    <feature>openhab-runtime-base</feature>
    <feature>openhab-runtime-compat1x</feature>
    <feature>openhab-misc-gcal1</feature>
    <bundle start-level="80">mvn:org.openhab.persistence/org.openhab.persistence.gcal/${project.version}</bundle>
    <configfile finalname="${openhab.conf}/services/gcal-persistence.cfg" override="false">mvn:${project.groupId}/openhab-addons-external/${project.version}/cfg/gcal-persistence</configfile>
</feature>

@watou
Copy link
Contributor

watou commented Dec 16, 2016

My understanding is that it's done by convention, so your change makes sense. I will delve deeper to find out for sure.

@kaikreuzer
Copy link
Member

openhab-misc-gcal1 will indeed make it appear on the "MISC" tab under Extensions in the Paper UI - this should be used for any feature that is installable by the user, while openhab-io... are only shared bundles that are required by other features, but do not make sense on their own.

But if you expose it to the UI, you should think of a slighly longer name than "GCal" for it, please!

@watou
Copy link
Contributor

watou commented Dec 16, 2016

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".

@mhilbush
Copy link
Contributor Author

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:
Google Calendar (GCal) Scheduler

And, for gcal-persistence, it could be one of these, which is more descriptive of what it actually does:

Google Calendar Presence Simulation
Google Calendar (GCal) Presence Simulation

@mhilbush
Copy link
Contributor Author

Or, to be a bit more consistent with Scheduler...

Google Calendar Presence Simulator
Google Calendar (GCal) Presence Simulator

@watou
Copy link
Contributor

watou commented Dec 16, 2016

I don't see a need for (GCal) but I like your suggestions.

@mhilbush
Copy link
Contributor Author

Alright, if there are no objections, I'll do:

Google Calendar Scheduler
Google Calendar Presence Simulator

mvolaart pushed a commit to mvolaart/openhab that referenced this pull request Dec 23, 2016
* [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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants