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.
196 197 198 |
# File 'lib/openhab/core/types/hsb_type.rb', line 196 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.
209 210 211 |
# File 'lib/openhab/core/types/hsb_type.rb', line 209 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.
140 141 142 |
# File 'lib/openhab/core/types/hsb_type.rb', line 140 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
109 110 111 |
# File 'lib/openhab/core/types/hsb_type.rb', line 109 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
59 60 61 |
# File 'lib/openhab/core/types/hsb_type.rb', line 59 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 41
|
.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 48
|
Instance Method Details
#<=>(other) ⇒ Integer?
Comparison
125 126 127 128 129 130 131 132 |
# File 'lib/openhab/core/types/hsb_type.rb', line 125 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%.
149 |
# File 'lib/openhab/core/types/hsb_type.rb', line 149 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")
230 231 232 |
# File 'lib/openhab/core/types/hsb_type.rb', line 230 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
.
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
# File 'lib/openhab/core/types/hsb_type.rb', line 249 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.to_s == "mired" cct |= "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.
153 154 155 |
# File 'lib/openhab/core/types/hsb_type.rb', line 153 def rgb argb & 0xffffff end |
#to_hex ⇒ String
Convert to an HTML-style string of 6 hex characters in the default sRGB color model.
159 160 161 |
# File 'lib/openhab/core/types/hsb_type.rb', line 159 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 184
|
#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 188
|