Class: Senec::Local::Request
- Inherits:
-
Object
- Object
- Senec::Local::Request
- Defined in:
- lib/senec/local/request.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#state_names ⇒ Object
readonly
Returns the value of attribute state_names.
Instance Method Summary collapse
- #application_version ⇒ Object
- #bat_charge_current ⇒ Object
- #bat_fuel_charge ⇒ Object
- #bat_power ⇒ Object
- #bat_voltage ⇒ Object
- #case_temp ⇒ Object
- #current_state_code ⇒ Object
- #current_state_name ⇒ Object
- #ev_connected ⇒ Object
- #get(*keys) ⇒ Object
- #grid_power ⇒ Object
- #house_power ⇒ Object
-
#initialize(connection:, body: BASIC_REQUEST, state_names: nil) ⇒ Request
constructor
A new instance of Request.
- #inverter_power ⇒ Object
- #measure_time ⇒ Object
- #mpp_power ⇒ Object
- #path ⇒ Object
- #perform! ⇒ Object
- #power_ratio ⇒ Object
- #response_duration ⇒ Object
- #wallbox_charge_power ⇒ Object
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
#body ⇒ Object (readonly)
Returns the value of attribute body.
13 14 15 |
# File 'lib/senec/local/request.rb', line 13 def body @body end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
13 14 15 |
# File 'lib/senec/local/request.rb', line 13 def connection @connection end |
#state_names ⇒ Object (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_version ⇒ Object
68 69 70 |
# File 'lib/senec/local/request.rb', line 68 def application_version get('WIZARD', 'APPLICATION_VERSION') end |
#bat_charge_current ⇒ Object
44 45 46 |
# File 'lib/senec/local/request.rb', line 44 def bat_charge_current get('ENERGY', 'GUI_BAT_DATA_CURRENT') end |
#bat_fuel_charge ⇒ Object
40 41 42 |
# File 'lib/senec/local/request.rb', line 40 def bat_fuel_charge get('ENERGY', 'GUI_BAT_DATA_FUEL_CHARGE') end |
#bat_power ⇒ Object
36 37 38 |
# File 'lib/senec/local/request.rb', line 36 def bat_power get('ENERGY', 'GUI_BAT_DATA_POWER') end |
#bat_voltage ⇒ Object
48 49 50 |
# File 'lib/senec/local/request.rb', line 48 def bat_voltage get('ENERGY', 'GUI_BAT_DATA_VOLTAGE') end |
#case_temp ⇒ Object
64 65 66 |
# File 'lib/senec/local/request.rb', line 64 def case_temp get('TEMPMEASURE', 'CASE_TEMP') end |
#current_state_code ⇒ Object
72 73 74 |
# File 'lib/senec/local/request.rb', line 72 def current_state_code get('ENERGY', 'STAT_STATE') end |
#current_state_name ⇒ Object
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_connected ⇒ Object
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.}" end |
#grid_power ⇒ Object
52 53 54 |
# File 'lib/senec/local/request.rb', line 52 def grid_power get('ENERGY', 'GUI_GRID_POW') end |
#house_power ⇒ Object
20 21 22 |
# File 'lib/senec/local/request.rb', line 20 def house_power get('ENERGY', 'GUI_HOUSE_POW') end |
#inverter_power ⇒ Object
24 25 26 |
# File 'lib/senec/local/request.rb', line 24 def inverter_power get('ENERGY', 'GUI_INVERTER_POWER') end |
#measure_time ⇒ Object
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_power ⇒ Object
28 29 30 |
# File 'lib/senec/local/request.rb', line 28 def mpp_power get('PV1', 'MPP_POWER') end |
#path ⇒ Object
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_ratio ⇒ Object
32 33 34 |
# File 'lib/senec/local/request.rb', line 32 def power_ratio get('PV1', 'POWER_RATIO') end |
#response_duration ⇒ Object
89 90 91 |
# File 'lib/senec/local/request.rb', line 89 def response_duration raw_response.env[:duration] end |
#wallbox_charge_power ⇒ Object
60 61 62 |
# File 'lib/senec/local/request.rb', line 60 def wallbox_charge_power get('WALLBOX', 'APPARENT_CHARGING_POWER') end |