Class: AlphaEss

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

Constant Summary collapse

AUTHPREFIX =
"al8e4s"
AUTHCONSTANT =
"LS885ZYDA95JVFQKUIUUUV7PQNODZRDZIS4ERREDS0EED8BCWSS"
AUTHSUFFIX =
"ui893ed"

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.



10
11
12
13
# File 'lib/alpha_ess.rb', line 10

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



45
46
47
48
49
# File 'lib/alpha_ess.rb', line 45

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



28
29
30
31
32
33
34
35
36
37
# File 'lib/alpha_ess.rb', line 28

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

#get_stics_by_dayObject



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/alpha_ess.rb', line 15

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



39
40
41
42
43
# File 'lib/alpha_ess.rb', line 39

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

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



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

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



51
52
53
54
55
56
# File 'lib/alpha_ess.rb', line 51

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