Class: ESPHome::Cli::Entities::Number

Inherits:
Form show all
Defined in:
lib/esphome/cli/entities/number.rb

Instance Attribute Summary

Attributes inherited from ESPHome::Cli::Entity

#cli, #index

Instance Method Summary collapse

Methods inherited from Form

#activate, #initialize

Methods inherited from ESPHome::Cli::Entity

#initialize, #move_left, #move_right, #print, #touch

Constructor Details

This class inherits a constructor from ESPHome::Cli::Entities::Form

Instance Method Details

#command(value) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/esphome/cli/entities/number.rb', line 23

def command(value)
  begin
    value = Float(value)
  rescue ArgumentError
    cli.error("Invalid number: #{value}")
    return
  end

  cli.info("Setting #{object_id_} to #{formatted_state(value)}")
  set(value)
end

#initial_valueObject



19
20
21
# File 'lib/esphome/cli/entities/number.rb', line 19

def initial_value
  format("%.#{accuracy_decimals}f", state) if state
end

#length_rangeObject



9
10
11
12
13
# File 'lib/esphome/cli/entities/number.rb', line 9

def length_range
  max_length = range&.end ? range.end.to_s.length : 10
  max_length += accuracy_decimals + 1 if accuracy_decimals.positive?
  1..max_length
end

#suffixObject



15
16
17
# File 'lib/esphome/cli/entities/number.rb', line 15

def suffix
  unit_of_measurement
end