Class: SmaApi::Client
- Inherits:
-
Object
- Object
- SmaApi::Client
- Defined in:
- lib/sma_api/client.rb
Overview
Ruby client for communicating with SMA Inverter web interface
Instance Method Summary collapse
-
#destroy_session ⇒ String
Logout and clear the session.
-
#download(path, target) ⇒ Object
Download the file specified by url and store it in a file on the local file system.
-
#get_fs(path) ⇒ Array
Retrieve list of files and directories for the path.
-
#get_values(keys) ⇒ Hash
Retrieve values specified by the keys using getValues.json endpoint.
-
#initialize(host:, password:, sid: nil) ⇒ Client
constructor
A new instance of Client.
-
#object_metadata ⇒ Array
ObjectMetadata_Istl endpoint.
-
#sid ⇒ String
The current session id.
Constructor Details
Instance Method Details
#destroy_session ⇒ String
Logout and clear the session. This is the same as using Logout from the web interface
22 23 24 |
# File 'lib/sma_api/client.rb', line 22 def destroy_session @client.destroy_session end |
#download(path, target) ⇒ Object
Download the file specified by url and store it in a file on the local file system.
60 61 62 |
# File 'lib/sma_api/client.rb', line 60 def download(path, target) @client.download(path, target) end |
#get_fs(path) ⇒ Array
Retrieve list of files and directories for the path.
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/sma_api/client.rb', line 42 def get_fs(path) result = @client.post('/dyn/getFS.json', { destDev: [], path: }) result['result'].first[1][path].map do |f| type = f.key?('f') ? 'f' : 'd' { name: f['d'] || f['f'], type:, last_modified: Time.at(f['tm']), size: f['s'] } end end |
#get_values(keys) ⇒ Hash
Retrieve values specified by the keys using getValues.json endpoint.
30 31 32 33 34 35 36 37 |
# File 'lib/sma_api/client.rb', line 30 def get_values(keys) result = @client.post('/dyn/getValues.json', { destDev: [], keys: }) return nil unless result['result'] keys.each_with_object({}) do |k, h| h[k] = get_value(k, result) end end |
#object_metadata ⇒ Array
ObjectMetadata_Istl endpoint
67 68 69 |
# File 'lib/sma_api/client.rb', line 67 def @client.post('/data/ObjectMetadata_Istl.json') end |
#sid ⇒ String
The current session id. If empty, it will create a new session
15 16 17 |
# File 'lib/sma_api/client.rb', line 15 def sid @client.sid end |