Class: ESPHome::Entities::Light
- Inherits:
-
ESPHome::Entity
- Object
- ESPHome::Entity
- ESPHome::Entities::Light
- Includes:
- HasState
- Defined in:
- lib/esphome/entities/light.rb
Instance Attribute Summary collapse
-
#blue ⇒ Object
readonly
Returns the value of attribute blue.
-
#brightness ⇒ Object
readonly
Returns the value of attribute brightness.
-
#cold_white ⇒ Object
readonly
Returns the value of attribute cold_white.
-
#color_brightness ⇒ Object
readonly
Returns the value of attribute color_brightness.
-
#color_mode ⇒ Object
readonly
Returns the value of attribute color_mode.
-
#color_temperature ⇒ Object
readonly
Returns the value of attribute color_temperature.
-
#effect ⇒ Object
readonly
Returns the value of attribute effect.
-
#effects ⇒ Object
readonly
Returns the value of attribute effects.
-
#flash_effect ⇒ Object
readonly
Returns the value of attribute flash_effect.
-
#green ⇒ Object
readonly
Returns the value of attribute green.
-
#mireds_range ⇒ Object
readonly
Returns the value of attribute mireds_range.
-
#red ⇒ Object
readonly
Returns the value of attribute red.
-
#supported_color_modes ⇒ Object
readonly
Returns the value of attribute supported_color_modes.
-
#transition_length ⇒ Object
readonly
Returns the value of attribute transition_length.
-
#warm_white ⇒ Object
readonly
Returns the value of attribute warm_white.
-
#white ⇒ Object
readonly
Returns the value of attribute white.
Attributes inherited from ESPHome::Entity
#device, #disabled_by_default, #entity_category, #icon, #key, #name, #object_id_
Instance Method Summary collapse
- #brightness? ⇒ Boolean
- #color_temperature? ⇒ Boolean
- #formatted_state ⇒ Object
-
#initialize(_device, list_entities_response) ⇒ Light
constructor
A new instance of Light.
- #rgb? ⇒ Boolean
- #update(state_response) ⇒ Object
- #white? ⇒ Boolean
- #ww? ⇒ Boolean
Methods inherited from ESPHome::Entity
Constructor Details
#initialize(_device, list_entities_response) ⇒ Light
Returns a new instance of Light.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/esphome/entities/light.rb', line 25 def initialize(_device, list_entities_response) super @supported_color_modes = list_entities_response.supported_color_modes.map { |mode| mode[11..].downcase.to_sym } if @supported_color_modes.empty? @supported_color_modes << :brightness if list_entities_response.legacy_supports_brightness @supported_color_modes << :rgb if list_entities_response.legacy_supports_rgb @supported_color_modes << :white if list_entities_response.legacy_supports_white @supported_color_modes << :color_temperature if list_entities_response.legacy_supports_color_temperature @supported_color_modes = [:on_off] if @supported_color_modes.empty? end @supported_color_modes = @supported_color_modes.to_set { |mode| transform_color_mode(mode) }.freeze @mireds_range = Range.new(list_entities_response.min_mireds, list_entities_response.max_mireds) @effects = list_entities_response.effects.map(&:freeze).freeze @brightness = @color_temperature = @red = @green = @blue = @white = @cold_white = @warm_white = nil end |
Instance Attribute Details
#blue ⇒ Object (readonly)
Returns the value of attribute blue.
8 9 10 |
# File 'lib/esphome/entities/light.rb', line 8 def blue @blue end |
#brightness ⇒ Object (readonly)
Returns the value of attribute brightness.
8 9 10 |
# File 'lib/esphome/entities/light.rb', line 8 def brightness @brightness end |
#cold_white ⇒ Object (readonly)
Returns the value of attribute cold_white.
8 9 10 |
# File 'lib/esphome/entities/light.rb', line 8 def cold_white @cold_white end |
#color_brightness ⇒ Object (readonly)
Returns the value of attribute color_brightness.
8 9 10 |
# File 'lib/esphome/entities/light.rb', line 8 def color_brightness @color_brightness end |
#color_mode ⇒ Object (readonly)
Returns the value of attribute color_mode.
8 9 10 |
# File 'lib/esphome/entities/light.rb', line 8 def color_mode @color_mode end |
#color_temperature ⇒ Object (readonly)
Returns the value of attribute color_temperature.
8 9 10 |
# File 'lib/esphome/entities/light.rb', line 8 def color_temperature @color_temperature end |
#effect ⇒ Object (readonly)
Returns the value of attribute effect.
8 9 10 |
# File 'lib/esphome/entities/light.rb', line 8 def effect @effect end |
#effects ⇒ Object (readonly)
Returns the value of attribute effects.
8 9 10 |
# File 'lib/esphome/entities/light.rb', line 8 def effects @effects end |
#flash_effect ⇒ Object (readonly)
Returns the value of attribute flash_effect.
8 9 10 |
# File 'lib/esphome/entities/light.rb', line 8 def flash_effect @flash_effect end |
#green ⇒ Object (readonly)
Returns the value of attribute green.
8 9 10 |
# File 'lib/esphome/entities/light.rb', line 8 def green @green end |
#mireds_range ⇒ Object (readonly)
Returns the value of attribute mireds_range.
8 9 10 |
# File 'lib/esphome/entities/light.rb', line 8 def mireds_range @mireds_range end |
#red ⇒ Object (readonly)
Returns the value of attribute red.
8 9 10 |
# File 'lib/esphome/entities/light.rb', line 8 def red @red end |
#supported_color_modes ⇒ Object (readonly)
Returns the value of attribute supported_color_modes.
8 9 10 |
# File 'lib/esphome/entities/light.rb', line 8 def supported_color_modes @supported_color_modes end |
#transition_length ⇒ Object (readonly)
Returns the value of attribute transition_length.
8 9 10 |
# File 'lib/esphome/entities/light.rb', line 8 def transition_length @transition_length end |
#warm_white ⇒ Object (readonly)
Returns the value of attribute warm_white.
8 9 10 |
# File 'lib/esphome/entities/light.rb', line 8 def warm_white @warm_white end |
#white ⇒ Object (readonly)
Returns the value of attribute white.
8 9 10 |
# File 'lib/esphome/entities/light.rb', line 8 def white @white end |
Instance Method Details
#brightness? ⇒ Boolean
45 46 47 |
# File 'lib/esphome/entities/light.rb', line 45 def brightness? @supported_color_modes.include?(:brightness) end |
#color_temperature? ⇒ Boolean
57 58 59 |
# File 'lib/esphome/entities/light.rb', line 57 def color_temperature? @supported_color_modes.intersect?(%i[color_temperature rgb_color_temperature]) end |
#formatted_state ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/esphome/entities/light.rb', line 84 def formatted_state result = case state when nil then "-" when true then "on" else "off" end result += " #{brightness || color_brightness || "-"}%" if brightness? if effect result += effect else result += " #{color_temperature || "-"} mired" if color_temperature? color = [] color.push(red, green, blue) if rgb? color.push(white) if white? color.push(cold_white, warm_white) if ww? result += " (#{color.map { |c| c || "-" }.join(",")})" unless color.empty? end result += " @ #{transition_length} ms" if transition_length result += " (flash)" if flash_effect result end |
#rgb? ⇒ Boolean
53 54 55 |
# File 'lib/esphome/entities/light.rb', line 53 def rgb? @supported_color_modes.intersect?(%i[rgb rgbw rgb_color_temperature rgbww]) end |
#update(state_response) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/esphome/entities/light.rb', line 65 def update(state_response) @state = state_response.state @brightness = state_response.brightness if brightness? @color_mode = state_response.color_mode if rgb? @color_brightness = state_response.color_brightness @red = state_response.red @green = state_response.green @blue = state_response.blue end @white = state_response.white if white? @color_temperature = state_response.color_temperature if color_temperature? if ww? @cold_white = state_response.cold_white @warm_white = state_response.warm_white end @effect = state_response.effect.empty? ? nil : state_response.effect end |
#white? ⇒ Boolean
49 50 51 |
# File 'lib/esphome/entities/light.rb', line 49 def white? @supported_color_modes.intersect?(%i[white ww rgbw rgbww]) end |
#ww? ⇒ Boolean
61 62 63 |
# File 'lib/esphome/entities/light.rb', line 61 def ww? @supported_color_modes.intersect?(%i[ww rgbww]) end |