class SmaApi::Client
Ruby client for communicating with SMA Inverter web interface
Public Class Methods
# File lib/sma_api/client.rb, line 6 def initialize(host:, password:, sid: nil) @host = host @password = password @client = Http.new(host: host, password: password, sid: sid) end
Public Instance Methods
Logout and clear the session. This is the same as using Logout from the web interface
@return [String] An empty session id
# File lib/sma_api/client.rb, line 22 def destroy_session @client.destroy_session end
Download the file specified by url and store it in a file on the local file system.
@param url [String] URL without /fs prefix. It should start with a '/' @param path [String] Path of the local file
# File lib/sma_api/client.rb, line 60 def download(path, target) @client.download(path, target) end
Retrieve list of files and directories for the path.
@return [Array] List of directories and files
# File lib/sma_api/client.rb, line 42 def get_fs(path) result = @client.post('/dyn/getFS.json', { destDev: [], path: path }) result['result'].first[1][path].map do |f| type = f.key?('f') ? 'f' : 'd' { name: f['d'] || f['f'], type: type, last_modified: Time.at(f['tm']), size: f['s'] } end end
Retrieve values specified by the keys using getValues.json endpoint.
@param keys [Array<String>] List of keys @return [Hash] Key-value pairs
# File lib/sma_api/client.rb, line 30 def get_values(keys) result = @client.post('/dyn/getValues.json', { destDev: [], keys: keys }) return nil unless result['result'] keys.each_with_object({}) do |k, h| h[k] = scalar_value(result['result'].first[1][k]) end end
ObjectMetadata_Istl endpoint
@return [Array] List of available object metadata
# File lib/sma_api/client.rb, line 67 def object_metadata @client.post('/data/ObjectMetadata_Istl.json') end
The current session id. If empty, it will create a new session
@return [String] the session id that will be used in subsequent requests.
# File lib/sma_api/client.rb, line 15 def sid @client.sid end
Private Instance Methods
# File lib/sma_api/client.rb, line 73 def scalar_value(value) value['1'].first['val'] end