Class: AlphaEss

Inherits:
Object
  • Object
show all
Defined in:
lib/alpha_ess.rb

Instance Method Summary collapse

Constructor Details

#initialize(sn = ENV["ess_serial"], u = ENV["ess_username"], p = ENV["ess_password"]) ⇒ AlphaEss

Returns a new instance of AlphaEss.



5
6
7
8
# File 'lib/alpha_ess.rb', line 5

def initialize(sn = ENV["ess_serial"], u = ENV["ess_username"], p = ENV["ess_password"])
    @serial, @username, @password = sn, u, p
    get_token()
end

Instance Method Details

#get_custom_use_ess_settingObject



47
48
49
50
51
# File 'lib/alpha_ess.rb', line 47

def get_custom_use_ess_setting()
    url = "https://cloud.alphaess.com/api/Account/GetCustomUseESSSetting"
    res = HTTParty.get(url, headers: header())
    res.parsed_response["data"]
end

#get_last_power_dataObject



23
24
25
26
27
28
29
30
31
# File 'lib/alpha_ess.rb', line 23

def get_last_power_data()
    body = {
        "sys_sn" => @serial,
        "noLoading" => true
    }
    url = "https://cloud.alphaess.com/api/ESS/GetLastPowerDataBySN"
    res = HTTParty.post(url, headers: header(), body: body.to_json)
    res.parsed_response["data"]
end

#get_stics_by_dayObject



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/alpha_ess.rb', line 10

def get_stics_by_day()
    body = {
        "sn" => @serial,
        "userId" => @serial,
        "szDay" => Time.now.strftime("%Y-%m-%d"),
        "isOEM" => 0,
        "sDate" => Time.now.strftime("%Y-%m-%d")
    }
    url = "https://cloud.alphaess.com/api/Power/SticsByDay"
    res = HTTParty.post(url, headers: header(), body: body.to_json)
    res.parsed_response["data"]
end

#get_stics_by_period(beginDay = Time.now.strftime("%Y-%m-%d"), endDay = Time.now.strftime("%Y-%m-%d")) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/alpha_ess.rb', line 33

def get_stics_by_period(beginDay = Time.now.strftime("%Y-%m-%d"), endDay = Time.now.strftime("%Y-%m-%d"))
    body = {
        "beginDay" => beginDay,
        "endDay" => endDay,
        "tday" => Time.now.strftime("%Y-%m-%d"),
        "isOEM" => 0,
        "SN" => @serial,
        "noLoading" => true
    }
    url = "https://cloud.alphaess.com/api/Power/SticsByPeriod"
    res = HTTParty.post(url, headers: header(), body: body.to_json)
    res.parsed_response["data"]
end

#send_pushover_alarm_by_soc(message, po_user = ENV["po_user"], po_token = ENV["po_token"]) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/alpha_ess.rb', line 60

def send_pushover_alarm_by_soc(message, po_user = ENV["po_user"], po_token = ENV["po_token"])
    # po_user: pushover username
    # po_token: pushover token
    body = {
        "user" => po_user,
        "token" => po_token,
        "message" => message
    }
    url = "https://api.pushover.net/1/messages.json"
    res = HTTParty.post(url, headers: {
        "Content-Type" => "application/json;charset=UTF-8"
    }, body: body.to_json)
end

#set_custom_use_ess_setting(hash = {}) ⇒ Object



53
54
55
56
57
58
# File 'lib/alpha_ess.rb', line 53

def set_custom_use_ess_setting(hash={})
    data = self.get_custom_use_ess_setting
    data.update(hash)
    url = "https://cloud.alphaess.com/api/Account/CustomUseESSSetting"
    res = HTTParty.post(url, headers: header(), body: data.to_json)
end