-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated config to include timezone in controller initialisation
- Loading branch information
twystd
committed
May 30, 2024
1 parent
2317ef9
commit bf109fd
Showing
6 changed files
with
227 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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= |