Class: OpenHAB::Core::Types::HSBType
- Inherits:
-
PercentType
- Object
- DecimalType
- PercentType
- OpenHAB::Core::Types::HSBType
- 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.
Constant Summary collapse
- BLACK =
- WHITE =
- RED =
- GREEN =
- BLUE =
Instance Attribute Summary collapse
- #blue ⇒ PercentType readonly
- #brightness ⇒ PercentType readonly
-
#cct ⇒ QuantityType
readonly
The correlated color temperature in Kelvin.
-
#duv ⇒ Float
readonly
The delta u, v.
- #green ⇒ PercentType readonly
-
#hue ⇒ QuantityType
readonly
The color's hue component as a QuantityType of unit DEGREE_ANGLE.
- #red ⇒ PercentType readonly
- #saturation ⇒ PercentType readonly
Class Method Summary collapse
-
.from_cct(cct) ⇒ HSBType
Create HSBType from a color temperature.
-
.from_hsb(hue, saturation, brightness) ⇒ HSBType
Create HSBType from hue, saturation, and brightness values.
-
.from_rgb(r, g, b) ⇒ HSBType
Create HSBType from RGB values.
-
.from_xy(x, y) ⇒ HSBType
Create HSBType representing the provided xy color values in CIE XY color model.
Instance Method Summary collapse
-
#<=>(other) ⇒ Integer?
Comparison.
-
#argb ⇒ Integer
Convert to a packed 32-bit RGB value representing the color in the default sRGB color model.
-
#planckian?(duv_tolerance: 0.015, maximum_saturation: 75) ⇒ true, false
(also: #white_cct?)
Checks if this color is within a certain tolerance of the planckian locus ("white").
-
#planckian_cct(range: nil, **kwargs) ⇒ QuantityType?
(also: #white_cct)
Returns the color temperature of this color if it is within a certain tolerance of the planckian locus ("white"), otherwise returns
nil
. -
#rgb ⇒ Integer
Convert to a packed 24-bit RGB value representing the color in the default sRGB color model.
-
#to_hex ⇒ String
Convert to an HTML-style string of 6 hex characters in the default sRGB color model.
-
#to_rgb ⇒ [PercentType, PercentType, PercentType]
Convert to RGB values representing the color in the default sRGB color model.
-
#to_xy ⇒ [PercentType, PercentType, PercentType]
Convert to the xyY values representing this object's color in CIE XY color model.
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
#cct ⇒ QuantityType (readonly)
Returns The correlated color temperature in Kelvin.
194 195 196 |
# File 'lib/openhab/core/types/hsb_type.rb', line 194 def cct ColorUtil.xy_to_kelvin(to_xy[0..1].map { |x| x.double_value / 100 }) | "K" end |
#duv ⇒ Float (readonly)
Returns The delta u, v.
207 208 209 |
# File 'lib/openhab/core/types/hsb_type.rb', line 207 def duv ColorUtil.xy_to_duv(to_xy[0..1].map { |x| x.double_value / 100 }) end |
#hue ⇒ QuantityType (readonly)
Returns The color's hue component as a QuantityType of unit DEGREE_ANGLE.
138 139 140 |
# File 'lib/openhab/core/types/hsb_type.rb', line 138 def hue QuantityType.new(raw_hue.to_big_decimal, Units::DEGREE_ANGLE) end |
Class Method Details
.from_cct(cct) ⇒ HSBType
Create HSBType from a color temperature
107 108 109 |
# File 'lib/openhab/core/types/hsb_type.rb', line 107 def from_cct(cct) from_xy(*ColorUtil.kelvin_to_xy((cct | "K").double_value)) end |
.from_hsb(hue, saturation, brightness) ⇒ HSBType
Create HSBType from hue, saturation, and brightness values
57 58 59 |
# File 'lib/openhab/core/types/hsb_type.rb', line 57 def from_hsb(hue, saturation, brightness) new(hue, saturation, brightness) end |
.from_rgb(r, g, b) ⇒ HSBType
Create HSBType from RGB values
|
# File 'lib/openhab/core/types/hsb_type.rb', line 39
|
.from_xy(x, y) ⇒ HSBType
Create HSBType representing the provided xy color values in CIE XY color model
|
# File 'lib/openhab/core/types/hsb_type.rb', line 46
|
Instance Method Details
#<=>(other) ⇒ Integer?
Comparison
123 124 125 126 127 128 129 130 |
# File 'lib/openhab/core/types/hsb_type.rb', line 123 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 |
#argb ⇒ Integer
Convert to a packed 32-bit RGB value representing the color in the default sRGB color model.
The alpha component is always 100%.
147 |
# File 'lib/openhab/core/types/hsb_type.rb', line 147 alias_method :argb, :rgb |
#planckian?(duv_tolerance: 0.015, maximum_saturation: 75) ⇒ true, false Also known as: white_cct?
The parameters and defaults for this method are subject to change in future releases of this library, and should be considered beta. For now, the default parameters should be sufficient to detect most colors that Apple's HomeKit color temperature color chooser uses as planckian, without detecting most other "real" colors as planckian.
Checks if this color is within a certain tolerance of the planckian locus ("white")
228 229 230 |
# File 'lib/openhab/core/types/hsb_type.rb', line 228 def planckian?(duv_tolerance: 0.015, maximum_saturation: 75) duv.abs < duv_tolerance && saturation < maximum_saturation end |
#planckian_cct(range: nil, **kwargs) ⇒ QuantityType? Also known as: white_cct
Additional parameters are forwarded to #planckian?
Returns the color temperature of this color if it is within a certain tolerance
of the planckian locus ("white"), otherwise returns nil
.
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/openhab/core/types/hsb_type.rb', line 247 def planckian_cct(range: nil, **kwargs) return unless planckian?(**kwargs) range = range.range if range.is_a?(NumberItem) cct = self.cct if range range_type = range.begin || range.end if !range_type.is_a?(QuantityType) range = Range.new(range.begin | "K", range.end | "K") elsif range_type.unit == Units::MIRED cct |= Units::MIRED end end return nil if range && !range.cover?(cct) cct end |
#rgb ⇒ Integer
Convert to a packed 24-bit RGB value representing the color in the default sRGB color model.
151 152 153 |
# File 'lib/openhab/core/types/hsb_type.rb', line 151 def rgb argb & 0xffffff end |
#to_hex ⇒ String
Convert to an HTML-style string of 6 hex characters in the default sRGB color model.
157 158 159 |
# File 'lib/openhab/core/types/hsb_type.rb', line 157 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 182
|
#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 186
|