Skip to content

Commit

Permalink
Refactor URLs.
Browse files Browse the repository at this point in the history
  • Loading branch information
hacktobeer committed Dec 18, 2020
1 parent 5c07249 commit e5ab45d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 32 deletions.
12 changes: 6 additions & 6 deletions cloudcontrol.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (c *Client) CreateSession(token string, username string, password string, s
if server != "" {
c.Server = server
} else {
c.Server = "https://accsmart.panasonic.com/"
c.Server = pt.URLServer
}

postBody, _ := json.Marshal(map[string]string{
Expand All @@ -105,7 +105,7 @@ func (c *Client) CreateSession(token string, username string, password string, s
"password": password,
})

body, err := c.doPostRequest("auth/login", postBody)
body, err := c.doPostRequest(pt.URLLogin, postBody)
if err != nil {
return fmt.Errorf("Error: %v %s", err, body)
}
Expand All @@ -123,7 +123,7 @@ func (c *Client) CreateSession(token string, username string, password string, s

// GetGroups gets all Panasonic Control groups associated to this account
func (c *Client) GetGroups() (pt.Groups, error) {
body, err := c.doGetRequest("/device/group")
body, err := c.doGetRequest(pt.URLGroups)
if err != nil {
return pt.Groups{}, fmt.Errorf("Error: %v %s", err, body)
}
Expand Down Expand Up @@ -154,7 +154,7 @@ func (c *Client) ListDevices() ([]string, error) {

// GetDevice gets all details on a specific device
func (c *Client) GetDevice(deviceGUID string) (pt.Device, error) {
body, err := c.doGetRequest("/deviceStatus/now/" + url.QueryEscape(deviceGUID))
body, err := c.doGetRequest(pt.URLDeviceStatus + url.QueryEscape(deviceGUID))
if err != nil {
return pt.Device{}, fmt.Errorf("Error: %v %s", err, body)
}
Expand All @@ -177,7 +177,7 @@ func (c *Client) GetDeviceHistory(timeFrame int) (pt.History, error) {
"osTimezone": "+01:00",
})

body, err := c.doPostRequest("deviceHistoryData", postBody)
body, err := c.doPostRequest(pt.URLHistory, postBody)
if err != nil {
return pt.History{}, fmt.Errorf("Error: %v %s", err, body)
}
Expand All @@ -198,7 +198,7 @@ func (c *Client) control(command pt.Command) error {
log.Println("JSON to be sent:")
log.Println(string(postBody))

body, err := c.doPostRequest("deviceStatus/control", postBody)
body, err := c.doPostRequest(pt.URLControl, postBody)
if err != nil {
return fmt.Errorf("Error: %v %s", err, body)
}
Expand Down
53 changes: 27 additions & 26 deletions types/types.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
package types

// Exported constants
const (
URLServer = "https://accsmart.panasonic.com"
URLLogin = "/auth/login"
URLGroups = "/device/group"
URLDeviceStatus = "/deviceStatus/now/"
URLHistory = "/deviceHistoryData"
URLControl = "/deviceStatus/control"
)

// HistoryDataMode maps out the time intervals to fetch history data
var HistoryDataMode = map[string]int{
"day": 0,
"week": 1,
"month": 2,
"year": 3,
}

// Modes define the different AC modes the device can be in
var Modes = map[string]int{
"auto": 0,
"dry": 1,
"cool": 2,
"heat": 3,
"fan": 3,
}

// Session is a login session structure
type Session struct {
Utoken string `njson:"uToken"`
Expand Down Expand Up @@ -103,32 +130,6 @@ type HistoryEntry struct {
AverageOutsideTemp float64 `njson:"averageOutsideTemp"`
}

// HistoryDataMode maps out the time intervals to fetch history data
var HistoryDataMode = map[string]int{
"day": 0,
"week": 1,
"month": 2,
"year": 3,
}

// Exported constants
const (
ModeAuto = 0
ModeDry = 1
ModeCool = 2
ModeHeat = 3
ModeFan = 4
)

// Modes definesthe different AC modes the device can be in
var Modes = map[string]int{
"auto": 0,
"dry": 1,
"cool": 2,
"heat": 3,
"fan": 3,
}

// Command is basic command control structure
type Command struct {
DeviceGUID string `json:"deviceGuid"`
Expand Down

0 comments on commit e5ab45d

Please sign in to comment.