Class: Radfish::PowerInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/radfish/power_info.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ PowerInfo

Returns a new instance of PowerInfo.



7
8
9
10
# File 'lib/radfish/power_info.rb', line 7

def initialize(client)
  @client = client
  @cache = {}
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



5
6
7
# File 'lib/radfish/power_info.rb', line 5

def client
  @client
end

Instance Method Details

#allocated_wattsObject



38
39
40
# File 'lib/radfish/power_info.rb', line 38

def allocated_watts
  fetch_power_consumption[:allocated_watts] || fetch_power_consumption[:power_allocated_watts]
end

#capacity_wattsObject



34
35
36
# File 'lib/radfish/power_info.rb', line 34

def capacity_watts
  fetch_power_consumption[:capacity_watts] || fetch_power_consumption[:power_capacity_watts]
end

#cycleObject



54
55
56
# File 'lib/radfish/power_info.rb', line 54

def cycle
  @client.adapter.power_cycle
end

#keysObject



12
13
14
# File 'lib/radfish/power_info.rb', line 12

def keys
  [:state, :usage_watts, :capacity_watts, :allocated_watts, :reset_types_allowed, :psus, :on, :off, :restart, :cycle]
end

#off(force: false) ⇒ Object



46
47
48
# File 'lib/radfish/power_info.rb', line 46

def off(force: false)
  @client.adapter.power_off(force: force)
end

#onObject



42
43
44
# File 'lib/radfish/power_info.rb', line 42

def on
  @client.adapter.power_on
end

#psusObject



62
63
64
# File 'lib/radfish/power_info.rb', line 62

def psus
  @cache[:psus] ||= @client.adapter.psus
end

#reset_types_allowedObject



58
59
60
# File 'lib/radfish/power_info.rb', line 58

def reset_types_allowed
  @cache[:reset_types] ||= @client.adapter.reset_type_allowed if @client.adapter.respond_to?(:reset_type_allowed)
end

#restart(force: false) ⇒ Object



50
51
52
# File 'lib/radfish/power_info.rb', line 50

def restart(force: false)
  @client.adapter.power_restart(force: force)
end

#stateObject



24
25
26
# File 'lib/radfish/power_info.rb', line 24

def state
  fetch_power_status[:power_state] || fetch_power_status[:state]
end

#to_hObject



16
17
18
19
20
21
22
# File 'lib/radfish/power_info.rb', line 16

def to_h
  # Only include data attributes, not methods
  data_keys = [:state, :usage_watts, :capacity_watts, :allocated_watts, :reset_types_allowed, :psus]
  data_keys.each_with_object({}) do |key, hash|
    hash[key] = send(key) rescue nil
  end
end

#usage_wattsObject



28
29
30
31
32
# File 'lib/radfish/power_info.rb', line 28

def usage_watts
  fetch_power_consumption[:consumed_watts] || 
    fetch_power_consumption[:power_usage_watts] || 
    fetch_power_consumption_watts
end