Pushover image support

pushover
Tags: #<Tag:0x00007f01472f7610>

(André) #21

sure, you can test it
download pushover action as jar

use it like this:
sendPushoverImage(“Hello, this is a message with attached image.”, “/path/to/image.jpeg”);

feedback is very appreciated


Using non-deprecated functions with Pushover action
Pushover cannot be resolved to an item or a type
(Ward) #22

thanks for sharing

I have 2 errors:

Rule:

var FrontDoorCam = "FrontDoor.jpg"
var LocationSS = "/tmp/"
var ImgFile = "file://" + LocationSS + FrontDoorCam
pushoverImage("Pushover test attachment", ImgFile)

Error:

2018-03-28 20:31:53.799 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'TEST pushover': The name 'pushoverImage' cannot be resolved to an item or type; line 33, column 9, length 50

When I use my normal pushover command, which worked previously, I receive the message on my phone, but I also see an amount of errors in the logs:

pushover(null, null, "test message", null, "Push test", null, null, 0, "spacealarm")

Error

2018-03-28 20:39:35.650 [INFO ] [org.openhab.action.pushover         ] - FrameworkEvent INFO - org.openhab.action.pushover
java.io.IOException: Exception in opening zip file: /var/lib/openhab2/cache/org.eclipse.osgi/213/0/bundleFile
	at org.eclipse.osgi.framework.util.SecureAction.getZipFile(SecureAction.java:321) ~[?:?]
	at org.eclipse.osgi.storage.bundlefile.ZipBundleFile.basicOpen(ZipBundleFile.java:93) ~[?:?]
	at org.eclipse.osgi.storage.bundlefile.ZipBundleFile.getZipFile(ZipBundleFile.java:106) ~[?:?]
	at org.eclipse.osgi.storage.bundlefile.ZipBundleFile.checkedOpen(ZipBundleFile.java:65) ~[?:?]
	at org.eclipse.osgi.storage.bundlefile.ZipBundleFile.getEntry(ZipBundleFile.java:240) ~[?:?]
	at org.eclipse.osgi.storage.bundlefile.BundleFile.getResourceURL(BundleFile.java:136) ~[?:?]
	at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findResourceImpl(ClasspathManager.java:418) ~[?:?]
	at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findLocalResources(ClasspathManager.java:395) ~[?:?]
	at org.eclipse.osgi.internal.loader.ModuleClassLoader.findLocalResources(ModuleClassLoader.java:321) ~[?:?]
	at org.eclipse.osgi.internal.loader.BundleLoader.findLocalResources(BundleLoader.java:837) ~[?:?]
	at org.eclipse.osgi.internal.loader.BundleLoader.findResources(BundleLoader.java:693) ~[?:?]
	at org.eclipse.osgi.internal.loader.ModuleClassLoader.getResources(ModuleClassLoader.java:231) ~[?:?]
	at org.eclipse.osgi.internal.framework.ContextFinder.getResources(ContextFinder.java:165) ~[?:?]
	at java.util.ServiceLoader$LazyIterator.hasNextService(ServiceLoader.java:348) ~[?:?]
	at java.util.ServiceLoader$LazyIterator.hasNext(ServiceLoader.java:393) ~[?:?]
	at java.util.ServiceLoader$1.hasNext(ServiceLoader.java:474) ~[?:?]
	at javax.xml.parsers.FactoryFinder$1.run(FactoryFinder.java:293) ~[?:?]
	at java.security.AccessController.doPrivileged(Native Method) ~[?:?]
	at javax.xml.parsers.FactoryFinder.findServiceProvider(FactoryFinder.java:289) ~[?:?]
	at javax.xml.parsers.FactoryFinder.find(FactoryFinder.java:267) ~[?:?]
	at javax.xml.parsers.DocumentBuilderFactory.newInstance(DocumentBuilderFactory.java:120) ~[?:?]
	at org.openhab.action.pushover.internal.Pushover.parseResponse(Pushover.java:370) ~[?:?]
	at org.openhab.action.pushover.internal.Pushover.pushover(Pushover.java:350) ~[?:?]
	at org.openhab.action.pushover.internal.Pushover.pushover(Pushover.java:101) ~[?:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.invokeOperation(XbaseInterpreter.java:1085) ~[?:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.invokeOperation(XbaseInterpreter.java:1060) ~[?:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._invokeFeature(XbaseInterpreter.java:1046) ~[?:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.invokeFeature(XbaseInterpreter.java:991) ~[?:?]
	at org.eclipse.smarthome.model.script.interpreter.ScriptInterpreter.invokeFeature(ScriptInterpreter.java:141) ~[?:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:901) ~[?:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:864) ~[?:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:223) ~[?:?]
	at org.eclipse.smarthome.model.script.interpreter.ScriptInterpreter.doEvaluate(ScriptInterpreter.java:215) ~[?:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:203) ~[?:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:446) ~[?:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:227) ~[?:?]
	at org.eclipse.smarthome.model.script.interpreter.ScriptInterpreter.doEvaluate(ScriptInterpreter.java:215) ~[?:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:203) ~[?:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:459) ~[?:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:243) ~[?:?]
	at org.eclipse.smarthome.model.script.interpreter.ScriptInterpreter.doEvaluate(ScriptInterpreter.java:215) ~[?:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:203) ~[?:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:446) ~[?:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:227) ~[?:?]
	at org.eclipse.smarthome.model.script.interpreter.ScriptInterpreter.doEvaluate(ScriptInterpreter.java:215) ~[?:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:203) ~[?:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.evaluate(XbaseInterpreter.java:189) ~[?:?]
	at org.eclipse.smarthome.model.script.runtime.internal.engine.ScriptImpl.execute(ScriptImpl.java:82) ~[?:?]
	at org.eclipse.smarthome.model.rule.runtime.internal.engine.RuleEngineImpl.lambda$2(RuleEngineImpl.java:343) ~[?:?]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:?]
	at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:?]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [?:?]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]
	at java.lang.Thread.run(Thread.java:748) [?:?]
Caused by: java.io.FileNotFoundException: /var/lib/openhab2/cache/org.eclipse.osgi/213/0/bundleFile (No such file or directory)
	at java.util.zip.ZipFile.open(Native Method) ~[?:?]
	at java.util.zip.ZipFile.<init>(ZipFile.java:225) ~[?:?]
	at java.util.zip.ZipFile.<init>(ZipFile.java:155) ~[?:?]
	at java.util.zip.ZipFile.<init>(ZipFile.java:169) ~[?:?]
	at org.eclipse.osgi.framework.util.SecureAction.getZipFile(SecureAction.java:304) ~[?:?]
	... 59 more

(Christoph Weitkamp) #23

We rename this action to sendPushoverImage(). Didn’t we?

@wars Had you uninstalled the original Pushover action before you put the new one into your addons folder?


(Frank Kintrup) #24

Works perfectly :grinning:

I put the snapshot jar in my addons folder, uninstalled the original Pushover binding, restarted openHAB.
Then I wrote the following in a rule which could be fired by a switch:

    sendPushoverImage("Test", "/volume1/SmartHome/openHAB/conf/icons/basic/washer.png")

And after clicking on the switch Pushover on my Android displayed the image!
No exceptions in my log, and the original “pushover” still works, too.

Thanks a lot!


(André) #25

ups sorry guys, sure, the method name is “sendPushoverImage” and not “pushoverImage” !
so the code should look like this:

sendPushoverImage(“Hello, this is a message with attached image.”, “/path/to/image.jpeg”);

(Ward) #26

It’s working with sendPushoverImage and after a restart of OpenHAB :slight_smile:
Thanks for the effort !

Although I see one warning message (I used a .jpg file of 216KB):

2018-03-29 11:24:44.185 [WARN ] [he.commons.httpclient.HttpMethodBase] - Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.

Is also possible to give extra parameters such as device, priority, sound… ? Or is the Pushover API not supporting this?


(André) #27

glad, its working for you
here is the code of the SNAPSHOT version, you are using

you can use the method

pushover(String apiKey, String user, String message, String device, String title, String url, String urlTitle, int priority, String sound, String attachment)

some kind of a builder pattern would be a better approach there, feel free to implement :slight_smile:


(Ward) #28

Thanks

I’m already using this kind of method for my other Pushover messages, but didn’t knew that the attachment can be added now.
So there is no difference between pushover and sendPushoverImage ? Except that the 2nd only accepts title, message & attachment?


(André) #29

correct
the old “pushover” method accepts additionally an optional “String attachment” parameter at the end of the list
“sendPushoverImage” accepts two parameters: message and path to the file, no title


(André) #30

just changed the code to avoid this warning

[WARN ] [he.commons.httpclient.HttpMethodBase] - Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.

the warning is gone, i updated the snapshot jar file on my server, feel free to use it


(Roger) #31

Works! :smiley: Two things i am missing tough:

  • Support for special characters, earlier my pushover would show æøå letters, this does not work now (replaced with “?”)

  • Possibility to add priority to the sendPushoverImage

Thnx for awesome work :slight_smile:


(André) #32

good catch, will have a look at it later today

edit:
just fixed the encoding, special characters should be fine now, the jar file is updated
i later will add another method to set the priority

edit2:
@rogerrem
just added the method

sendPushoverImage(String message, int priority, String attachment)

feel free to test it, do not forget to renew the jar file

edit3:

sorry @rogerrem
the correct method is: sendPushoverImage(String message, String attachment, int priority)


(Roger) #33

Tested it now, but now it seems it doesnt work at all, downloaded the jar file from your previous post again.

2018-04-02 19:09:42.064 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during
the execution of rule 'Ringeklokke': The name 'sendPushoverImage(<XStringLiteral
Impl>,<XNumberLiteralImpl>,<XStringLiteralImpl>)' cannot be resolved to an item
or type.

(Roger) #34

Strange, the jar does not seem to work at all, the normal pushover(xxx) does not work anymore either.


(SiHui) #35

Cannot confirm, the “normal” pushover functions do work as before.
Note that you cannot have both bindings installed: you need to uninstall the “old” pushover binding and drop the new one into your addons folder.


(Roger) #36

I did, but thanks, the problem must be at my side - I will investigate :smiley:

edit:
I tried “downgrading” to an old jar, when doing this, pushover(xxx) works fine.
When upgrading to the 1.12.0 snapshot it stops working again…

Any ideas? :thinking:


(namraccr) #37
sendPushoverImage(<XStringLiteralImpl>,<XNumberLiteralImpl>,<XStringLiteralImpl>)

The new method signature is (String, String, int) instead of (String, int, String)


(SiHui) #38

Today I tried the new image function but get errors:

2018-04-03 09:42:07.680 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'doorbell.rules' has errors, therefore ignoring it: [60,20]: no viable alternative at input '“'
[60,21]: no viable alternative at input 'Doorbell'
[60,71]: no viable alternative at input '”'
[60,74]: mismatched input ')' expecting 'end'

Command is:

sendPushoverImage(“Doorbell”,“/opt/openhab2/userdata/tmp/lastsnap.jpg”,1)

Edit: sendPushoverImage("Doorbell","/opt/openhab2/userdata/tmp/lastsnap.jpg",1)

openHAB snapshot #1246, pushover jar from post above. Bundle-Version: 1.12.0.201804021632

I can confirm that the “normal” pushover actions do work as before …

Edit: Damn, beginner error: wrong double quotes … sorry, disregard post :sunglasses:


(SiHui) #39

@andre77, thanks for this amazing piece of code, works great.
But you should maybe edit your post above so other users don’t make the same mistake and copy those wrong quotes, too :rofl:


(Ward) #40

I’ll check this evening to see if the warning message is gone.

I still don’t understand why there are 2 methods (sendPushoverImage and pushover).