Skip to content

Commit

Permalink
Add charge/discharge requests
Browse files Browse the repository at this point in the history
  • Loading branch information
ledermann committed Dec 9, 2023
1 parent 47881ba commit 1b921a3
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/senec/local/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions lib/senec/local/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 30 additions & 0 deletions spec/lib/senec/local/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
37 changes: 37 additions & 0 deletions spec/support/cassettes/local/request-allow-discharge.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions spec/support/cassettes/local/request-safety-charge.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1b921a3

Please sign in to comment.