Class: ESPHome::Cli::Entities::Number
- Inherits:
-
Form
show all
- Defined in:
- lib/esphome/cli/entities/number.rb
Instance Attribute Summary
#cli, #index
Instance Method Summary
collapse
Methods inherited from Form
#activate, #initialize
#initialize, #move_left, #move_right, #print, #touch
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_value ⇒ Object
19
20
21
|
# File 'lib/esphome/cli/entities/number.rb', line 19
def initial_value
format("%.#{accuracy_decimals}f", state) if state
end
|
#length_range ⇒ Object
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
|
#suffix ⇒ Object
15
16
17
|
# File 'lib/esphome/cli/entities/number.rb', line 15
def suffix
unit_of_measurement
end
|