Class: ESPHome::Cli::Entity

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/esphome/cli/entity.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cli, entity, index) ⇒ Entity

Returns a new instance of Entity.



10
11
12
13
14
15
16
# File 'lib/esphome/cli/entity.rb', line 10

def initialize(cli, entity, index)
  super(entity)

  @cli = cli
  @index = index
  touch
end

Instance Attribute Details

#cliObject (readonly)

Returns the value of attribute cli.



8
9
10
# File 'lib/esphome/cli/entity.rb', line 8

def cli
  @cli
end

#indexObject (readonly)

Returns the value of attribute index.



8
9
10
# File 'lib/esphome/cli/entity.rb', line 8

def index
  @index
end

Instance Method Details

#move_leftObject



19
# File 'lib/esphome/cli/entity.rb', line 19

def move_left = nil

#move_rightObject



20
# File 'lib/esphome/cli/entity.rb', line 20

def move_right = nil


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/esphome/cli/entity.rb', line 22

def print(win, clear_line: true, active: false)
  row = @index + Monitor::HEADER_ROWS
  return if row >= win.maxy

  win.setpos(row, 0)
  win.clrtoeol if clear_line
  safe_addstr(win, "#{name.ljust(cli.name_width)} : ")
  print_state(win, active:)

  return unless __getobj__.is_a?(ESPHome::Entity::HasState)

  timestamp = "[#{@last_update.strftime("%H:%M:%S.%L")}]"
  return if timestamp.length >= win.maxx

  pos = [win.cury, win.curx]
  win.setpos(row, win.maxx - timestamp.length)
  safe_addstr(win, timestamp)
  win.setpos(*pos) if pos[1] < win.maxx
rescue Curses::Error
  nil
end

#touchObject



18
# File 'lib/esphome/cli/entity.rb', line 18

def touch = @last_update = Time.now