Quantity

Quantity

Class allowing easy Units of Measurement/Quantity handling by wrapping the openHAB QuantityType.

Throws QuantityError when Quantity creation or operation failed due to wrong quantity or unit. Throws TypeError when wrong argument type is provided.

Members

dimension :string

Description:
  • Dimension of this Quantity, e.g. [L] for metres or [L]² for cubic-metres

Source:

Dimension of this Quantity, e.g. [L] for metres or [L]² for cubic-metres

Type:
  • string

float :number

Description:
  • Float (decimal number) value of this Quantity

Source:

Float (decimal number) value of this Quantity

Type:
  • number

int :number

Description:
  • Integer (non-decimal number) value of this Quantity

Source:

Integer (non-decimal number) value of this Quantity

Type:
  • number

symbol :string|null

Description:
  • Unit symbol of this Quantity, e.g. m, or null if not available

Source:

Unit symbol of this Quantity, e.g. m, or null if not available

Type:
  • string | null

unit :string|null

Description:
  • Unit of this Quantity, e.g. Metre, or null if not available

Source:

Unit of this Quantity, e.g. Metre, or null if not available

Type:
  • string | null

Methods

add(value) → {Quantity}

Description:
  • Add the given value to this Quantity.

Source:
Parameters:
Name Type Description
value Item | string | Quantity

Quantity-compatible Item, string consisting of amount and unit or a Quantity

Returns:

result as new Quantity

Type
Quantity

divide(value) → {Quantity}

Description:
  • Divide this Quantity by the given value.

Source:
Example
Quantity('20 W').divide(4); // is 5 W
Quantity('20 W').divide('4 W') // is 5
Parameters:
Name Type Description
value Item | number | string | Quantity

usually a number; may also be an Item which is either Quantity-compatible or holds a number, a string consisting of amount and unit or a Quantity, but be careful: 1 W / 5 W = 0.2 which might not be what you want

Returns:

result as new Quantity

Type
Quantity

equal(value) → {boolean}

Description:
  • Checks whether this Quantity is equal to the passed in value.

Source:
Parameters:
Name Type Description
value Item | string | Quantity

Quantity-compatible Item, string consisting of amount and unit or a Quantity

Returns:
Type
boolean

greaterThan(value) → {boolean}

Description:
  • Checks whether this Quantity is larger than the passed in value.

Source:
Parameters:
Name Type Description
value Item | string | Quantity

Quantity-compatible Item, string consisting of amount and unit or a Quantity

Returns:
Type
boolean

greaterThanOrEqual(value) → {boolean}

Description:
  • Checks whether this Quantity is larger than or equal to the passed in value.

Source:
Parameters:
Name Type Description
value Item | string | Quantity

Quantity-compatible Item, string consisting of amount and unit or a Quantity

Returns:
Type
boolean

lessThan(value) → {boolean}

Description:
  • Checks whether this Quantity is smaller than the passed in value.

Source:
Parameters:
Name Type Description
value Item | string | Quantity

Quantity-compatible Item, string consisting of amount and unit or a Quantity

Returns:
Type
boolean

lessThanOrEqual(value) → {boolean}

Description:
  • Checks whether this Quantity is smaller than or equal to the passed in value.

Source:
Parameters:
Name Type Description
value Item | string | Quantity

Quantity-compatible Item, string consisting of amount and unit or a Quantity

Returns:
Type
boolean

multiply(value) → {Quantity}

Description:
  • Multiply this Quantity by the given value.

Source:
Example
Quantity('20 W').multiply(4); // is 80 W
Quantity('20 W').multiply('4 W') // is 80 W^2
Parameters:
Name Type Description
value Item | number | string | Quantity

usually a number; may also be an Item which is either Quantity-compatible or holds a number, a string consisting of amount and unit or a Quantity, but be careful: 1 W * 5 W = 5 W^2 which might not be what you want

Returns:

result as new Quantity

Type
Quantity

subtract(value) → {Quantity}

Description:
  • Subtract the given value from this Quantity.

Source:
Parameters:
Name Type Description
value Item | string | Quantity

Quantity-compatible Item, string consisting of amount and unit or a Quantity

Returns:

result as new Quantity

Type
Quantity

toUnit(unit) → {Quantity|null}

Description:
  • Convert this Quantity to the given unit.

Source:
Parameters:
Name Type Description
unit string
Throws:

when unit cannot be parsed because it is invalid

Type
QuantityError
Returns:

a new Quantity with the given unit or null if conversion to this unit is not possible

Type
Quantity | null