Class: ESPHome::Entities::Fan
- Inherits:
-
ESPHome::Entity
- Object
- ESPHome::Entity
- ESPHome::Entities::Fan
- Includes:
- HasState
- Defined in:
- lib/esphome/entities/fan.rb
Instance Attribute Summary collapse
-
#direction ⇒ Object
readonly
Returns the value of attribute direction.
-
#preset_mode ⇒ Object
readonly
Returns the value of attribute preset_mode.
-
#preset_modes ⇒ Object
readonly
Returns the value of attribute preset_modes.
-
#speed ⇒ Object
readonly
Returns the value of attribute speed.
-
#speed_count ⇒ Object
readonly
Returns the value of attribute speed_count.
Attributes inherited from ESPHome::Entity
#device, #disabled_by_default, #entity_category, #icon, #key, #name, #object_id_
Instance Method Summary collapse
- #formatted_state ⇒ Object
-
#initialize(_device, list_entities_response) ⇒ Fan
constructor
A new instance of Fan.
- #oscillating? ⇒ Boolean
- #oscillation? ⇒ Boolean
- #speed? ⇒ Boolean
- #update(state_response) ⇒ Object
Methods inherited from ESPHome::Entity
Constructor Details
#initialize(_device, list_entities_response) ⇒ Fan
Returns a new instance of Fan.
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/esphome/entities/fan.rb', line 14 def initialize(_device, list_entities_response) super @supports_oscillation = list_entities_response.supports_oscillation @supports_speed = list_entities_response.supports_speed @speed_count = list_entities_response.supported_speed_count if speed? @speed_count = 3 if speed_count.zero? && speed? @preset_modes = list_entities_response.supported_preset_modes.map(&:freeze).freeze @oscillating = @speed = @direction = @preset_mode = nil end |
Instance Attribute Details
#direction ⇒ Object (readonly)
Returns the value of attribute direction.
8 9 10 |
# File 'lib/esphome/entities/fan.rb', line 8 def direction @direction end |
#preset_mode ⇒ Object (readonly)
Returns the value of attribute preset_mode.
8 9 10 |
# File 'lib/esphome/entities/fan.rb', line 8 def preset_mode @preset_mode end |
#preset_modes ⇒ Object (readonly)
Returns the value of attribute preset_modes.
8 9 10 |
# File 'lib/esphome/entities/fan.rb', line 8 def preset_modes @preset_modes end |
#speed ⇒ Object (readonly)
Returns the value of attribute speed.
8 9 10 |
# File 'lib/esphome/entities/fan.rb', line 8 def speed @speed end |
#speed_count ⇒ Object (readonly)
Returns the value of attribute speed_count.
8 9 10 |
# File 'lib/esphome/entities/fan.rb', line 8 def speed_count @speed_count end |
Instance Method Details
#formatted_state ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/esphome/entities/fan.rb', line 38 def formatted_state result = case state when nil then "-" when true then "on" else "off" end if speed? result += if speed_count == 100 " #{speed || "-"}%" else " #{speed || "-"}/#{speed_count}" end end result += " oscillating" if oscillating? result += " reversed" if direction == :reverse result += " (#{preset_mode})" if preset_mode result end |
#oscillating? ⇒ Boolean
34 35 36 |
# File 'lib/esphome/entities/fan.rb', line 34 def oscillating? @oscillating end |
#oscillation? ⇒ Boolean
26 27 28 |
# File 'lib/esphome/entities/fan.rb', line 26 def oscillation? @supports_oscillation end |
#speed? ⇒ Boolean
30 31 32 |
# File 'lib/esphome/entities/fan.rb', line 30 def speed? @supports_speed end |
#update(state_response) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/esphome/entities/fan.rb', line 58 def update(state_response) @state = state_response.state @oscillating = state_response.oscillating @speed = state_response.speed_level if speed? && speed.nil? @speed = { FAN_SPEED_LOW: 1, FAN_SPEED_MEDIUM: 2, FAN_SPEED_HIGH: 3 }[state_response.speed] end @direction = state_response.direction[14..].downcase.to_sym @preset_mode = state_response.preset_mode.empty? ? nil : state_response.preset_mode end |