diff --git a/lib/senec/local/constants.rb b/lib/senec/local/constants.rb index a9735ed..7a36dd4 100644 --- a/lib/senec/local/constants.rb +++ b/lib/senec/local/constants.rb @@ -32,5 +32,27 @@ module Local APPARENT_CHARGING_POWER: '' } }.freeze + + SAFETY_CHARGE = { + ENERGY: { + SAFE_CHARGE_FORCE: 'u8_01', + SAFE_CHARGE_PROHIBIT: '', + SAFE_CHARGE_RUNNING: '', + LI_STORAGE_MODE_START: '', + LI_STORAGE_MODE_STOP: '', + LI_STORAGE_MODE_RUNNING: '' + } + }.freeze + + ALLOW_DISCHARGE = { + ENERGY: { + SAFE_CHARGE_FORCE: '', + SAFE_CHARGE_PROHIBIT: 'u8_01', + SAFE_CHARGE_RUNNING: '', + LI_STORAGE_MODE_START: '', + LI_STORAGE_MODE_STOP: '', + LI_STORAGE_MODE_RUNNING: '' + } + }.freeze end end diff --git a/lib/senec/local/request.rb b/lib/senec/local/request.rb index 7995b60..8383153 100644 --- a/lib/senec/local/request.rb +++ b/lib/senec/local/request.rb @@ -12,6 +12,11 @@ def initialize(connection:, body: BASIC_REQUEST, state_names: nil) attr_reader :connection, :body, :state_names + def perform! + parsed_response + true + end + def house_power get('ENERGY', 'GUI_HOUSE_POW') end diff --git a/spec/lib/senec/local/request_spec.rb b/spec/lib/senec/local/request_spec.rb index af5c560..84abd73 100644 --- a/spec/lib/senec/local/request_spec.rb +++ b/spec/lib/senec/local/request_spec.rb @@ -133,6 +133,36 @@ end end + context 'when safety-charge', vcr: 'local/request-safety-charge' do + subject(:request) do + described_class.new( + connection:, + body: Senec::Local::SAFETY_CHARGE, + ) + end + + describe '#perform' do + subject(:perform) { request.perform! } + + it { is_expected.to be(true) } + end + end + + context 'when allow-discharge', vcr: 'local/request-allow-discharge' do + subject(:request) do + described_class.new( + connection:, + body: Senec::Local::ALLOW_DISCHARGE, + ) + end + + describe '#perform' do + subject(:perform) { request.perform! } + + it { is_expected.to be(true) } + end + end + context 'when body is customized', vcr: 'local/request-custom' do subject(:request) do described_class.new( diff --git a/spec/support/cassettes/local/request-allow-discharge.yml b/spec/support/cassettes/local/request-allow-discharge.yml new file mode 100644 index 0000000..237c9cd --- /dev/null +++ b/spec/support/cassettes/local/request-allow-discharge.yml @@ -0,0 +1,37 @@ +--- +http_interactions: +- request: + method: post + uri: https://senec/lala.cgi + body: + encoding: UTF-8 + string: '{"ENERGY":{"SAFE_CHARGE_FORCE":"","SAFE_CHARGE_PROHIBIT":"u8_01","SAFE_CHARGE_RUNNING":"","LI_STORAGE_MODE_START":"","LI_STORAGE_MODE_STOP":"","LI_STORAGE_MODE_RUNNING":""}}' + headers: + Connection: + - keep-alive + User-Agent: + - Faraday v2.7.12 + Content-Type: + - application/x-www-form-urlencoded; charset=UTF-8 + Accept: + - application/json, text/javascript, */*; q=0.01 + response: + status: + code: 200 + message: OK + headers: + server: + - nginx/1.17.7 + date: + - Sat, 09 Dec 2023 19:08:04 GMT + content-type: + - application/json; charset=utf-8 + transfer-encoding: + - chunked + connection: + - keep-alive + body: + encoding: UTF-8 + string: '{"ENERGY":{"SAFE_CHARGE_FORCE":"u8_00","SAFE_CHARGE_PROHIBIT":"u8_01","SAFE_CHARGE_RUNNING":"u8_01","LI_STORAGE_MODE_START":"u8_00","LI_STORAGE_MODE_STOP":"u8_00","LI_STORAGE_MODE_RUNNING":"u8_00"}}' + recorded_at: Sat, 09 Dec 2023 19:08:04 GMT +recorded_with: VCR 6.2.0 diff --git a/spec/support/cassettes/local/request-safety-charge.yml b/spec/support/cassettes/local/request-safety-charge.yml new file mode 100644 index 0000000..dd60616 --- /dev/null +++ b/spec/support/cassettes/local/request-safety-charge.yml @@ -0,0 +1,37 @@ +--- +http_interactions: +- request: + method: post + uri: https://senec/lala.cgi + body: + encoding: UTF-8 + string: '{"ENERGY":{"SAFE_CHARGE_FORCE":"u8_01","SAFE_CHARGE_PROHIBIT":"","SAFE_CHARGE_RUNNING":"","LI_STORAGE_MODE_START":"","LI_STORAGE_MODE_STOP":"","LI_STORAGE_MODE_RUNNING":""}}' + headers: + Connection: + - keep-alive + User-Agent: + - Faraday v2.7.12 + Content-Type: + - application/x-www-form-urlencoded; charset=UTF-8 + Accept: + - application/json, text/javascript, */*; q=0.01 + response: + status: + code: 200 + message: OK + headers: + server: + - nginx/1.17.7 + date: + - Sat, 09 Dec 2023 19:06:15 GMT + content-type: + - application/json; charset=utf-8 + transfer-encoding: + - chunked + connection: + - keep-alive + body: + encoding: UTF-8 + string: '{"ENERGY":{"SAFE_CHARGE_FORCE":"u8_01","SAFE_CHARGE_PROHIBIT":"u8_00","SAFE_CHARGE_RUNNING":"u8_00","LI_STORAGE_MODE_START":"u8_00","LI_STORAGE_MODE_STOP":"u8_00","LI_STORAGE_MODE_RUNNING":"u8_00"}}' + recorded_at: Sat, 09 Dec 2023 19:06:15 GMT +recorded_with: VCR 6.2.0