Skip to content

Commit 21d934f

Browse files
introduce secretsService to mock includes for CI builds
1 parent a211b1f commit 21d934f

File tree

5 files changed

+35
-31
lines changed

5 files changed

+35
-31
lines changed

src/inputs/telegram.h

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66

77
// Telegram Bot is technically a connector, especially with admin notifications. Might want to rename it.
88

9-
#include "secrets.h"
9+
#include "shared/secretsService.h"
1010
#include "shared/serialWrapper.h"
1111
#include <Arduino.h>
12+
#include <SafeString.h>
1213
#include <UniversalTelegramBot.h> // https://github.com/witnessmenow/Universal-Arduino-Telegram-Bot
1314
#include <WiFiClientSecure.h>
14-
#include <SafeString.h>
1515

1616
namespace Input_Telegram {
1717

@@ -36,8 +36,7 @@ void logMsg(const telegramMessage& msg) {
3636
}
3737

3838
void sendModeKeyboard(const String& chat_id) {
39-
bot.sendMessageWithReplyKeyboard(chat_id, F("Choose a command: "), "",
40-
F("[[\"/off\",\"/on\"], \"/clock\"]"), true);
39+
bot.sendMessageWithReplyKeyboard(chat_id, F("Choose a command: "), "", F("[[\"/off\",\"/on\"], \"/clock\"]"), true);
4140
}
4241

4342
void displayPairingKey() {
@@ -47,8 +46,7 @@ void displayPairingKey() {
4746
}
4847

4948
void pairUser(const String& chat_id) {
50-
if (iPairs >= N_MAX_PAIRED)
51-
iPairs -= N_MAX_PAIRED;
49+
if (iPairs >= N_MAX_PAIRED) iPairs -= N_MAX_PAIRED;
5250
// add to Set of IDs
5351
pairedKeys[iPairs++] = chat_id.c_str();
5452
}
@@ -58,27 +56,22 @@ bool isPaired(const String& chat_id) {
5856
for (const char* i : pairedKeys) {
5957
printRaw(i);
6058
println(F(", "));
61-
if (chat_id.equals(i))
62-
return true;
59+
if (chat_id.equals(i)) return true;
6360
}
6461
return false;
6562
}
6663

6764
void handleCommand(const String& chat_id, SafeString& cmd, SafeString& param1, SafeString& param2) {
6865
if (cmd == "/pair") {
69-
if (param1.isEmpty()) {
70-
bot.sendMessage(chat_id, F("Missing key, I expect \"/pair KEY\""));
71-
}
66+
if (param1.isEmpty()) { bot.sendMessage(chat_id, F("Missing key, I expect \"/pair KEY\"")); }
7267
if (param1 != pairingKey) {
7368
bot.sendMessage(chat_id, F("Sorry, that's not my key"));
7469
return;
7570
}
7671
pairUser(chat_id);
7772
bot.sendMessage(chat_id, F("Paired successfully!"));
7873
} else if (!isPaired(chat_id)) {
79-
bot.sendMessage(
80-
chat_id,
81-
F("I don't know you yet, let's pair! \nCall /pair KEY with the displayed characters"));
74+
bot.sendMessage(chat_id, F("I don't know you yet, let's pair! \nCall /pair KEY with the displayed characters"));
8275
displayPairingKey();
8376
return;
8477
}
@@ -88,9 +81,8 @@ void handleCommand(const String& chat_id, SafeString& cmd, SafeString& param1, S
8881

8982
void handleCommand(const telegramMessage& msg) {
9083
if (msg.text.startsWith("/start") || msg.text.startsWith("/help")) {
91-
bot.sendMessage(
92-
msg.chat_id,
93-
F("Hello there 👋🏼 I'm here to give you easy access to ModischMatrix functions."));
84+
bot.sendMessage(msg.chat_id,
85+
F("Hello there 👋🏼 I'm here to give you easy access to ModischMatrix functions."));
9486
// probably useless, Telegram offers native command selection now
9587
sendModeKeyboard(msg.chat_id);
9688
return;
@@ -149,9 +141,7 @@ void setup() {
149141
// secured_client.setInsecure(); // this shouldn't be necessary with active Cert
150142
bot.waitForResponse = 5 * 1000;
151143

152-
if (!bot.getMe()) {
153-
logWarning(F("T: Can't find myself!"));
154-
}
144+
if (!bot.getMe()) { logWarning(F("T: Can't find myself!")); }
155145

156146
// pairUser(T_ADMIN_ID);
157147

@@ -161,8 +151,7 @@ void setup() {
161151

162152
uint32_t t_last_poll = 0;
163153
void loop() {
164-
if (!ready)
165-
return;
154+
if (!ready) return;
166155

167156
uint32_t now = millis();
168157
if (now - t_last_poll > POLL_DELAY) {

src/main.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
#include <Arduino.h>
2-
//#include <loopTimer.h> // part of SafeStrings
32

43
#define DEBUG
54

6-
#ifdef CI_BUILD
7-
#pragma message "-- CI Build --"
8-
#endif
9-
105
#include "pinout.h"
116

127
#include "shared/fileServer.h"
@@ -63,16 +58,15 @@ void setup() {
6358
void loop() {
6459
TimeService::loop();
6560
WeatherService::loop();
61+
6662
Input_Touch::loop();
63+
// Input_Telegram::loop();
6764
Controller::loop();
6865

6966
PersistenceManager::loop();
7067

71-
// Input_Telegram::loop();
72-
7368
RebootManager::loop();
7469

75-
// loopTimer.check(Serial);
7670
// heartbeatSerial();
7771
delay(1);
7872
}

src/secrets_template.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#pragma once
2+
3+
// COPY, FILL WITH YOUR VALUES AND RENAME TO "secrets.h"
4+
5+
const char OWM_LOCATION_KEY[] = "69420,TW"; // Postcode, ISO 3166 Country ID
6+
const char OWM_API_KEY[] = "lbilgu453l345g232vj432mj4f2"; // get from https://openweathermap.org/
7+
8+
// disabled for now, but might be reactivated eventually
9+
//const char T_BOT_TOKEN[] = "457654:ibfeaililuafilhafli"; // ask @BotFather
10+
//const char T_ADMIN_ID[] = "872392349"; // Telegram user account

src/shared/secretsService.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#pragma once
2+
3+
// pun intended.
4+
5+
// CI and other pipelines need something to work with, using the template should be fine.
6+
#ifdef CI_BUILD
7+
#pragma message(-- CI Build, mocking secrets --)
8+
#include "secrets_template.h"
9+
#else
10+
#include "secrets.h"
11+
#endif

src/shared/weatherService.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#include "secrets.h"
3+
#include "shared/secretsService.h"
44
#include "shared/serialWrapper.h"
55
#include <ArduinoJson.h>
66
#include <HTTPClient.h>

0 commit comments

Comments
 (0)