openhab-scripters / openhab-helper-libraries

Scripts and modules for use with openHAB
Eclipse Public License 1.0
88 stars 69 forks source link

Initial check in for Ephemeris Time of Day #282

Closed rkoshak closed 3 years ago

rkoshak commented 4 years ago

Implements the Time of Day Design Pattern using Ephemeris to define and detect day types (holidays, weekends, etc.). The code supports a different set of times of days based on the type of the day.

Signed-off-by: Rich Koshak rlkoshak@gmail.com

rkoshak commented 4 years ago

This PR is ready for review

mjcumming commented 4 years ago

Also would suggest adding this to reload the config file.

import configuration
reload (configuration)
from configuration import tod_group_ephem, tod_item_ephem
rkoshak commented 4 years ago

Have you found that in practice? I've had all sorts of timing but I've never had Astro not populate an Item before Rules start running. It's a good test to have there and I should probably test for UNDEF there too because I want this to work with any DateTime source, not just Astro and some bindings can set Items to UNDEF when they go offline.

I'm just curious if you've actually seen this with Astro. I suppose if you hadn't you would have made the comment. :-)

As for the reload, I'm not yet sure what Scott's policy is on having that in the community scripts which is why I didn't include it. In fact I have the reload in my own instant of this and if Scott says it's OK I'll add it back here. But I think I asked about this on one of my other PRs and haven't received an answer yet.

mjcumming commented 4 years ago

Yes, I was seeing an error at that line. Items were not being populated with Astro after editing the .items file and saving. I thought they only populated when the channel was updated?

Not sure about the reload - it doesn't really cause any issues (that I know of). That being said, I am not sure I like the idea of the configuration.py file anyway. I don't think its a great solution. Ideally in 3.0 there would be a way to have scripts be able to generate their own UI's for configuration.

rkoshak commented 4 years ago

A configuration UI was part of Kai's original vision. I'm not sure if we will get all the way there though. Time will tell.

As for Astro, I remember seeing Astro log statements when I reloaded a file. I thought it was when I reloaded a .items file that had Items linked to Astro Channels, but now I'm wondering if I mainly saw that when I reloaded a .rules file with Astro Rule triggers. I just tried reloading my .items file and Astro did indeed not log anything. I use restoreOnStartup so I don't lose the value but I would hate to make that a requirement. I may need to do something more drastic because if you reload the .items file and Astro doesn't repopulate it until that midnight, it would break the state machine.

mjcumming commented 4 years ago

I am thinking they do not populate - I do not persist my Astro items (maybe I should). I wonder if we can force Astro to generate channel events from a script?

volfan6415 commented 4 years ago

So if i am going to try and use this what changes do i need to make? I see mention of the reload of a configuration and persisting astro items?

rkoshak commented 4 years ago

I would say to just install and configure it using the docstrings in the code as a guide. If it fails to work, we can help you add the suggestions mjcumming recommends making. Or I'll set up an alternative repo until this PR get's reviewed and merged or rejected.

volfan6415 commented 4 years ago

Ok so progress/ please disregard the previous post. jython wasn't installed properly. Fixed that and moved ephem_tod.py to jsr223\python\community and now at least getting error messsages:

`2020-02-04 22:36:48.523 [INFO ] [me.core.service.AbstractWatchService] - Loading script 'python/community/ephem_tod.py' 2020-02-04 22:36:53.149 [INFO ] [ort.shared.ScriptedAutomationManager] - removeAll added handlers 2020-02-04 22:36:53.160 [INFO ] [me.core.service.AbstractWatchService] - Loading script 'python/community/ephem_tod.py' 2020-02-04 22:36:53.184 [WARN ] [23.jython.Time of Day with Ephemeris] - Interrupted while sleeping waiting for Items to finsih updating! Hoping for the best. 2020-02-04 22:36:53.267 [ERROR] [23.jython.Time of Day with Ephemeris] - Traceback (most recent call last): File "/etc/openhab2/automation/lib/python/core/log.py", line 51, in wrapper return fn(*args, **kwargs) File " Githubissues.

  • Githubissues is a development platform for aggregating issues.