2024-03-05 21:30:48 +00:00
|
|
|
package main
|
|
|
|
|
2025-01-06 20:38:43 +00:00
|
|
|
import (
|
|
|
|
"git.sr.ht/~michalr/go-satel"
|
|
|
|
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
|
|
|
)
|
2024-03-05 21:30:48 +00:00
|
|
|
|
|
|
|
func makeTestSatelEvent(changeType satel.ChangeType, index int, val bool) satel.Event {
|
|
|
|
return satel.Event{
|
|
|
|
BasicEvents: []satel.BasicEventElement{{Type: changeType, Index: index, Value: val}},
|
|
|
|
}
|
|
|
|
}
|
2025-01-06 13:55:08 +00:00
|
|
|
|
|
|
|
func makeGenericMessage(changeType satel.ChangeType, index int, val bool) GenericMessage {
|
|
|
|
return GenericMessage{[]satel.BasicEventElement{{Type: changeType, Index: index, Value: val}}}
|
|
|
|
}
|
2025-01-06 20:38:43 +00:00
|
|
|
|
|
|
|
type MockTgBotAPI struct {
|
|
|
|
messages []tgbotapi.Chattable
|
2025-01-13 19:37:50 +00:00
|
|
|
updates chan tgbotapi.Update
|
2025-01-06 20:38:43 +00:00
|
|
|
}
|
|
|
|
|
2025-01-13 22:30:34 +00:00
|
|
|
func MakeMockTgBotAPI() *MockTgBotAPI {
|
|
|
|
return &MockTgBotAPI{messages: []tgbotapi.Chattable{}, updates: make(chan tgbotapi.Update)}
|
|
|
|
}
|
|
|
|
|
2025-01-13 19:37:50 +00:00
|
|
|
func (botMock *MockTgBotAPI) Send(c tgbotapi.Chattable) (tgbotapi.Message, error) {
|
|
|
|
botMock.messages = append(botMock.messages, c)
|
2025-01-06 20:38:43 +00:00
|
|
|
return tgbotapi.Message{}, nil
|
|
|
|
}
|
|
|
|
|
2025-01-13 19:37:50 +00:00
|
|
|
func (botMock *MockTgBotAPI) GetUpdatesChan(u tgbotapi.UpdateConfig) tgbotapi.UpdatesChannel {
|
|
|
|
return botMock.updates
|
|
|
|
}
|
|
|
|
|
|
|
|
func (botMock *MockTgBotAPI) StopReceivingUpdates() { close(botMock.updates) }
|
|
|
|
|
2025-01-06 20:38:43 +00:00
|
|
|
type MockSatelNameGetter struct {
|
|
|
|
name string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self MockSatelNameGetter) GetName(devType satel.DeviceType, index byte) (*satel.NameEvent, error) {
|
|
|
|
retval := satel.NameEvent{
|
|
|
|
DevType: devType,
|
|
|
|
DevNumber: index,
|
|
|
|
DevTypeFunction: 0,
|
|
|
|
DevName: self.name,
|
|
|
|
}
|
|
|
|
return &retval, nil
|
|
|
|
}
|