Class: Senec::Local::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/senec/local/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection:, body: BASIC_REQUEST, state_names: nil) ⇒ Request

Returns a new instance of Request.



7
8
9
10
11
# File 'lib/senec/local/request.rb', line 7

def initialize(connection:, body: BASIC_REQUEST, state_names: nil)
  @connection = connection
  @body = body
  @state_names = state_names
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



13
14
15
# File 'lib/senec/local/request.rb', line 13

def body
  @body
end

#connectionObject (readonly)

Returns the value of attribute connection.



13
14
15
# File 'lib/senec/local/request.rb', line 13

def connection
  @connection
end

#state_namesObject (readonly)

Returns the value of attribute state_names.



13
14
15
# File 'lib/senec/local/request.rb', line 13

def state_names
  @state_names
end

Instance Method Details

#application_versionObject



68
69
70
# File 'lib/senec/local/request.rb', line 68

def application_version
  get('WIZARD', 'APPLICATION_VERSION')
end

#bat_charge_currentObject



44
45
46
# File 'lib/senec/local/request.rb', line 44

def bat_charge_current
  get('ENERGY', 'GUI_BAT_DATA_CURRENT')
end

#bat_fuel_chargeObject



40
41
42
# File 'lib/senec/local/request.rb', line 40

def bat_fuel_charge
  get('ENERGY', 'GUI_BAT_DATA_FUEL_CHARGE')
end

#bat_powerObject



36
37
38
# File 'lib/senec/local/request.rb', line 36

def bat_power
  get('ENERGY', 'GUI_BAT_DATA_POWER')
end

#bat_voltageObject



48
49
50
# File 'lib/senec/local/request.rb', line 48

def bat_voltage
  get('ENERGY', 'GUI_BAT_DATA_VOLTAGE')
end

#case_tempObject



64
65
66
# File 'lib/senec/local/request.rb', line 64

def case_temp
  get('TEMPMEASURE', 'CASE_TEMP')
end

#current_state_codeObject



72
73
74
# File 'lib/senec/local/request.rb', line 72

def current_state_code
  get('ENERGY', 'STAT_STATE')
end

#current_state_nameObject



76
77
78
79
80
# File 'lib/senec/local/request.rb', line 76

def current_state_name
  throw RuntimeError, 'No state names provided!' unless state_names

  state_names[current_state_code]
end

#ev_connectedObject



56
57
58
# File 'lib/senec/local/request.rb', line 56

def ev_connected
  get('WALLBOX', 'EV_CONNECTED')
end

#get(*keys) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/senec/local/request.rb', line 93

def get(*keys)
  return unless parsed_response

  value = parsed_response.dig(*keys)

  if value.is_a?(Array)
    value.map do |v|
      Value.new(v).decoded
    end
  elsif value
    Value.new(value).decoded
  else
    raise Error, "Value missing for #{keys.join('.')}"
  end
rescue Senec::Local::DecodingError => e
  raise Error, "Decoding failed for #{keys.join('.')}: #{e.message}"
end

#grid_powerObject



52
53
54
# File 'lib/senec/local/request.rb', line 52

def grid_power
  get('ENERGY', 'GUI_GRID_POW')
end

#house_powerObject



20
21
22
# File 'lib/senec/local/request.rb', line 20

def house_power
  get('ENERGY', 'GUI_HOUSE_POW')
end

#inverter_powerObject



24
25
26
# File 'lib/senec/local/request.rb', line 24

def inverter_power
  get('ENERGY', 'GUI_INVERTER_POWER')
end

#measure_timeObject



82
83
84
85
86
87
# File 'lib/senec/local/request.rb', line 82

def measure_time
  web_time = get('RTC', 'WEB_TIME')
  utc_offset = get('RTC', 'UTC_OFFSET')

  web_time - (utc_offset * 60)
end

#mpp_powerObject



28
29
30
# File 'lib/senec/local/request.rb', line 28

def mpp_power
  get('PV1', 'MPP_POWER')
end

#pathObject



111
112
113
# File 'lib/senec/local/request.rb', line 111

def path
  '/lala.cgi'
end

#perform!Object



15
16
17
18
# File 'lib/senec/local/request.rb', line 15

def perform!
  parsed_response
  true
end

#power_ratioObject



32
33
34
# File 'lib/senec/local/request.rb', line 32

def power_ratio
  get('PV1', 'POWER_RATIO')
end

#response_durationObject



89
90
91
# File 'lib/senec/local/request.rb', line 89

def response_duration
  raw_response.env[:duration]
end

#wallbox_charge_powerObject



60
61
62
# File 'lib/senec/local/request.rb', line 60

def wallbox_charge_power
  get('WALLBOX', 'APPARENT_CHARGING_POWER')
end