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

sendCommandIfDifferent fails with Dimmer and Number Items when using String commands #410

Open
rkoshak opened this issue Dec 23, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@rkoshak
Copy link
Contributor

rkoshak commented Dec 23, 2024

Expected Behavior

If the Dimmer or Number is 0, calling sendCommandIfDifferent("0") or calling sendCommandIfDifferent("0.0") should both suppress the command.

Current Behavior

If sending 0 or 0.0 as a command the command is suppressed. If sending the value as a String however, the command is not suppressed.

Possible Solution

My first thought was to make _toOpenhabPrimitiveType smarter but I don't think it has enough information there to do so.

So I think sendCommandIfDifferent needs to see if it can parse the string to a number and if so compare the parsed value to the numericValue.

I'm not sure how to handle Quantity. If I send "0" to a Number:Dimensionless that's 0 % the command isn't suppressed. If I send "0 %" the command is suppressed. Sending 0 the command is also suppressed. So for consistency I'd say we need to parse the value to a Quantity if the Item has a a QuantiyType too but what if the string is without units? Do we assume the same units as the quantityValue? It gets rather complicated, but handlable.

I can supply a PR but need advice on whether to address the Quantity issue as well.

Steps to Reproduce (for Bugs)

  1. Create a test Number and/or Dimmer Item
  2. initialize it with the value 0
  3. from a script call items.TestItem.sendCommandIfDifferent("0") and observe the command was send in any of the usual ways (e.g. events.log)

Context

In my Presence Simulation rule template I was only sending the string version of the value retrieved from persistence as a command to the Item. However, because it's a String, it litters the logs with commands which should not have occurred because the Item is already in that state.

Your Environment

  • openHAB version used (check Main UI -> About): 4.3 release
  • openhab-js version used (run console.log('openhab-js ' + utils.OPENHAB_JS_VERSION) from a JS script): 5.8.1
  • Operating System and version (e.g. desktop or mobile, Windows 10, Raspbian Buster, ...): Official OH Docker Image (debian)
@rkoshak rkoshak added the bug Something isn't working label Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant