Skip to content

Commit

Permalink
chore: bump version to 1.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Laxilef authored Dec 4, 2024
2 parents 1eb1056 + 43c065b commit 7efcbaa
Show file tree
Hide file tree
Showing 43 changed files with 6,517 additions and 4,134 deletions.
17 changes: 17 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const cssnano = require('cssnano');
const terser = require('gulp-terser');
const jsonminify = require('gulp-jsonminify');
const htmlmin = require('gulp-html-minifier-terser');
const replace = require('gulp-replace');

// Paths for tasks
let paths = {
Expand Down Expand Up @@ -59,6 +60,10 @@ const styles = (cb) => {
const items = paths.styles.bundles[name];

src(items)
.pipe(replace(
"{BUILD_TIME}",
Math.floor(Date.now() / 1000)
))
.pipe(postcss([
cssnano({ preset: 'advanced' })
]))
Expand All @@ -77,6 +82,10 @@ const scripts = (cb) => {
const items = paths.scripts.bundles[name];

src(items)
.pipe(replace(
"{BUILD_TIME}",
Math.floor(Date.now() / 1000)
))
.pipe(terser().on('error', console.error))
.pipe(concat(name))
.pipe(gzip({
Expand All @@ -93,6 +102,10 @@ const jsonFiles = (cb) => {
const item = paths.json[i];

src(item.src)
.pipe(replace(
"{BUILD_TIME}",
Math.floor(Date.now() / 1000)
))
.pipe(jsonminify())
.pipe(gzip({
append: true
Expand All @@ -119,6 +132,10 @@ const staticFiles = (cb) => {

const pages = () => {
return src(paths.pages.src)
.pipe(replace(
"{BUILD_TIME}",
Math.floor(Date.now() / 1000)
))
.pipe(htmlmin({
html5: true,
caseSensitive: true,
Expand Down
16 changes: 13 additions & 3 deletions lib/BufferedWebServer/BufferedWebServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ class BufferedWebServer {
free(this->buffer);
}

void send(int code, const char* contentType, JsonDocument& content, bool pretty = false) {
template <class T>
void send(int code, T contentType, const JsonVariantConst content, bool pretty = false) {
#ifdef ARDUINO_ARCH_ESP8266
if (!this->webServer->chunkedResponseModeStart(code, contentType)) {
this->webServer->send(505, F("text/html"), F("HTTP1.1 required"));
Expand Down Expand Up @@ -76,10 +77,19 @@ class BufferedWebServer {
return;
}

this->webServer->sendContent((const char*)this->buffer, this->bufferPos);
#ifdef ARDUINO_ARCH_ESP8266
::optimistic_yield(1000);
#endif

auto& client = this->webServer->client();
if (client.connected()) {
this->webServer->sendContent((const char*)this->buffer, this->bufferPos);
}

this->bufferPos = 0;

#ifdef ARDUINO_ARCH_ESP8266
::delay(0);
::optimistic_yield(1000);
#endif
}

Expand Down
60 changes: 0 additions & 60 deletions lib/CustomOpenTherm/CustomOpenTherm.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,66 +98,6 @@ class CustomOpenTherm : public OpenTherm {
));
}

bool setHeatingCh1Temp(float temperature) {
unsigned long response = this->sendRequest(buildRequest(
OpenThermMessageType::WRITE_DATA,
OpenThermMessageID::TSet,
temperatureToData(temperature)
));

return isValidResponse(response) && isValidResponseId(response, OpenThermMessageID::TSet);
}

bool setHeatingCh2Temp(float temperature) {
unsigned long response = this->sendRequest(buildRequest(
OpenThermMessageType::WRITE_DATA,
OpenThermMessageID::TsetCH2,
temperatureToData(temperature)
));

return isValidResponse(response) && isValidResponseId(response, OpenThermMessageID::TsetCH2);
}

bool setDhwTemp(float temperature) {
unsigned long response = this->sendRequest(buildRequest(
OpenThermMessageType::WRITE_DATA,
OpenThermMessageID::TdhwSet,
temperatureToData(temperature)
));

return isValidResponse(response) && isValidResponseId(response, OpenThermMessageID::TdhwSet);
}

bool setRoomSetpoint(float temperature) {
unsigned long response = this->sendRequest(buildRequest(
OpenThermMessageType::WRITE_DATA,
OpenThermMessageID::TrSet,
temperatureToData(temperature)
));

return isValidResponse(response) && isValidResponseId(response, OpenThermMessageID::TrSet);
}

bool setRoomSetpointCh2(float temperature) {
unsigned long response = this->sendRequest(buildRequest(
OpenThermMessageType::WRITE_DATA,
OpenThermMessageID::TrSetCH2,
temperatureToData(temperature)
));

return isValidResponse(response) && isValidResponseId(response, OpenThermMessageID::TrSetCH2);
}

bool setRoomTemp(float temperature) {
unsigned long response = this->sendRequest(buildRequest(
OpenThermMessageType::WRITE_DATA,
OpenThermMessageID::Tr,
temperatureToData(temperature)
));

return isValidResponse(response) && isValidResponseId(response, OpenThermMessageID::Tr);
}

bool sendBoilerReset() {
unsigned int data = 1;
data <<= 8;
Expand Down
36 changes: 30 additions & 6 deletions lib/HomeAssistantHelper/HomeAssistantHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ class HomeAssistantHelper {
return result;
}

template <class T>
String getTopic(T category, T name, char nameSeparator = '/') {
template <class CT, class NT>
String makeConfigTopic(CT category, NT name, char nameSeparator = '/') {
String topic = "";
topic.concat(this->prefix);
topic.concat('/');
Expand All @@ -110,21 +110,45 @@ class HomeAssistantHelper {
topic.concat(this->devicePrefix);
topic.concat(nameSeparator);
topic.concat(name);
topic.concat("/config");
topic.concat(F("/config"));
return topic;
}

template <class T>
String getDeviceTopic(T value, char separator = '/') {
String getDeviceTopic(T value, char dpvSeparator = '/') {
String topic = "";
topic.concat(this->devicePrefix);
topic.concat(separator);
topic.concat(dpvSeparator);
topic.concat(value);
return topic;
}

template <class CT, class NT>
String getDeviceTopic(CT category, NT name, char dpcSeparator = '/', char cnSeparator = '/') {
String topic = "";
topic.concat(this->devicePrefix);
topic.concat(dpcSeparator);
topic.concat(category);
topic.concat(cnSeparator);
topic.concat(name);
return topic;
}

template <class CT, class NT, class ST>
String getDeviceTopic(CT category, NT name, ST suffix, char dpcSeparator = '/', char cnSeparator = '/', char nsSeparator = '/') {
String topic = "";
topic.concat(this->devicePrefix);
topic.concat(dpcSeparator);
topic.concat(category);
topic.concat(cnSeparator);
topic.concat(name);
topic.concat(nsSeparator);
topic.concat(suffix);
return topic;
}

template <class T>
String getObjectId(T value, char separator = '_') {
String getObjectIdWithPrefix(T value, char separator = '_') {
String topic = "";
topic.concat(this->devicePrefix);
topic.concat(separator);
Expand Down
7 changes: 7 additions & 0 deletions lib/HomeAssistantHelper/strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const char HA_ENABLED_BY_DEFAULT[] PROGMEM = "enabled_by_default";
const char HA_UNIQUE_ID[] PROGMEM = "unique_id";
const char HA_OBJECT_ID[] PROGMEM = "object_id";
const char HA_ENTITY_CATEGORY[] PROGMEM = "entity_category";
const char HA_ENTITY_CATEGORY_DIAGNOSTIC[] PROGMEM = "diagnostic";
const char HA_ENTITY_CATEGORY_CONFIG[] PROGMEM = "config";
const char HA_STATE_TOPIC[] PROGMEM = "state_topic";
const char HA_VALUE_TEMPLATE[] PROGMEM = "value_template";
const char HA_OPTIONS[] PROGMEM = "options";
Expand All @@ -35,16 +37,21 @@ const char HA_DEVICE_CLASS[] PROGMEM = "device_class";
const char HA_UNIT_OF_MEASUREMENT[] PROGMEM = "unit_of_measurement";
const char HA_UNIT_OF_MEASUREMENT_C[] PROGMEM = "°C";
const char HA_UNIT_OF_MEASUREMENT_F[] PROGMEM = "°F";
const char HA_UNIT_OF_MEASUREMENT_PERCENT[] PROGMEM = "%";
const char HA_UNIT_OF_MEASUREMENT_L_MIN[] PROGMEM = "L/min";
const char HA_UNIT_OF_MEASUREMENT_GAL_MIN[] PROGMEM = "gal/min";
const char HA_ICON[] PROGMEM = "icon";
const char HA_MIN[] PROGMEM = "min";
const char HA_MAX[] PROGMEM = "max";
const char HA_STEP[] PROGMEM = "step";
const char HA_MODE[] PROGMEM = "mode";
const char HA_MODE_BOX[] PROGMEM = "box";
const char HA_STATE_ON[] PROGMEM = "state_on";
const char HA_STATE_OFF[] PROGMEM = "state_off";
const char HA_PAYLOAD_ON[] PROGMEM = "payload_on";
const char HA_PAYLOAD_OFF[] PROGMEM = "payload_off";
const char HA_STATE_CLASS[] PROGMEM = "state_class";
const char HA_STATE_CLASS_MEASUREMENT[] PROGMEM = "measurement";
const char HA_EXPIRE_AFTER[] PROGMEM = "expire_after";
const char HA_CURRENT_TEMPERATURE_TOPIC[] PROGMEM = "current_temperature_topic";
const char HA_CURRENT_TEMPERATURE_TEMPLATE[] PROGMEM = "current_temperature_template";
Expand Down
2 changes: 1 addition & 1 deletion lib/MqttWriter/MqttWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class MqttWriter {
#endif
}

bool publish(const char* topic, JsonDocument& doc, bool retained = false) {
bool publish(const char* topic, const JsonVariantConst doc, bool retained = false) {
if (!this->client->connected()) {
this->bufferPos = 0;
return false;
Expand Down
3 changes: 1 addition & 2 deletions lib/WebServerHandlers/DynamicPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class DynamicPage : public RequestHandler {
}

if (this->cacheHeader != nullptr) {
server.sendHeader("Cache-Control", this->cacheHeader);
server.sendHeader(F("Cache-Control"), this->cacheHeader);
}

#ifdef ARDUINO_ARCH_ESP8266
Expand Down Expand Up @@ -218,7 +218,6 @@ class DynamicPage : public RequestHandler {
CanHandleCallback canHandleCallback;
BeforeSendCallback beforeSendCallback;
TemplateCallback templateCallback;
String eTag;
const char* uri = nullptr;
const char* path = nullptr;
const char* cacheHeader = nullptr;
Expand Down
34 changes: 21 additions & 13 deletions lib/WebServerHandlers/StaticPage.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include <FS.h>
#include <detail/mimetable.h>
#if defined(ARDUINO_ARCH_ESP32)
#include <detail/RequestHandlersImpl.h>
#endif

using namespace mime;

Expand All @@ -8,7 +11,8 @@ class StaticPage : public RequestHandler {
typedef std::function<bool(HTTPMethod, const String&)> CanHandleCallback;
typedef std::function<bool()> BeforeSendCallback;

StaticPage(const char* uri, FS* fs, const char* path, const char* cacheHeader = nullptr) {
template <class T>
StaticPage(const char* uri, FS* fs, T path, const char* cacheHeader = nullptr) {
this->uri = uri;
this->fs = fs;
this->path = path;
Expand Down Expand Up @@ -46,21 +50,25 @@ class StaticPage : public RequestHandler {
return true;
}

#if defined(ARDUINO_ARCH_ESP8266)
if (server._eTagEnabled) {
if (server._eTagFunction) {
this->eTag = (server._eTagFunction)(*this->fs, this->path);

} else if (this->eTag.isEmpty()) {
this->eTag = esp8266webserver::calcETag(*this->fs, this->path);
if (this->eTag.isEmpty()) {
if (server._eTagFunction) {
this->eTag = (server._eTagFunction)(*this->fs, this->path);

} else {
#if defined(ARDUINO_ARCH_ESP8266)
this->eTag = esp8266webserver::calcETag(*this->fs, this->path);
#elif defined(ARDUINO_ARCH_ESP32)
this->eTag = StaticRequestHandler::calcETag(*this->fs, this->path);
#endif
}
}

if (server.header("If-None-Match").equals(this->eTag.c_str())) {
if (!this->eTag.isEmpty() && server.header(F("If-None-Match")).equals(this->eTag.c_str())) {
server.send(304);
return true;
}
}
#endif

if (!this->path.endsWith(FPSTR(mimeTable[gz].endsWith)) && !this->fs->exists(path)) {
String pathWithGz = this->path + FPSTR(mimeTable[gz].endsWith);
Expand All @@ -80,14 +88,14 @@ class StaticPage : public RequestHandler {
}

if (this->cacheHeader != nullptr) {
server.sendHeader("Cache-Control", this->cacheHeader);
server.sendHeader(F("Cache-Control"), this->cacheHeader);
}

#if defined(ARDUINO_ARCH_ESP8266)
if (server._eTagEnabled && this->eTag.length() > 0) {
server.sendHeader("ETag", this->eTag);
if (server._eTagEnabled && !this->eTag.isEmpty()) {
server.sendHeader(F("ETag"), this->eTag);
}

#if defined(ARDUINO_ARCH_ESP8266)
server.streamFile(file, F("text/html"), method);
#else
server.streamFile(file, F("text/html"), 200);
Expand Down
6 changes: 4 additions & 2 deletions lib/WebServerHandlers/UpgradeHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,12 @@ class UpgradeHandler : public RequestHandler {

void upload(WebServer& server, const String& uri, HTTPUpload& upload) override {
UpgradeResult* result;
if (upload.name.equals("firmware")) {
if (upload.name.equals(F("firmware"))) {
result = &this->firmwareResult;
} else if (upload.name.equals("filesystem")) {

} else if (upload.name.equals(F("filesystem"))) {
result = &this->filesystemResult;

} else {
return;
}
Expand Down
4 changes: 0 additions & 4 deletions otgateway.ino

This file was deleted.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"gulp-html-minifier-terser": "^7.1.0",
"gulp-jsonminify": "^1.1.0",
"gulp-postcss": "^10.0.0",
"gulp-terser": "^2.1.0"
"gulp-terser": "^2.1.0",
"gulp-replace": "^1.1.4"
}
}
Loading

0 comments on commit 7efcbaa

Please sign in to comment.