openhab / openhab-js

openHAB JavaScript Library for JavaScript Scripting Automation
https://www.openhab.org/addons/automation/jsscripting/
Eclipse Public License 2.0
38 stars 31 forks source link

Item.sendCommandIfDifferent should handle conversion from JS Number to QuantityType #330

Closed wertzui closed 1 week ago

wertzui commented 1 month ago

Item.sendCommandIfDifferent(value) is an easy way to only send updates if something changed.

However if the items state is a QuantityType and the value is a Number or a String without a quantity, this method always detects a change. This is, because it compares the strings directly and if for example the state returns 26 °C and the value is 26, these are different.

It would be good if this method handles such cases and if value is a number, it just compares the number of the state and not the value too.