Skip to content

Commit

Permalink
Updated config to include timezone in controller initialisation
Browse files Browse the repository at this point in the history
  • Loading branch information
twystd committed May 30, 2024
1 parent 2317ef9 commit bf109fd
Show file tree
Hide file tree
Showing 6 changed files with 227 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

###
1. Added github nightly build with executable artifacts.
2. Changed default controller timezone from UTC to Local.


## [0.8.8](https://github.com/uhppoted/uhppote-cli/releases/tag/v0.8.8) - 2024-03-27
Expand Down
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ publish: release
gh release create "$(VERSION)" "./dist/uhppote-cli_$(VERSION).tar.gz" "./dist/uhppote-cli_$(VERSION).zip" --draft --prerelease --title "$(VERSION)-beta" --notes-file release-notes.md

debug: build
./bin/uhppote-cli --debug --bind 192.168.1.100:12345 get-device 405419896
./bin/uhppote-cli --debug --bind 192.168.1.100:12345 get-device 303986753
./bin/uhppote-cli --debug set-address 423187757 192.168.1.125 255.255.255.255 192.168.1.1


irl: build
Expand Down
210 changes: 210 additions & 0 deletions commands/comand_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
package commands

import (
"fmt"
"net"
"net/netip"
"os"
"reflect"
"testing"
"time"

"github.com/uhppoted/uhppote-core/types"
"github.com/uhppoted/uhppote-core/uhppote"
"github.com/uhppoted/uhppoted-lib/config"
)

func TestCommandNewContext(t *testing.T) {
LA, _ := time.LoadLocation("America/Los_Angeles")

u := stub{}
c := config.Config{
Devices: config.DeviceMap{
405419896: &config.Device{
Name: "Alpha",
Address: types.MustParseControllerAddr("192.168.1.100:60000"),
Doors: []string{"Gryffindor", "Hufflepuff", "Ravenclaw", "Slytherin"},
TimeZone: "America/Los_Angeles",
Protocol: "tcp",
},
303986753: &config.Device{
Name: "Beta",
Address: types.MustParseControllerAddr("192.168.1.100:60000"),
Doors: []string{"Great Hall", "Kitchen", "Dungeon", "Hogsmeade"},
},
},
}

expected := Context{
uhppote: &u,
config: &c,
devices: []uhppote.Device{
uhppote.Device{
Name: "Beta",
DeviceID: 303986753,
Doors: []string{"Great Hall", "Kitchen", "Dungeon", "Hogsmeade"},
Address: types.MustParseControllerAddr("192.168.1.100:60000"),
TimeZone: time.Local,
Protocol: "udp",
},
uhppote.Device{
Name: "Alpha",
DeviceID: 405419896,
Doors: []string{"Gryffindor", "Hufflepuff", "Ravenclaw", "Slytherin"},
Address: types.MustParseControllerAddr("192.168.1.100:60000"),
TimeZone: LA,
Protocol: "tcp",
},
},
debug: false,
}

ctx := NewContext(&u, &c, false)

if !reflect.DeepEqual(ctx, expected) {
t.Errorf("incorrect context\n expected:%v\n got: %v", expected, ctx)
}
}

type stub struct {
}

func (s *stub) GetDevices() ([]types.Device, error) {
return nil, fmt.Errorf("Not implemented")
}

func (s *stub) GetDevice(controller uint32) (*types.Device, error) {
return nil, fmt.Errorf("Not implemented")
}

func (s *stub) SetAddress(controller uint32, address, mask, gateway net.IP) (*types.Result, error) {
return nil, fmt.Errorf("Not implemented")
}

func (s *stub) GetTime(controller uint32) (*types.Time, error) {
return nil, fmt.Errorf("Not implemented")
}

func (s *stub) SetTime(controller uint32, datetime time.Time) (*types.Time, error) {
return nil, fmt.Errorf("Not implemented")
}

func (s *stub) GetDoorControlState(controller uint32, door byte) (*types.DoorControlState, error) {
return nil, fmt.Errorf("Not implemented")
}

func (s *stub) SetDoorControlState(controller uint32, door uint8, state types.ControlState, delay uint8) (*types.DoorControlState, error) {
return nil, fmt.Errorf("Not implemented")
}

func (s *stub) SetDoorPasscodes(controller uint32, door uint8, passcodes ...uint32) (bool, error) {
return false, fmt.Errorf("Not implemented")
}

func (s *stub) SetInterlock(controller uint32, interlock types.Interlock) (bool, error) {
return false, fmt.Errorf("Not implemented")
}

func (s *stub) ActivateKeypads(controller uint32, keypads map[uint8]bool) (bool, error) {
return false, fmt.Errorf("Not implemented")
}

func (s *stub) GetListener(controller uint32) (netip.AddrPort, error) {
return netip.AddrPort{}, fmt.Errorf("Not implemented")
}

func (s *stub) SetListener(controller uint32, address netip.AddrPort) (bool, error) {
return false, fmt.Errorf("Not implemented")
}

func (s *stub) GetStatus(controller uint32) (*types.Status, error) {
return nil, fmt.Errorf("Not implemented")
}

func (s *stub) GetCards(controller uint32) (uint32, error) {
return 0, fmt.Errorf("Not implemented")
}

func (s *stub) GetCardByIndex(controller, index uint32) (*types.Card, error) {
return nil, fmt.Errorf("Not implemented")
}

func (s *stub) GetCardByID(controller, cardID uint32) (*types.Card, error) {
return nil, fmt.Errorf("Not implemented")
}

func (s *stub) PutCard(controller uint32, card types.Card, formats ...types.CardFormat) (bool, error) {
return false, fmt.Errorf("Not implemented")
}

func (s *stub) DeleteCard(controller uint32, cardNumber uint32) (bool, error) {
return false, fmt.Errorf("Not implemented")
}

func (s *stub) DeleteCards(controller uint32) (bool, error) {
return false, fmt.Errorf("Not implemented")
}

func (s *stub) GetTimeProfile(controller uint32, profileID uint8) (*types.TimeProfile, error) {
return nil, fmt.Errorf("Not implemented")
}

func (s *stub) SetTimeProfile(controller uint32, profile types.TimeProfile) (bool, error) {
return false, fmt.Errorf("Not implemented")
}

func (s *stub) ClearTimeProfiles(controller uint32) (bool, error) {
return false, fmt.Errorf("Not implemented")
}

func (s *stub) ClearTaskList(controller uint32) (bool, error) {
return false, fmt.Errorf("Not implemented")
}

func (s *stub) AddTask(controller uint32, task types.Task) (bool, error) {
return false, fmt.Errorf("Not implemented")
}

func (s *stub) RefreshTaskList(controller uint32) (bool, error) {
return false, fmt.Errorf("Not implemented")
}

func (s *stub) RecordSpecialEvents(controller uint32, enable bool) (bool, error) {
return false, fmt.Errorf("Not implemented")
}

func (s *stub) GetEvent(controller, index uint32) (*types.Event, error) {
return nil, fmt.Errorf("Not implemented")
}

func (s *stub) GetEventIndex(controller uint32) (*types.EventIndex, error) {
return nil, fmt.Errorf("Not implemented")
}

func (s *stub) SetEventIndex(controller, index uint32) (*types.EventIndexResult, error) {
return nil, fmt.Errorf("Not implemented")
}

func (s *stub) Listen(listener uhppote.Listener, q chan os.Signal) error {
return fmt.Errorf("Not implemented")
}

func (s *stub) OpenDoor(controller uint32, door uint8) (*types.Result, error) {
return nil, fmt.Errorf("Not implemented")
}

func (s *stub) SetPCControl(controller uint32, enable bool) (bool, error) {
return false, fmt.Errorf("Not implemented")
}

func (s *stub) RestoreDefaultParameters(controller uint32) (bool, error) {
return false, fmt.Errorf("Not implemented")
}

func (s *stub) DeviceList() map[uint32]uhppote.Device {
return nil
}

func (s *stub) ListenAddrList() []netip.AddrPort {
return nil
}
10 changes: 9 additions & 1 deletion commands/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"sort"
"strconv"
"strings"
"time"

"github.com/uhppoted/uhppote-core/types"
"github.com/uhppoted/uhppote-core/uhppote"
Expand Down Expand Up @@ -36,12 +37,19 @@ func NewContext(u uhppote.IUHPPOTE, c *config.Config, debug bool) Context {
d := c.Devices[id]
address := types.ControllerAddr{}
protocol := d.Protocol
timezone := time.Local

if d.Address.IsValid() {
address = types.ControllerAddrFrom(d.Address.Addr(), d.Address.Port())
}

if device := uhppote.NewDevice(d.Name, id, address, protocol, d.Doors); device.IsValid() {
if d.TimeZone != "" {
if tz, err := time.LoadLocation(d.TimeZone); err == nil && tz != nil {
timezone = tz
}
}

if device := uhppote.NewDevice(d.Name, id, address, protocol, d.Doors, timezone); device.IsValid() {
devices = append(devices, device)
}
}
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/uhppoted/uhppote-cli
go 1.22

require (
github.com/uhppoted/uhppote-core v0.8.9-0.20240528150603-37c5df8bb47f
github.com/uhppoted/uhppoted-lib v0.8.9-0.20240528151010-a3cffa5b9381
github.com/uhppoted/uhppote-core v0.8.9-0.20240530164535-c743e72dd723
github.com/uhppoted/uhppoted-lib v0.8.9-0.20240530171621-d3485dd0b34d
)

require golang.org/x/sys v0.20.0 // indirect
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
github.com/uhppoted/uhppote-core v0.8.9-0.20240528150603-37c5df8bb47f h1:cee7NdQFQ8P+C6u1J++FFAaK+yr3aV0hHXlvIK4sXiQ=
github.com/uhppoted/uhppote-core v0.8.9-0.20240528150603-37c5df8bb47f/go.mod h1:Q+DHtT8s74efLs2b0eF20DRBUL9yBkySwaTQ+0lsEVM=
github.com/uhppoted/uhppoted-lib v0.8.9-0.20240528151010-a3cffa5b9381 h1:QuAU374rlmn9vBraZ6XbywgRLpIQw3m0yYMwj8bR8Cc=
github.com/uhppoted/uhppoted-lib v0.8.9-0.20240528151010-a3cffa5b9381/go.mod h1:Yf3cROHpYsNUX7IJWsZncCQVwyG4eppUWQEs1ST6tv0=
github.com/uhppoted/uhppote-core v0.8.9-0.20240530164535-c743e72dd723 h1:itDcd2d0Iz23IWG+Vl6kj8MqPM/mv4C097O5hUCkLYg=
github.com/uhppoted/uhppote-core v0.8.9-0.20240530164535-c743e72dd723/go.mod h1:Q+DHtT8s74efLs2b0eF20DRBUL9yBkySwaTQ+0lsEVM=
github.com/uhppoted/uhppoted-lib v0.8.9-0.20240530171621-d3485dd0b34d h1:tF9pdfTgbUfdP2tQ9/H/olYEHkXVh+aDiuq0DatcdFQ=
github.com/uhppoted/uhppoted-lib v0.8.9-0.20240530171621-d3485dd0b34d/go.mod h1:luEG0DJWxSzCTDqYkqvE+T0HP59LKDUJ4iZHGn84C6w=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=

0 comments on commit bf109fd

Please sign in to comment.