Add KeepAlive duration to IaR struct and update related functionality; remove obsolete test file
All checks were successful
Golan Testing / testing (1.25.x, ubuntu-latest) (push) Successful in 24s
All checks were successful
Golan Testing / testing (1.25.x, ubuntu-latest) (push) Successful in 24s
This commit is contained in:
@@ -41,6 +41,7 @@ type IaR struct {
|
||||
PagerGroupID string
|
||||
PagerGroupName string
|
||||
Type string
|
||||
KeepAlive time.Duration
|
||||
}
|
||||
|
||||
// New function creates a New MySubaru API client
|
||||
@@ -52,6 +53,7 @@ func New(credentials *config.Credentials, logger *slog.Logger) (*Client, error)
|
||||
PagerGroupID: "",
|
||||
PagerGroupName: "",
|
||||
Type: "",
|
||||
KeepAlive: 15 * time.Minute,
|
||||
},
|
||||
isAlive: false,
|
||||
logger: logger,
|
||||
@@ -86,6 +88,7 @@ func (c *Client) KeepAlive() error {
|
||||
c.IAR.PagerGroupID = pg.ID
|
||||
c.IAR.PagerGroupName = pg.Name
|
||||
c.IAR.Type = pg.Type
|
||||
c.IAR.KeepAlive = time.Duration(resp.Data.GetTTDSetting.KeyValue) * time.Second
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -118,11 +121,11 @@ func (c *Client) Alert(audioBase64 string) error {
|
||||
}
|
||||
|
||||
// ServeKeepAlive starts a goroutine that sends keep-alive requests at the specified interval.
|
||||
func (c *Client) ServeKeepAlive(ctx context.Context, interval time.Duration) {
|
||||
ticker := time.NewTicker(interval)
|
||||
func (c *Client) ServeKeepAlive(ctx context.Context) {
|
||||
ticker := time.NewTicker(c.IAR.KeepAlive)
|
||||
defer ticker.Stop()
|
||||
|
||||
slog.Info("Starting keep-alive sender", "interval", interval)
|
||||
slog.Info("Starting keep-alive sender", slog.Duration("interval", c.IAR.KeepAlive))
|
||||
|
||||
for {
|
||||
select {
|
||||
|
Reference in New Issue
Block a user