10 gatewayRequestInterval = 6 * time.Second
11 gatewayExchangeTimeout = 5 * time.Second
19 func (g *gateway) status(ctx context.Context) ([]State, error) {
22 return nil, fmt.Errorf("wait for status slot: %w", err)
25 ctx, cancel := context.WithTimeout(ctx, gatewayExchangeTimeout)
28 states, err := g.client.Status(ctx)
30 return nil, fmt.Errorf("read gateway status: %w", err)
36 func (g *gateway) wait(ctx context.Context) error {
42 delay := time.Until(g.nextStart)
44 timer := time.NewTimer(delay)
59 deadline, exists := ctx.Deadline()
60 if exists && !time.Now().Before(deadline) {
61 return context.DeadlineExceeded
64 g.nextStart = time.Now().Add(gatewayRequestInterval)
69 func (g *gateway) action(ctx context.Context, mac string, action Action) (State, error) {
72 return State{}, fmt.Errorf("wait for action slot: %w", err)
75 ctx, cancel := context.WithTimeout(ctx, gatewayExchangeTimeout)
78 state, err := g.client.Action(ctx, mac, action)
80 return State{}, fmt.Errorf("exchange gateway action: %w", err)