Skip to content

Commit

Permalink
improved logging
Browse files Browse the repository at this point in the history
  • Loading branch information
halacs committed Feb 1, 2024
1 parent d8e01e8 commit 00cddba
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 30 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,22 @@ INFO[2024-01-31T21:09:40+01:00] Success
### Get users
```bash
$ ./dist/halsecur users list
INFO[2024-01-31T21:10:20+01:00] Users: [ID=0, Name="admin", IsAdmin=true, Groups:[]][ID=1, Name="app", IsAdmin=false, Groups:[0]]
INFO[2024-01-31T21:56:53+01:00] [{"id":0,"name":"admin","isAdmin":true,"Groups":[]},{"id":1,"name":"app","isAdmin":false,"Groups":[0]}]
```

### Get groups
```bash
$ ./dist/halsecur groups list
INFO[2024-01-31T21:10:46+01:00] Groups: ID=0 Name="garazs" Ports=[ID=0 Type=IMPULS]
INFO[2024-02-01T17:35:32+01:00] [{"id":0,"name":"garazs","ports":[{"typeName":"IMPULS","id":0,"type":1}]}]
```

### Get door status
```bash
$ ./dist/halsecur status --devicePort 0
INFO[2024-01-31T21:11:25+01:00] Transition: HmGetTransitionResponse[StateInPercent: 0, DesiredStateInPerced: 0, Error: false, AutoClose: false, DriveTime: 0, Gk: 257, Hcp: HCP[PositionOpen: false, PositionClose: true, OptionRelais: false, LightBarrier: false, Error: false, DrivingToClose: false, Driving: false, HalfOpened: false, ForecastLeadTime: false, Learned: true, NotReferenced: false], Exst: [0 0 0 0 0 0 0 0], Time: 2024-01-31 21:11:25.143422907 +0100 CET m=+1.916999818]
INFO[2024-02-01T17:34:22+01:00] Token expired. Logging in...
INFO[2024-02-01T17:34:22+01:00] Token: 0xA0A67B43
INFO[2024-02-01T17:34:24+01:00] Transition: {"StateInPercent":0,"DesiredStateInPercent":0,"Error":false,"AutoClose":false,"DriveTime":0,"Gk":257,"Hcp":{"PositionOpen":false,"PositionClose":true,"OptionRelais":false,"LightBarrier":false,"Error":false,"DrivingToClose":false,"Driving":false,"HalfOpened":false,"ForecastLeadTime":false,"Learned":true,"NotReferenced":false},"Exst":"AAAAAAAAAAA=","Time":"2024-02-01T17:34:24.794359108+01:00"}

```

### Open/close door
Expand Down
12 changes: 2 additions & 10 deletions sdk/Group.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,10 @@ func DecodeGroups(jsonStr string) (Groups, error) {
return data, nil
}

func (g *Group) String() string {
json, err := json.Marshal(g)
func (groups Groups) String() string {
json, err := json.Marshal(groups)
if err != nil {
panic(err)
}
return string(json)
}

func (groups Groups) String() string {
s := ""
for _, g := range groups {
s = s + g.String()
}
return s
}
25 changes: 13 additions & 12 deletions sdk/Port.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sdk

import (
"encoding/json"
"fmt"
)

Expand All @@ -11,12 +12,20 @@ type Port struct {
Type int `json:"type"`
}

func (p *Port) String() string {
portTypeStr, err := PortTypeToString(p.Type)
func (p *Port) MarshalJSON() ([]byte, error) {
typeName, err := PortTypeToString(p.Type)
if err != nil {
portTypeStr = fmt.Sprintf("%v", err)
return nil, err
}
return fmt.Sprintf("ID=%d Type=%s", p.ID, portTypeStr)

type Alias Port
return json.Marshal(&struct {
TypeName string `json:"typeName"`
*Alias
}{
TypeName: typeName,
Alias: (*Alias)(p),
})
}

func PortTypeToString(t int) (string, error) {
Expand Down Expand Up @@ -57,11 +66,3 @@ func PortTypeToString(t int) (string, error) {

return "", fmt.Errorf("unknown port type value: %d", t)
}

func (ports Ports) toString() string {
s := ""
for _, p := range ports {
s = s + p.String()
}
return s
}
10 changes: 5 additions & 5 deletions sdk/User.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ func (u *User) String() string {
return string(json)
}

func (users Users) String() string {
s := ""
for _, u := range users {
s = s + u.String()
func (u *Users) String() string {
json, err := json.Marshal(u)
if err != nil {
panic(err)
}
return s
return string(json)
}

0 comments on commit 00cddba

Please sign in to comment.