Class: OpenHAB::Core::Types::HSBType

Inherits:
PercentType show all
Defined in:
lib/openhab/core/types/hsb_type.rb

Overview

HSBType is a complex type with constituents for hue, saturation and

brightness and can be used for color items.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PercentType

#down?, #off?, #on?, #scale, #to_byte, #up?

Methods inherited from DecimalType

#-@, #coerce, #initialize, #|

Methods included from NumericType

#+@, #eql?, #to_d, #to_f, #to_i

Constructor Details

This class inherits a constructor from OpenHAB::Core::Types::DecimalType

Instance Attribute Details

#bluePercentType (readonly)

Returns:



# File 'lib/openhab/core/types/hsb_type.rb', line 168

#brightnessPercentType (readonly)

Returns:



# File 'lib/openhab/core/types/hsb_type.rb', line 159

#greenPercentType (readonly)

Returns:



# File 'lib/openhab/core/types/hsb_type.rb', line 165

#hueQuantityType (readonly)

Returns The color’s hue component as a QuantityType of unit DEGREE_ANGLE.

Returns:



127
128
129
# File 'lib/openhab/core/types/hsb_type.rb', line 127

def hue
  QuantityType.new(raw_hue.to_big_decimal, Units::DEGREE_ANGLE)
end

#redPercentType (readonly)

Returns:



# File 'lib/openhab/core/types/hsb_type.rb', line 162

#saturationPercentType (readonly)

Returns:



# File 'lib/openhab/core/types/hsb_type.rb', line 156

Class Method Details

.from_hsb(hue, saturation, brightness) ⇒ HSBType

Create HSBType from hue, saturation, and brightness values

Parameters:

Returns:



54
55
56
# File 'lib/openhab/core/types/hsb_type.rb', line 54

def from_hsb(hue, saturation, brightness)
  new(hue, saturation, brightness)
end

.from_rgb(r, g, b) ⇒ HSBType

Create HSBType from RGB values

Parameters:

  • r (Integer)

    Red component (0-255)

  • g (Integer)

    Green component (0-255)

  • b (Integer)

    Blue component (0-255)

Returns:



# File 'lib/openhab/core/types/hsb_type.rb', line 36

.from_xy(x, y) ⇒ HSBType

Create HSBType representing the provided xy color values in CIE XY color model

Parameters:

Returns:



# File 'lib/openhab/core/types/hsb_type.rb', line 43

Instance Method Details

#<=>(other) ⇒ Integer?

Comparison

Parameters:

Returns:

  • (Integer, nil)

    -1, 0, +1 depending on whether ‘other` is less than, equal to, or greater than self

    ‘nil` is returned if the two values are incomparable.



112
113
114
115
116
117
118
119
# File 'lib/openhab/core/types/hsb_type.rb', line 112

def <=>(other)
  logger.trace("(#{self.class}) #{self} <=> #{other} (#{other.class})")
  if other.is_a?(HSBType)
    [brightness, hue, saturation] <=> [other.brightness, other.hue, other.saturation]
  else
    super
  end
end

#argbInteger

Convert to a packed 32-bit RGB value representing the color in the default sRGB color model.

The alpha component is always 100%.

Returns:



136
# File 'lib/openhab/core/types/hsb_type.rb', line 136

alias_method :argb, :rgb

#rgbInteger

Convert to a packed 24-bit RGB value representing the color in the default sRGB color model.

Returns:



140
141
142
# File 'lib/openhab/core/types/hsb_type.rb', line 140

def rgb
  argb & 0xffffff
end

#to_hexString

Convert to an HTML-style string of 6 hex characters in the default sRGB color model.

Returns:

  • (String)

    ‘“#xxxxxx”`



146
147
148
# File 'lib/openhab/core/types/hsb_type.rb', line 146

def to_hex
  Kernel.format("#%06x", rgb)
end

#to_rgb[PercentType, PercentType, PercentType]

Convert to RGB values representing the color in the default sRGB color model



# File 'lib/openhab/core/types/hsb_type.rb', line 171

#to_xy[PercentType, PercentType, PercentType]

Convert to the xyY values representing this object’s color in CIE XY color model



# File 'lib/openhab/core/types/hsb_type.rb', line 175