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

[items] Item: Fix sendCommandIfDifferent fails to compare Quantity #343

Merged
merged 2 commits into from
Jun 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions src/items/items.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
const osgi = require('../osgi');
const utils = require('../utils');
const log = require('../log')('items');
const { _toOpenhabPrimitiveType } = require('../helpers');
const { _toOpenhabPrimitiveType, _isQuantity } = require('../helpers');
const { getQuantity, QuantityError } = require('../quantity');

const { UnDefType, OnOffType, events, itemRegistry } = require('@runtime');
Expand Down Expand Up @@ -245,12 +245,29 @@ class Item {
* @see sendCommand
*/
sendCommandIfDifferent (value) {
// value and current state both are Quantity and have equal value
if (_isQuantity(value) && this.quantityState !== null) {
if (this.quantityState.equal(value)) {
return false;
}
}

// value and current state are both numeric and have equal value
if (typeof value === 'number' && this.numericState !== null) {
if (value === this.numericState) {
return false;
}
}

// stringified value and string state are equal
value = _toOpenhabPrimitiveType(value);
if (value.toString() !== this.state) {
this.sendCommand(value);
return true;
if (value.toString() === this.state) {
return false;
}
return false;

// else send the command
this.sendCommand(value);
return true;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion types/items/items.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading