Skip to content

Commit

Permalink
[deco] now pulling mappings from the database
Browse files Browse the repository at this point in the history
  • Loading branch information
DictumMortuum committed Oct 21, 2024
1 parent 8365a16 commit a8aae1a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
28 changes: 28 additions & 0 deletions cmd/servus-deco/db.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package main

import (
"github.com/DictumMortuum/servus-extapi/pkg/db"
)

type Mapping struct {
Id int64 `json:"id"`
Mac string `json:"mac"`
Alias string `json:"alias"`
}

func getMappings() ([]Mapping, error) {
DB, err := db.DatabaseX()
if err != nil {
return nil, err
}
defer DB.Close()

rs := []Mapping{}
q := `select id, mac, alias from tdevices`
err = DB.Select(&rs, q)
if err != nil {
return nil, err
}

return rs, nil
}
17 changes: 8 additions & 9 deletions cmd/servus-deco/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ func printDevices(c *deco.Client) error {
return err
}

mappings, err := getMappings()
if err != nil {
return err
}

for _, device := range result.Result.ClientList {
var status int
if device.Online {
Expand All @@ -23,16 +28,10 @@ func printDevices(c *deco.Client) error {
status = 0
}

mappings := map[string]string{
"BC-6A-D1-28-77-A8": "Dimitris",
"56-0F-2C-A4-EC-30": "Ebelina",
"BC-6A-D1-2A-00-5D": "Theoni",
}

nickname := strings.ReplaceAll(device.Name, ",", " ")
for key, val := range mappings {
if key == device.MAC {
nickname = val
for _, mapping := range mappings {
if mapping.Mac == device.MAC {
nickname = mapping.Alias
break
}
}
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "0.0.37"
"version": "0.0.38"
}

0 comments on commit a8aae1a

Please sign in to comment.