package alamo import ( "context" "time" ) const testMAC = "fc610e7f98aa" type fakeGateway struct { states []State starts []time.Time actions []Action err error delay time.Duration } func (g *fakeGateway) Status(ctx context.Context) ([]State, error) { err := g.request(ctx) if err != nil { return nil, err } return append([]State(nil), g.states...), nil } func (g *fakeGateway) Action(ctx context.Context, mac string, action Action) (State, error) { err := g.request(ctx) if err != nil { return State{}, err } g.actions = append(g.actions, action) for index := range g.states { state := &g.states[index] if state.MAC != mac { continue } if action.Power != nil { state.Power = *action.Power } if action.TargetTemperature != nil { state.TargetTemperature = *action.TargetTemperature } return *state, nil } return State{}, nil } func (g *fakeGateway) request(ctx context.Context) error { g.starts = append(g.starts, time.Now()) if g.delay > 0 { timer := time.NewTimer(g.delay) defer timer.Stop() select { case <-ctx.Done(): return ctx.Err() case <-timer.C: } } return g.err } func testState() State { return State{ MAC: testMAC, TargetTemperature: 20, CurrentTemperature: 19.5, FloorTemperature: 23, } }