Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OH #1518: issues with "now" implementations #553

Closed
nesys opened this issue Feb 9, 2019 · 13 comments
Closed

OH #1518: issues with "now" implementations #553

nesys opened this issue Feb 9, 2019 · 13 comments

Comments

@nesys
Copy link

nesys commented Feb 9, 2019

Hi team,

after updating to #1518 I've encountered issues in all my rules where I implement solutions with persistence (eg. lastUpdate.isAfter(now.minusSeconds(6)) or averageSince(now.minusMinutes(2)) )

Let me share an example:

2019-02-09 12:14:43.879 [INFO ] [el.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model 'presence.rules', using it anyway:
The method createTimer(Object, Procedure0) from the type ScriptExecution refers to the missing type Object
The method lastUpdate(Item) from the type PersistenceExtensions refers to the missing type Object
The method lastUpdate(Item) from the type PersistenceExtensions refers to the missing type Object
The method lastUpdate(Item) from the type PersistenceExtensions refers to the missing type Object

My rule is:

rule "Welcome home my dear"
when
    Member of gPhones changed to ON
then
    if(cameHomeTimer !== null) {
        return; // do nothing if there is already a Timer
    }
    logInfo("test", "Rule triggered by " + triggeringItem.name + " at " + now.toString)
    cameHomeTimer = createTimer(now.plusSeconds(5), [ |

        val cameHome = gPhones.members.filter[ p | p.state == ON && (p.name == triggeringItem.name || (p.lastUpdate !== null && p.lastUpdate.isAfter(now.minusSeconds(6)))) ].map[ name.replace("_Phone_Home_Unifi_online", "") ]

        gPhones.members.forEach[ p | logInfo("test", "Values for " + p.name + "\n" + "State = " + p.state.toString + "\n" + "LastUpdate = " + p.lastUpdate.toString)]

        var message = "Benvenuti a casa, "

        switch(cameHome.size) {
            case 0: {
                logError("came home", "Unexpected number of phones: " + cameHome.size)
                return;
            }
            case cameHome.size == 1 && cameHome.get(0) == "Andrea": message = "Benvenuto a casa, Andrea"
            case cameHome.size == 1 && cameHome.get(0) == "Cate": message = "Benvenuta a casa, Caterina"
            case cameHome.size == 1 && cameHome.get(0) == "Sofia": message = "Benvenuta a casa, Sofia"
            case cameHome.size == 1 && cameHome.get(0) == "Edo": message = "Benvenuto a casa, Edoardo"
            default: {
                message = message + cameHome.members.reduce[ String list, String name | list + ", " + name ]
                val ind = message.lastIndexOf(",")
                message = new StringBuilder(str).replace(ind, ind+1," e").toString();
            }
        }
        logInfo("check message", "message is: " + message)

        Echo_Living_Room_TTS_Volume.sendCommand('90')
        Echo_Living_Room_TTS.sendCommand('<speak><break time="2s"/>' + message + '</speak>')
        //Echo_Living_Room_TTS.sendCommand(message)      
        cameHomeTimer = null
    ])
end

When the rule is triggered, I see this error in my logs (and the rule not works):

2019-02-09 12:18:22.223 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Welcome home my dear': The name 'now' cannot be resolved to an item or type; line 28, column 75, length 3

Any suggestion? is that related to ESH bundles?

I've also a community topic open:
https://community.openhab.org/t/issues-in-rules-after-upgrading-to-1518/67136/5

Thanks for your support

Kind Regards

Andrea

@jimduchek
Copy link

Same issue here. Tried a number of things, really, it looks like a great deal of Joda seems to be broken. This issue completely breaks the rules for heating/cooling my house so it's quite a problem. Temporary workaround for me (really I just need the current epoch time) is to revert to some deprecated stuff.

var millis = new DateTimeType().calendar.timeInMillis

@toffyrn
Copy link

toffyrn commented Feb 12, 2019

For me I resolved it by reverting to snapshot 1512.

@kaikreuzer
Copy link
Member

@maggu2810 I assume this must be in some way related to the fact that Jodatime is not part of model.persistence anymore. I can see that Jodatime is installed as a separate bundle and there are import-package statements in model.persistence, so I don't see any obvious problem. Do you have an idea, why this broke?

@maggu2810
Copy link
Contributor

@nesys I fixed your initial comment. Please use triple backticks for multiline preformatted text.

@maggu2810
Copy link
Contributor

maggu2810 commented Feb 12, 2019

@maggu2810 I assume this must be in some way related to the fact that Jodatime is not part of model.persistence anymore.

I don't have the time to dig into the models.
So perhaps the simplest solution would be to bundle it again.

Wasn't the intention to get rid of Joda time at all?

@kaikreuzer
Copy link
Member

Wasn't the intention to get rid of Joda time at all?

Yes, but that hasn't been implemented yet, so I guess we have to fix this regression first...

@maggu2810
Copy link
Contributor

I had a look at the ESH manifests.

joda time has been added to the persistence model bundle.
So it should not matter if bundled or not, from a script / rule perspective it should be the same if provided by persistence or a separate one.

Perhaps an import gets lost.

@kaikreuzer
Copy link
Member

Yes, that's also what I saw and mentioned above:

I can see that Jodatime is installed as a separate bundle and there are import-package statements in model.persistence

The model.persistence bundle is fully resolved and active, so it does not seem to miss anything.

I am still struggling to get the app.bndrun working, so I currently cannot test & debug in the IDE... Will try to get that working first.

@maggu2810
Copy link
Contributor

maggu2810 closed this in [maggu2810/openhab-core.bnd-playground@fd2bd9e](/maggu2810/openhab-core.bnd-playground/commit/fd2bd9edc85bb8bcee3b0674d715858c5de75b60) 3 minutes ago

Strange, why is this issue closed if I commit to a repository of mine?

@nesys
Copy link
Author

nesys commented Feb 12, 2019

guys thanks for your support here. @maggu2810 understood and will do next time

@kaikreuzer
Copy link
Member

Strange, why is this issue closed if I commit to a repository of mine?

Because you say it fixes this issue and you have write access to this repo here - that's how the Github auto-closing feature works :-)

kaikreuzer pushed a commit that referenced this issue Feb 13, 2019
Fixes: #553

Signed-off-by: Markus Rathgeb <maggu2810@gmail.com>
@maggu2810
Copy link
Contributor

If I commit to branch "fit-xyz" into my repository the issue get's not closed. Otherwise I will never be able to create PRs without already closing the issue.
I assume it has been caused because I added it to the master branch of my repository.

But that's annoying.
This will make it much harder to work on forks while having write permission.
Just because I fix an issue in my repo it does not solve it in the repo of the upstream project.

@kaikreuzer
Copy link
Member

Many thanks for the fix, @maggu2810, I can confirm that "now" now works smoothly in the latest distro 1522!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants