-Add update sensor to HA. AWL search for an update every hour.
- Fixes duration in custom apps
This commit is contained in:
Stephan Mühl
2023-04-02 01:08:26 +02:00
parent 88085597d7
commit bc72069ae3
9 changed files with 38 additions and 70 deletions

View File

@@ -11,7 +11,6 @@
- Features
- [Apps](apps.md)
- [Alarm clock](alarm.md)
- [Timer](timer.md)
- [Icons](icons.md)
- [Sounds](sounds.md)
- [Hidden features](dev.md)

View File

@@ -1,31 +0,0 @@
# Timer
With AWTRIX Light, you can set a timer using MQTT. Simply send a JSON object to the topic **[PREFIX]/timer** to start a timer.
When the timer goes off, the display will show a notification, and you can dismiss the timer by pressing the middle button.
## JSON Properties
The JSON object has the following properties:
| Key | Type | Description |
| --- | ---- | ----------- |
| `hours` | number | The number of hours after midnight when the timer should be triggered. |
| `minutes` | number | The number of minutes after the hour when the timer should be triggered. |
| `seconds` | number | The number of seconds after the minute when the timer should be triggered. |
| `sound` | string | The name of the sound file (without extension) to play when the timer is triggered. |
Each value is optional, so you can set a timer for just minutes, or any combination of hours, minutes, and seconds. If you only want to start a timer in some minutes, just send the minutes.
## Example
Here's an example JSON object to start a timer for 1 hour, 30 minutes, and 10 seconds, with the sound "friends":
```json
{
"hours": 1,
"minutes": 30,
"seconds": 10,
"sound": "friends"
}
```

View File

@@ -7,7 +7,7 @@
#include <ArduinoJson.h>
#include "Dictionary.h"
#include "PeripheryManager.h"
#include "Updater.h"
#include "UpdateManager.h"
WiFiClient espClient;
uint8_t lastBrightness;
@@ -67,7 +67,7 @@ void onButtonCommand(HAButton *sender)
else if (sender == doUpdate)
{
if (UPDATE_AVAILABLE)
Updater.updateFirmware();
UpdateManager.updateFirmware();
}
}
@@ -194,7 +194,7 @@ void onMqttMessage(const char *topic, const uint8_t *payload, uint16_t length)
if (strTopic == MQTT_PREFIX + "/doupdate")
{
if (UPDATE_AVAILABLE)
Updater.updateFirmware();
UpdateManager.updateFirmware();
return;
}

View File

@@ -4,9 +4,9 @@
#include <ServerManager.h>
#include <DisplayManager.h>
#include <PeripheryManager.h>
#include <updater.h>
//#include <update.h>
#include <icons.h>
#include <Updater.h>
#include <UpdateManager.h>
String menuText;
int menuSelection;
@@ -378,9 +378,9 @@ void MenuManager_::selectButton()
#endif
case 13:
if (Updater.checkUpdate(true))
if (UpdateManager.checkUpdate(true))
{
Updater.updateFirmware();
UpdateManager.updateFirmware();
}
break;
default:

View File

@@ -9,7 +9,7 @@
#include <LittleFS.h>
#include <WiFi.h>
#include "DisplayManager.h"
#include "Updater.h"
#include "UpdateManager.h"
WebServer server(80);
FSWebServer mws(LittleFS, server);
@@ -99,7 +99,7 @@ void ServerManager_::setup()
{ mws.webserver->sendContent(DisplayManager.getStat()); });
mws.addHandler("/api/doupdate", HTTP_POST, []()
{ if (UPDATE_AVAILABLE)
Updater.updateFirmware(); mws.webserver->send(200,"OK"); });
UpdateManager.updateFirmware(); mws.webserver->send(200,"OK"); });
Serial.println("Webserver loaded");
}
mws.addHandler("/version", HTTP_GET, versionHandler);

View File

@@ -1,4 +1,4 @@
#include <Updater.h>
#include <UpdateManager.h>
#include <WiFi.h>
#include <HTTPClient.h>
#include <HTTPUpdate.h>
@@ -14,14 +14,14 @@
Ticker UpdateTicker;
// The getter for the instantiated singleton instance
Updater_ &Updater_::getInstance()
UpdateManager_ &UpdateManager_::getInstance()
{
static Updater_ instance;
static UpdateManager_ instance;
return instance;
}
// Initialize the global shared instance
Updater_ &Updater = Updater.getInstance();
UpdateManager_ &UpdateManager = UpdateManager.getInstance();
void update_started()
{
@@ -43,7 +43,7 @@ void update_error(int err)
DisplayManager.show();
}
void Updater_::updateFirmware()
void UpdateManager_::updateFirmware()
{
WiFiClientSecure client;
client.setCACert(rootCACertificate);
@@ -70,7 +70,7 @@ void Updater_::updateFirmware()
}
}
bool Updater_::checkUpdate(bool withScreen)
bool UpdateManager_::checkUpdate(bool withScreen)
{
if (withScreen)
{
@@ -143,10 +143,10 @@ bool Updater_::checkUpdate(bool withScreen)
void checkUpdateNoReturn()
{
Serial.println("Check Update");
Updater.getInstance().checkUpdate(false);
UpdateManager.getInstance().checkUpdate(false);
}
void Updater_::setup()
void UpdateManager_::setup()
{
UpdateTicker.attach(3600, checkUpdateNoReturn);
}

18
src/UpdateManager.h Normal file
View File

@@ -0,0 +1,18 @@
#ifndef UpdateManager_h
#define UpdateManager_h
#include <Arduino.h>
class UpdateManager_
{
private:
UpdateManager_() = default;
public:
static UpdateManager_ &getInstance();
void setup();
bool checkUpdate(bool);
void updateFirmware();
};
extern UpdateManager_ &UpdateManager;
#endif

View File

@@ -36,7 +36,7 @@
#include "MQTTManager.h"
#include "ServerManager.h"
#include "Globals.h"
#include "Updater.h"
#include "UpdateManager.h"
TaskHandle_t taskHandle;
volatile bool StopTask = false;
@@ -74,8 +74,8 @@ void setup()
{
MQTTManager.setup();
DisplayManager.loadNativeApps();
Updater.setup();
Updater.checkUpdate(false);
UpdateManager.setup();
UpdateManager.checkUpdate(false);
StopTask = true;
float x = 4;
while (x >= -85)

View File

@@ -1,18 +0,0 @@
#ifndef UPDATER_h
#define UPDATER_h
#include <Arduino.h>
class Updater_
{
private:
Updater_() = default;
public:
static Updater_ &getInstance();
void setup();
bool checkUpdate(bool);
void updateFirmware();
};
extern Updater_ &Updater;
#endif