├── .gitignore ├── .github ├── CODEOWNERS ├── logo.png └── FUNDING.yml ├── homed-gpio.pri ├── homed-sun.pri ├── homed-color.pri ├── homed-parser.pri ├── README.md ├── .gitlab-ci ├── pipeline.yml ├── build.yml └── deploy.yml ├── homed-endpoint.pri ├── deploy ├── apt │ └── control ├── entware │ └── control ├── opkg │ └── control └── data │ └── usr │ └── share │ └── homed-common │ └── expose.json ├── gpio.h ├── logger.h ├── homed-common.pri ├── color.h ├── parser.h ├── sun.h ├── logger.cpp ├── gpio.cpp ├── homed.h ├── main.cpp ├── color.cpp ├── sun.cpp ├── expose.h ├── endpoint.h ├── .gitlab-ci.yml ├── homed.cpp ├── endpoint.cpp ├── parser.cpp ├── expose.cpp └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @u236 2 | -------------------------------------------------------------------------------- /homed-gpio.pri: -------------------------------------------------------------------------------- 1 | HEADERS += $$PWD/gpio.h 2 | SOURCES += $$PWD/gpio.cpp 3 | -------------------------------------------------------------------------------- /homed-sun.pri: -------------------------------------------------------------------------------- 1 | HEADERS += $$PWD/sun.h 2 | SOURCES += $$PWD/sun.cpp 3 | -------------------------------------------------------------------------------- /homed-color.pri: -------------------------------------------------------------------------------- 1 | HEADERS += $$PWD/color.h 2 | SOURCES += $$PWD/color.cpp 3 | -------------------------------------------------------------------------------- /homed-parser.pri: -------------------------------------------------------------------------------- 1 | HEADERS += $$PWD/parser.h 2 | SOURCES += $$PWD/parser.cpp 3 | -------------------------------------------------------------------------------- /.github/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/homed-service-common/master/.github/logo.png -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | custom: ["https://boosty.to/voznemozhno", "https://yoomoney.ru/to/4100118059626125"] 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![HOMEd ZigBee](.github/logo.png) 2 | 3 | # HOMEd Common 4 | 5 | Общий код сервисов HOMEd 6 | -------------------------------------------------------------------------------- /.gitlab-ci/pipeline.yml: -------------------------------------------------------------------------------- 1 | include: 2 | - local: ".gitlab-ci/build.yml" 3 | - local: ".gitlab-ci/deploy.yml" 4 | -------------------------------------------------------------------------------- /homed-endpoint.pri: -------------------------------------------------------------------------------- 1 | HEADERS += \ 2 | $$PWD/endpoint.h \ 3 | $$PWD/expose.h 4 | 5 | SOURCES += \ 6 | $$PWD/endpoint.cpp \ 7 | $$PWD/expose.cpp 8 | -------------------------------------------------------------------------------- /deploy/apt/control: -------------------------------------------------------------------------------- 1 | Package: homed-common 2 | Version: 3 | Architecture: 4 | Maintainer: u236 5 | Section: misc 6 | Priority: standard 7 | Description: HOMEd Services Common Files 8 | -------------------------------------------------------------------------------- /deploy/entware/control: -------------------------------------------------------------------------------- 1 | Package: homed-common 2 | Version: 3 | Architecture: 4 | Maintainer: u236 5 | Section: misc 6 | Priority: standard 7 | Description: HOMEd Services Common Files 8 | -------------------------------------------------------------------------------- /deploy/opkg/control: -------------------------------------------------------------------------------- 1 | Package: homed-common 2 | Version: 3 | Architecture: 4 | Maintainer: u236 5 | Section: misc 6 | Priority: standard 7 | Description: HOMEd Services Common Files 8 | -------------------------------------------------------------------------------- /gpio.h: -------------------------------------------------------------------------------- 1 | #ifndef GPIO_H 2 | #define GPIO_H 3 | 4 | #include 5 | 6 | class GPIO 7 | { 8 | 9 | public: 10 | 11 | enum Direction 12 | { 13 | Input, 14 | Output 15 | }; 16 | 17 | static void direction(const QString &gpio, Direction direction); 18 | static void setStatus(const QString &gpio, bool status); 19 | static bool getStatus(const QString &gpio); 20 | 21 | }; 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /logger.h: -------------------------------------------------------------------------------- 1 | #ifndef LOGGER_H 2 | #define LOGGER_H 3 | 4 | #define logDebug(debug) if (debug) qDebug() 5 | #define logInfo qInfo() 6 | #define logWarning qWarning() 7 | 8 | #include 9 | 10 | void setLogEnabled(bool value); 11 | void setLogTimestams(bool value); 12 | void setLogFile(const QString &value); 13 | void logger(QtMsgType type, const QMessageLogContext &context, const QString &message); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /homed-common.pri: -------------------------------------------------------------------------------- 1 | HEADERS += \ 2 | $$PWD/homed.h \ 3 | $$PWD/logger.h 4 | 5 | SOURCES += \ 6 | $$PWD/homed.cpp \ 7 | $$PWD/logger.cpp \ 8 | $$PWD/main.cpp 9 | 10 | DISTFILES += \ 11 | $$PWD/deploy/data/usr/share/homed-common/expose.json 12 | 13 | QT -= gui 14 | QT += mqtt 15 | 16 | QMAKE_CXXFLAGS_RELEASE -= -O2 17 | QMAKE_CXXFLAGS_RELEASE += -Os 18 | QMAKE_POST_LINK = $(STRIP) $(TARGET) 19 | 20 | CONFIG += c++17 console exceptions_off ltcg object_parallel_to_source rtti_off 21 | INCLUDEPATH += ../homed-common/ 22 | 23 | target.path = /usr/bin 24 | INSTALLS += target 25 | -------------------------------------------------------------------------------- /color.h: -------------------------------------------------------------------------------- 1 | #ifndef COLOR_H 2 | #define COLOR_H 3 | 4 | #include 5 | 6 | class Color 7 | { 8 | 9 | public: 10 | 11 | Color(double r, double g, double b) : m_r(r < 0 ? 0 : r < 1 ? r : 1), m_g(g < 0 ? 0 : g < 1 ? g : 1), m_b(b < 0 ? 0 : b < 1 ? b : 1) {} 12 | 13 | inline double r(void) { return m_r; } 14 | inline double g(void) { return m_g; } 15 | inline double b(void) { return m_b; } 16 | 17 | static Color fromCT(double ct); 18 | static Color fromHS(double h, double s); 19 | static Color fromXY(double x, double y); 20 | 21 | void toHS(double *h, double *s); 22 | void toXY(double *x, double *y); 23 | 24 | private: 25 | 26 | double m_r, m_g, m_b; 27 | 28 | static double correctGamma(double value); 29 | static double reverseGamma(double value); 30 | 31 | }; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /parser.h: -------------------------------------------------------------------------------- 1 | #ifndef PARSER_H 2 | #define PARSER_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | class Expression 10 | { 11 | 12 | public: 13 | 14 | Expression(QString text); 15 | inline double result(void) { return m_result; } 16 | 17 | private: 18 | 19 | enum class Type 20 | { 21 | Empty, 22 | Number, 23 | OpenBracket, 24 | CloseBracket, 25 | Comma, 26 | Add, 27 | Subtract, 28 | Multiply, 29 | Divide, 30 | Remainder, 31 | Pow, 32 | Round, 33 | Ceil, 34 | Floor, 35 | Sqrt, 36 | Exp, 37 | Min, 38 | Max, 39 | Random 40 | }; 41 | 42 | struct Item 43 | { 44 | Type type; 45 | QString value; 46 | }; 47 | 48 | double m_result; 49 | QVector m_items; 50 | 51 | Type itemType(const QString &v); 52 | int itemPriority(Type type); 53 | 54 | void calculate(void); 55 | 56 | }; 57 | 58 | class Parser 59 | { 60 | 61 | public: 62 | 63 | static QString formatValue(const QString &string); 64 | static QVariant jsonValue(const QByteArray &data, const QString &path); 65 | static QString urlValue(const QByteArray &string, const QString &key); 66 | static QString xmlValue(const QByteArray &string, const QString &key); 67 | static QVariant stringValue(const QString &string); 68 | 69 | }; 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /sun.h: -------------------------------------------------------------------------------- 1 | #ifndef SUN_H 2 | #define SUN_H 3 | 4 | #define ANGLE 90.833 5 | 6 | #include 7 | #include 8 | 9 | class Sun 10 | { 11 | 12 | public: 13 | 14 | Sun(double latitude, double longitude) : 15 | m_latitude(latitude), m_longitude(longitude), m_julianDay(0), m_offset(0) {} 16 | 17 | inline void setDate(const QDate &value) { m_julianDay = value.toJulianDay(); } 18 | inline void setOffset(int value) { m_offset = value / 60; } 19 | 20 | inline QTime sunrise(void) { return m_sunrise; } 21 | inline QTime sunset(void) { return m_sunset; } 22 | 23 | void updateSunrise(void); 24 | void updateSunset(void); 25 | 26 | QTime fromString(const QString &string); 27 | 28 | private: 29 | 30 | double m_latitude, m_longitude, m_julianDay, m_offset; 31 | QTime m_sunrise, m_sunset; 32 | 33 | inline double radian(double value) { return value / 180 * M_PI; } 34 | inline double degree(double value) { return value * 180 / M_PI; } 35 | 36 | double julianDay(double century); 37 | double julianCentury(double day); 38 | 39 | double meanSunAnomaly(double t); 40 | double meanSunLongitude(double t); 41 | double sunDeclination(double t); 42 | double obliquityCorrection(double t); 43 | double timeEquation(double t); 44 | 45 | double sunriseHourAngle(double latitude, double declination, double offset); 46 | double sunsetHourAngle(double latitude, double declination, double offset); 47 | 48 | }; 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /logger.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "logger.h" 7 | 8 | static bool enabled, timestamps; 9 | static QFile file; 10 | static QMutex mutex; 11 | static QString service; 12 | 13 | static QString typeString(QtMsgType type) 14 | { 15 | switch (type) 16 | { 17 | case QtDebugMsg: return "dbg"; 18 | case QtWarningMsg: return "wrn"; 19 | default: return "inf"; 20 | } 21 | } 22 | 23 | static QString formatMessage(QString message) 24 | { 25 | message.front() = message.front().toUpper(); 26 | return message; 27 | } 28 | 29 | void setLogEnabled(bool value) 30 | { 31 | enabled = value; 32 | } 33 | 34 | void setLogTimestams(bool value) 35 | { 36 | timestamps = value; 37 | } 38 | 39 | void setLogFile(const QString &value) 40 | { 41 | file.setFileName(value); 42 | } 43 | 44 | void logger(QtMsgType type, const QMessageLogContext &, const QString &message) 45 | { 46 | QMutexLocker lock(&mutex); 47 | QString timestamp = QDateTime::currentDateTime().toString("yyyy.MM.dd hh:mm:ss.zzz"), data; 48 | 49 | if (service.isEmpty()) 50 | service = QCoreApplication::applicationName().split('-').last().append(':').leftJustified(11); 51 | 52 | data = QString("(%1) %2 %3").arg(typeString(type), service, formatMessage(message)); 53 | 54 | if (enabled && file.open(QIODevice::WriteOnly | QIODevice::Append)) 55 | { 56 | QTextStream stream(&file); 57 | stream << QString("%1 %2").arg(timestamp, data) << Qt::endl; 58 | file.close(); 59 | } 60 | 61 | std::cout << (timestamps ? QString("%1 %2").arg(timestamp, data) : data).toStdString() << std::endl; 62 | } 63 | -------------------------------------------------------------------------------- /gpio.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "gpio.h" 3 | 4 | void GPIO::direction(const QString &gpio, Direction direction) 5 | { 6 | QList list = gpio.split('|'); 7 | QFile file; 8 | bool check; 9 | int pin = list.value(0).toInt(&check); 10 | 11 | if (!check || pin < 0) 12 | return; 13 | 14 | file.setFileName("/sys/class/gpio/export"); 15 | 16 | if (!file.open(QFile::WriteOnly)) 17 | return; 18 | 19 | file.write(QString("%1\n").arg(pin).toUtf8()); 20 | file.close(); 21 | file.setFileName(QString("/sys/class/gpio/gpio%1/direction").arg(pin)); 22 | 23 | if (!file.open(QFile::WriteOnly)) 24 | return; 25 | 26 | switch (direction) 27 | { 28 | case Input: 29 | file.write("in"); 30 | break; 31 | 32 | case Output: 33 | file.write("out"); 34 | break; 35 | } 36 | 37 | file.close(); 38 | } 39 | 40 | void GPIO::setStatus(const QString &gpio, bool status) 41 | { 42 | QList list = gpio.split('|'); 43 | QFile file; 44 | bool check; 45 | int pin = list.value(0).toInt(&check); 46 | 47 | if (check && pin < 0) 48 | return; 49 | 50 | file.setFileName(check ? QString("/sys/class/gpio/gpio%1/value").arg(pin) : list.value(0)); 51 | 52 | if (!file.open(QFile::WriteOnly)) 53 | return; 54 | 55 | if (list.value(1) == "invert") 56 | status = status ? false : true; 57 | 58 | file.write(status ? "1" : "0"); 59 | file.close(); 60 | } 61 | 62 | bool GPIO::getStatus(const QString &gpio) 63 | { 64 | QList list = gpio.split('|'); 65 | QFile file; 66 | bool check; 67 | int pin = list.value(0).toInt(&check); 68 | char status; 69 | 70 | if (check && pin < 0) 71 | return false; 72 | 73 | file.setFileName(check ? QString("/sys/class/gpio/gpio%1/value").arg(pin) : list.value(0)); 74 | 75 | if (!file.open(QFile::ReadOnly)) 76 | return false; 77 | 78 | file.read(&status, sizeof(status)); 79 | file.close(); 80 | 81 | return list.value(1) == "invert" ? status == '0' : status != '0'; 82 | } 83 | -------------------------------------------------------------------------------- /homed.h: -------------------------------------------------------------------------------- 1 | #ifndef HOMED_H 2 | #define HOMED_H 3 | 4 | #define MQTT_DEFAULT_QOS 0 5 | #define MQTT_RECONNECT_INTERVAL 2000 6 | #define STATUS_UPDATE_PERIOD 60000 7 | #define EXIT_RESTART 1000 8 | 9 | #define mqttSafe(string) QString(string).replace(QRegExp("[\\#|\\+|\\/]"), "_") 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | class HOMEd : public QObject 22 | { 23 | Q_OBJECT 24 | 25 | public: 26 | 27 | HOMEd(const QString &version, const QString &configFile, bool multiple = false); 28 | 29 | inline QSettings *getConfig(void) { return m_config; } 30 | inline QString mqttPrefix(void) { return m_mqttPrefix; } 31 | inline QString serviceTopic(void) { return m_serviceTopic; } 32 | inline QString uniqueId(void) { return m_uniqueId; } 33 | inline bool mqttStatus(void) { return m_connected; } 34 | 35 | void mqttSubscribe(const QString &topic); 36 | void mqttUnsubscribe(const QString &topic); 37 | 38 | void mqttPublish(const QString &topic, const QJsonObject &json, bool retain = false); 39 | void mqttPublishString(const QString &topic, const QString &message, bool retain = false); 40 | void mqttPublishDiscovery(const QString &name, const QString &version, const QString &haPrefix, bool permitJoin = false); 41 | void mqttPublishStatus(bool online = true); 42 | 43 | QString mqttTopic(const QString &topic = QString()); 44 | 45 | private: 46 | 47 | QMqttClient *m_mqtt; 48 | QTimer *m_statusTimer, *m_reconnectTimer; 49 | 50 | QFileSystemWatcher *m_watcher; 51 | QSettings *m_config; 52 | 53 | QString m_mqttPrefix, m_serviceTopic, m_uniqueId; 54 | quint32 m_interval; 55 | bool m_connected, m_first; 56 | 57 | public slots: 58 | 59 | virtual void quit(void); 60 | 61 | private slots: 62 | 63 | virtual void mqttConnected(void) {}; 64 | virtual void mqttDisconnected(void) {}; 65 | virtual void mqttReceived(const QByteArray &, const QMqttTopicName &) {}; 66 | 67 | void connected(void); 68 | void disconnected(void); 69 | void reconnect(void); 70 | void publishStatus(void); 71 | void fileChanged(void); 72 | 73 | }; 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "controller.h" 6 | 7 | static void signalHandler(int) 8 | { 9 | QCoreApplication::quit(); 10 | } 11 | 12 | static int start(const QCoreApplication &application, const QString &configFile, const QString &lockFile) 13 | { 14 | QFile config(configFile); 15 | QLockFile lock(lockFile); 16 | int result = EXIT_RESTART; 17 | 18 | if (!configFile.isEmpty() && !config.open(QFile::ReadOnly)) 19 | { 20 | printf("Startup failed, unable to open configurantion file \"%s\"\n", configFile.toUtf8().constData()); 21 | return EXIT_FAILURE; 22 | } 23 | 24 | if (!application.arguments().contains("-f") && !lock.tryLock(1000)) 25 | { 26 | printf("Startup failed, unable to create lock file \"%s\"\n", lockFile.toUtf8().constData()); 27 | return EXIT_FAILURE; 28 | } 29 | 30 | signal(SIGINT, signalHandler); 31 | signal(SIGTERM, signalHandler); 32 | 33 | while (result == EXIT_RESTART) 34 | { 35 | Controller controller(configFile); 36 | QObject::connect(&application, &QCoreApplication::aboutToQuit, &controller, &Controller::quit); 37 | result = application.exec(); 38 | } 39 | 40 | return result; 41 | } 42 | 43 | int main(int argc, char **argv) 44 | { 45 | QList list = {"-c", "-l"}; 46 | QCoreApplication application(argc, argv); 47 | QString configFile, lockFile; 48 | 49 | if (application.arguments().contains("-h")) 50 | { 51 | printf("\n" 52 | " -c use the specified configuraton file\n" 53 | " -l use the specified lock file\n" 54 | " -f force start (ignore lock file)\n" 55 | " -v print application version\n" 56 | " -h print this help\n" 57 | "\n"); 58 | 59 | return EXIT_SUCCESS; 60 | } 61 | 62 | if (application.arguments().contains("-v")) 63 | { 64 | printf("%s %s\n", application.applicationName().toUtf8().constData(), SERVICE_VERSION); 65 | return EXIT_SUCCESS; 66 | } 67 | 68 | for (int i = 0; i < argc; i++) 69 | { 70 | switch (list.indexOf(application.arguments().value(i))) 71 | { 72 | case 0: configFile = application.arguments().value(++i); break; 73 | case 1: lockFile = application.arguments().value(++i); break; 74 | } 75 | } 76 | 77 | return start(application, configFile, lockFile.isEmpty() ? QString("%1/%2.lock").arg(QDir::tempPath(), application.applicationName()) : lockFile); 78 | } 79 | -------------------------------------------------------------------------------- /color.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "color.h" 3 | 4 | Color Color::fromCT(double ct) 5 | { 6 | double r, g, b, k = 10000 / ct; 7 | 8 | r = k > 66 ? 1.292936 * pow(k - 60, -0.133205) : 1; 9 | g = k > 66 ? 1.129891 * pow(k - 60, -0.075515) : 0.390082 * log(k) - 0.631841; 10 | b = k < 66 ? 0.543207 * log(k - 10) -1.1962540 : 1; 11 | 12 | return Color(r, g, b); 13 | } 14 | 15 | Color Color::fromHS(double h, double s) 16 | { 17 | double p = floor(h * 6), q = h * 6 - p, i = 1 - s, j = 1 - s * q, k = 1 - s * (1 - q); 18 | 19 | switch (static_cast (p) % 6) 20 | { 21 | case 0: return Color(1, k, i); 22 | case 1: return Color(j, 1, i); 23 | case 2: return Color(i, 1, k); 24 | case 3: return Color(i, j, 1); 25 | case 4: return Color(k, i, 1); 26 | case 5: return Color(1, i, j); 27 | } 28 | 29 | return Color(0, 0, 0); 30 | } 31 | 32 | Color Color::fromXY(double x, double y) 33 | { 34 | double z = 1 - x - y, p = 1 / y * x, q = 1 / y * z, r, g, b, max; 35 | 36 | r = correctGamma(p * 1.656492 - q * 0.255038 - 0.354851); 37 | g = correctGamma(p * -0.707196 + q * 0.036152 + 1.655397); 38 | b = correctGamma(p * 0.051713 + q * 1.011530 - 0.121364); 39 | 40 | max = r > g ? r > b ? r : b : g > b ? g : b; 41 | 42 | if (max > 1) 43 | { 44 | r /= max; 45 | g /= max; 46 | b /= max; 47 | } 48 | 49 | return Color(r, g, b); 50 | } 51 | 52 | void Color::toHS(double *h, double *s) 53 | { 54 | double max = m_r > m_g ? m_r > m_b ? m_r : m_b : m_g > m_b ? m_g : m_b, min = m_r < m_g ? m_r < m_b ? m_r : m_b : m_g < m_b ? m_g : m_b, delta = max - min; 55 | 56 | if (!delta) 57 | *h = 0; 58 | else if (m_r == max) 59 | *h = ((m_g - m_b) + delta * (m_g < m_b ? 6 : 0)) / delta / 6; 60 | else if (m_g == max) 61 | *h = ((m_b - m_r) + delta * 2) / delta / 6; 62 | else if (m_b == max) 63 | *h = ((m_r - m_g) + delta * 4) / delta / 6; 64 | 65 | *s = max ? delta / max : 0; 66 | } 67 | 68 | void Color::toXY(double *x, double *y) 69 | { 70 | double r = reverseGamma(m_r), g = reverseGamma(m_g), b = reverseGamma(m_b), z; 71 | 72 | *x = r * 0.664511 + g * 0.154324 + b * 0.162028; 73 | *y = r * 0.283881 + g * 0.668433 + b * 0.047685; 74 | z = r * 0.000088 + g * 0.072310 + b * 0.986039 + *x + *y; 75 | 76 | *x /= z; 77 | *y /= z; 78 | } 79 | 80 | double Color::correctGamma(double value) 81 | { 82 | return value <= 0.0031306684425006 ? value * 12.92 : pow(value, 1 / 2.4) * 1.055 - 0.055; 83 | } 84 | 85 | double Color::reverseGamma(double value) 86 | { 87 | return value <= 0.0404482362771076 ? value / 12.92 : pow((value + 0.055) / 1.055, 2.4); 88 | } 89 | -------------------------------------------------------------------------------- /sun.cpp: -------------------------------------------------------------------------------- 1 | #include "sun.h" 2 | 3 | void Sun::updateSunrise(void) 4 | { 5 | double t = julianCentury(m_julianDay), n = julianCentury(julianDay(t) + (720 - (m_longitude + degree(sunriseHourAngle(m_latitude, sunDeclination(t), ANGLE))) * 4 - timeEquation(t)) / 1440.0), m = round(720 - (m_longitude + degree(sunriseHourAngle(m_latitude, sunDeclination(n), ANGLE))) * 4 - timeEquation(n)) + m_offset; 6 | m_sunrise = QTime(static_cast (m / 60), static_cast (m) % 60); 7 | } 8 | 9 | void Sun::updateSunset(void) 10 | { 11 | double t = julianCentury(m_julianDay), n = julianCentury(julianDay(t) + (720 - (m_longitude + degree(sunsetHourAngle(m_latitude, sunDeclination(t), ANGLE))) * 4 - timeEquation(t)) / 1440.0), m = round(720 - (m_longitude + degree(sunsetHourAngle(m_latitude, sunDeclination(n), ANGLE))) * 4 - timeEquation(n)) + m_offset; 12 | m_sunset = QTime(static_cast (m / 60), static_cast (m) % 60); 13 | } 14 | 15 | QTime Sun::fromString(const QString &string) 16 | { 17 | QList itemList = string.split(QRegExp("[(\\-|\\+)]")), valueList = {"sunrise", "sunset"}; 18 | QString value = itemList.value(0).toLower().trimmed(); 19 | qint32 offset = itemList.value(1).toInt(); 20 | 21 | if (string.mid(itemList.value(0).length(), 1) == "-") 22 | offset *= -1; 23 | 24 | switch (valueList.indexOf(value)) 25 | { 26 | case 0: return m_sunrise.addSecs(offset * 60); 27 | case 1: return m_sunset.addSecs(offset * 60); 28 | default: return QTime::fromString(value, "h:mm"); 29 | } 30 | } 31 | 32 | double Sun::julianCentury(double day) 33 | { 34 | return (day - 2451545) / 36525; 35 | } 36 | 37 | double Sun::julianDay(double century) 38 | { 39 | return century * 36525 + 2451545; 40 | } 41 | 42 | double Sun::meanSunAnomaly(double t) 43 | { 44 | return 357.52911 + t * (35999.05029 - t * 0.0001537); 45 | } 46 | 47 | double Sun::meanSunLongitude(double t) 48 | { 49 | return fmod(t * (36000.76983 + t * 0.0003032) + 280.46646, 360); 50 | } 51 | 52 | double Sun::sunDeclination(double t) 53 | { 54 | double r = radian(meanSunAnomaly(t)), l = meanSunLongitude(t) + sin(r) * (1.914602 - t * (0.004817 + t * 0.000014)) + sin(r * 2) * (0.019993 - t * 0.000101) + sin(r * 3) * 0.000289 - sin(radian(125.04 - 1934.136 * t)) * 0.00478 - 0.00569; 55 | return degree(asin(sin(radian(obliquityCorrection(t))) * sin(radian(l)))); 56 | } 57 | 58 | double Sun::obliquityCorrection(double t) 59 | { 60 | return cos(radian(125.04 - t * 1934.136)) * 0.00256 + (((21.448 - t * (46.8150 + t * (0.00059 - t * 0.001813))) / 60) + 26) / 60 + 23; 61 | } 62 | 63 | double Sun::timeEquation(double t) 64 | { 65 | double e = 0.016708634 - t * (0.000042037 + t * 0.0000001267), y = pow(tan(radian(obliquityCorrection(t)) / 2), 2), a = meanSunAnomaly(t), l = meanSunLongitude(t), s = sin(radian(a)); 66 | return degree(y * sin(radian(l) * 2) - e * s * 2 + e * y * s * cos(radian(l) * 2) * 4 - pow(y, 2) * sin(radian(l) * 4) / 2 - pow(e, 2) * sin(radian(a) * 2) * 1.25) * 4; 67 | } 68 | 69 | double Sun::sunriseHourAngle(double latitude, double declination, double offset) 70 | { 71 | double l = radian(latitude), s = radian(declination); 72 | return acos(cos(radian(offset)) / (cos(l) * cos(s)) - tan(l) * tan(s)); 73 | } 74 | 75 | double Sun::sunsetHourAngle(double latitude, double declination, double offset) 76 | { 77 | return sunriseHourAngle(latitude, declination, offset) * -1; 78 | } 79 | -------------------------------------------------------------------------------- /.gitlab-ci/build.yml: -------------------------------------------------------------------------------- 1 | .build: 2 | stage: build 3 | script: 4 | - "export PATH=\"${PATH}:/opt/gcc/${COMPILER}/bin\"" 5 | - "export STAGING_DIR=\"/opt/gcc/${COMPILER}\"" 6 | - "/opt/qt/${QT_BUILD}/bin/qmake ${NAME}.pro" 7 | - "make -j $(nproc)" 8 | - "cp ${NAME} ${NAME}-${ARCHITECTURE}" 9 | - "cp ${NAME}-${ARCHITECTURE} /var/www/sandbox.u236.org/${NAME}" 10 | artifacts: 11 | paths: 12 | - "${NAME}-*" 13 | expire_in: 1 day 14 | rules: 15 | - if: $CI_COMMIT_TAG =~ /^\d.\d+.\d+$/ || $CI_COMMIT_TAG == "dev" 16 | when: always 17 | - when: never 18 | 19 | Build Linux Binary (amd64): 20 | extends: .build 21 | variables: 22 | ARCHITECTURE: linux-amd64 23 | QT_BUILD: qt-amd64-linux-5.15.4-shared 24 | script: 25 | - "docker run --rm -u ${UID}:${UID} -v /opt/qt/${QT_BUILD}:/opt/qt/${QT_BUILD} -v ${PWD}/..:/build -w /build/${NAME} gcc:10.5.0 bash -c \"/opt/qt/${QT_BUILD}/bin/qmake ${NAME}.pro; make -j $(nproc)\"" 26 | - "cp ${NAME} ${NAME}-${ARCHITECTURE}" 27 | - "cp ${NAME}-${ARCHITECTURE} /var/www/sandbox.u236.org/${NAME}" 28 | 29 | Build Linux Binary (aarch64): 30 | extends: .build 31 | variables: 32 | ARCHITECTURE: linux-aarch64 33 | QT_BUILD: qt-aarch64-linux-gnu-5.15.4-shared 34 | COMPILER: gcc-aarch64-none-linux-gnu-10.2.0 35 | after_script: 36 | - "cp ${NAME}-linux-aarch64 ${NAME}-linux-arm64" 37 | 38 | Build Linux Binary (armhf): 39 | extends: .build 40 | variables: 41 | ARCHITECTURE: linux-armhf 42 | QT_BUILD: qt-arm-linux-gnueabihf-5.15.4-shared 43 | COMPILER: gcc-arm-linux-gnuebihf-9.4.0 44 | 45 | Build OpenWRT Binary (aarch64_generic): 46 | extends: .build 47 | variables: 48 | ARCHITECTURE: openwrt-aarch64_generic 49 | QT_BUILD: qt-aarch64_generic-openwrt-linux-5.15.4-shared 50 | COMPILER: gcc-aarch64_generic-openwrt-linux-8.4.0-musl 51 | 52 | Build OpenWRT Binary (arm_cortex-a7_neon-vfpv4): 53 | extends: .build 54 | variables: 55 | ARCHITECTURE: openwrt-arm_cortex-a7_neon-vfpv4 56 | QT_BUILD: qt-arm_cortex-a7_neon-vfpv4-openwrt-linux-5.15.4-shared 57 | COMPILER: gcc-arm_cortex-a7_neon-vfpv4-openwrt-linux-8.4.0-musl 58 | 59 | Build OpenWRT Binary (arm_cortex-a9_neon): 60 | extends: .build 61 | variables: 62 | ARCHITECTURE: openwrt-arm_cortex-a9_neon 63 | QT_BUILD: qt-arm_cortex-a9_neon-openwrt-linux-5.15.4-shared 64 | COMPILER: gcc-arm_cortex-a9_neon-openwrt-linux-8.4.0-musl 65 | 66 | Build OpenWRT Binary (mips_24kc): 67 | extends: .build 68 | variables: 69 | ARCHITECTURE: openwrt-mips_24kc 70 | QT_BUILD: qt-mips_24kc-openwrt-linux-5.15.4-shared 71 | COMPILER: gcc-mips_24kc-openwrt-linux-8.4.0-musl 72 | 73 | Build OpenWRT Binary (mipsel_24kc): 74 | extends: .build 75 | variables: 76 | ARCHITECTURE: openwrt-mipsel_24kc 77 | QT_BUILD: qt-mipsel_24kc-openwrt-linux-5.15.4-shared 78 | COMPILER: gcc-mipsel_24kc-openwrt-linux-8.4.0-musl 79 | 80 | Build Keenetic NDMS Binary (aarch64-3.10): 81 | extends: .build 82 | variables: 83 | ARCHITECTURE: entware-aarch64-3.10 84 | QT_BUILD: qt-aarch64-openwrt-linux-gnu-5.15.4-shared 85 | COMPILER: gcc-aarch64-openwrt-linux-gnu-8.4.0 86 | 87 | Build Keenetic NDMS Binary (mips-3.4): 88 | extends: .build 89 | variables: 90 | ARCHITECTURE: entware-mips-3.4 91 | QT_BUILD: qt-mips-openwrt-linux-gnu-5.15.4-shared 92 | COMPILER: gcc-mips-openwrt-linux-gnu-8.4.0 93 | 94 | Build Keenetic NDMS Binary (mipsel-3.4): 95 | extends: .build 96 | variables: 97 | ARCHITECTURE: entware-mipsel-3.4 98 | QT_BUILD: qt-mipsel-openwrt-linux-gnu-5.15.4-shared 99 | COMPILER: gcc-mipsel-openwrt-linux-gnu-8.4.0 100 | -------------------------------------------------------------------------------- /expose.h: -------------------------------------------------------------------------------- 1 | #ifndef EXPOSE_H 2 | #define EXPOSE_H 3 | 4 | #include 5 | #include 6 | #include "endpoint.h" 7 | 8 | class ExposeObject; 9 | typedef QSharedPointer Expose; 10 | 11 | class ExposeObject : public AbstractMetaObject 12 | { 13 | 14 | public: 15 | 16 | ExposeObject(const QString &name, const QString &component) : 17 | AbstractMetaObject(name), m_component(component), m_multiple(false), m_discovery(true) {} 18 | 19 | ExposeObject(const QString &name) : 20 | AbstractMetaObject(name), m_multiple(false), m_discovery(false) {} 21 | 22 | virtual ~ExposeObject(void) {} 23 | virtual QJsonObject request(void) { return QJsonObject(); }; 24 | 25 | inline QString component(void) { return m_component; } 26 | 27 | inline void setStateTopic(const QString &value) { m_stateTopic = value; } 28 | inline void setCommandTopic(const QString &value) { m_commandTopic = value; } 29 | 30 | inline bool multiple(void) { return m_multiple; } 31 | inline void setMultiple(bool value) { m_multiple = value; } 32 | 33 | inline bool discovery(void) { return m_discovery; } 34 | static void registerMetaTypes(void); 35 | 36 | protected: 37 | 38 | QString m_component, m_stateTopic, m_commandTopic; 39 | bool m_multiple, m_discovery; 40 | 41 | }; 42 | 43 | class BinaryObject : public ExposeObject 44 | { 45 | 46 | public: 47 | 48 | BinaryObject(const QString &name = "binary") : ExposeObject(name, "binary_sensor") {} 49 | QJsonObject request(void) override; 50 | 51 | }; 52 | 53 | class SensorObject : public ExposeObject 54 | { 55 | 56 | public: 57 | 58 | SensorObject(const QString &name = "sensor") : ExposeObject(name, "sensor") {} 59 | QJsonObject request(void) override; 60 | 61 | }; 62 | 63 | class ToggleObject : public ExposeObject 64 | { 65 | 66 | public: 67 | 68 | ToggleObject(const QString &name = "toggle") : ExposeObject(name, "switch") {} 69 | QJsonObject request(void) override; 70 | 71 | }; 72 | 73 | class NumberObject : public ExposeObject 74 | { 75 | 76 | public: 77 | 78 | NumberObject(const QString &name = "number") : ExposeObject(name, "number") {} 79 | QJsonObject request(void) override; 80 | 81 | }; 82 | 83 | class SelectObject : public ExposeObject 84 | { 85 | 86 | public: 87 | 88 | SelectObject(const QString &name = "select") : ExposeObject(name, "select") {} 89 | QJsonObject request(void) override; 90 | 91 | }; 92 | 93 | class ButtonObject : public ExposeObject 94 | { 95 | 96 | public: 97 | 98 | ButtonObject(const QString &name = "button") : ExposeObject(name, "button") {} 99 | QJsonObject request(void) override; 100 | 101 | }; 102 | 103 | class SwitchObject : public ExposeObject 104 | { 105 | 106 | public: 107 | 108 | SwitchObject(void) : ExposeObject("switch", "switch") {} 109 | QJsonObject request(void) override; 110 | 111 | }; 112 | 113 | class LightObject : public ExposeObject 114 | { 115 | 116 | public: 117 | 118 | LightObject(void) : ExposeObject("light", "light") {} 119 | QJsonObject request(void) override; 120 | 121 | }; 122 | 123 | class CoverObject : public ExposeObject 124 | { 125 | 126 | public: 127 | 128 | CoverObject(void) : ExposeObject("cover", "cover") {} 129 | QJsonObject request(void) override; 130 | 131 | }; 132 | 133 | class LockObject : public ExposeObject 134 | { 135 | 136 | public: 137 | 138 | LockObject(void) : ExposeObject("lock", "lock") {} 139 | QJsonObject request(void) override; 140 | 141 | }; 142 | 143 | class ThermostatObject : public ExposeObject 144 | { 145 | 146 | public: 147 | 148 | ThermostatObject(void) : ExposeObject("thermostat", "climate") {} 149 | QJsonObject request(void) override; 150 | 151 | }; 152 | 153 | #endif 154 | -------------------------------------------------------------------------------- /endpoint.h: -------------------------------------------------------------------------------- 1 | #ifndef ENDPOINT_H 2 | #define ENDPOINT_H 3 | 4 | #include 5 | #include 6 | #include "homed.h" 7 | 8 | class ExposeObject; 9 | typedef QSharedPointer Expose; 10 | 11 | class EndpointObject; 12 | typedef QSharedPointer Endpoint; 13 | 14 | class DeviceObject; 15 | typedef QSharedPointer Device; 16 | 17 | enum class Availability 18 | { 19 | Unknown, 20 | Online, 21 | Offline 22 | }; 23 | 24 | class AbstractEndpointObject : public QObject 25 | { 26 | Q_OBJECT 27 | 28 | public: 29 | 30 | AbstractEndpointObject(quint8 id, const Device &device) : 31 | QObject(nullptr), m_id(id), m_device(device) {} 32 | 33 | inline quint8 id(void) { return m_id; } 34 | inline Device device(void) { return m_device; } 35 | inline QMap &meta(void) { return m_meta; } 36 | inline QList &exposes(void) { return m_exposes; } 37 | 38 | protected: 39 | 40 | quint8 m_id; 41 | QWeakPointer m_device; 42 | QMap m_meta; 43 | QList m_exposes; 44 | 45 | }; 46 | 47 | class AbstractDeviceObject : public QObject 48 | { 49 | Q_OBJECT 50 | 51 | public: 52 | 53 | AbstractDeviceObject(const QString &name) : 54 | QObject(nullptr), m_version(0), m_name(name), m_active(true), m_discovery(true), m_cloud(true), m_availability(Availability::Unknown) {} 55 | 56 | inline quint8 version(void) { return m_version; } 57 | inline void setVersion(quint8 value) { m_version = value; } 58 | 59 | inline QString name(void) { return m_name; } 60 | inline void setName(const QString &value) { m_name = value; } 61 | 62 | inline QString manufacturerName(void) { return m_manufacturerName; } 63 | inline void setManufacturerName(const QString &value) { m_manufacturerName = value; } 64 | 65 | inline QString modelName(void) { return m_modelName; } 66 | inline void setModelName(const QString &value) { m_modelName = value; } 67 | 68 | inline QString description(void) { return m_description; } 69 | inline void setDescription(const QString &value) { m_description = value; } 70 | 71 | inline QString note(void) { return m_note; } 72 | inline void setNote(const QString &value) { m_note = value; } 73 | 74 | inline bool active(void) { return m_active; } 75 | inline void setActive(bool value) { m_active = value; } 76 | 77 | inline bool discovery(void) { return m_discovery; } 78 | inline void setDiscovery(bool value) { m_discovery = value; } 79 | 80 | inline bool cloud(void) { return m_cloud; } 81 | inline void setCloud(bool value) { m_cloud = value; } 82 | 83 | inline Availability availability(void) { return m_availability; } 84 | inline void setAvailability(Availability value) { m_availability = value; } 85 | 86 | inline QMap &options(void) { return m_options; } 87 | inline QMap &endpoints(void) { return m_endpoints; } 88 | 89 | void publishExposes(HOMEd *controller, const QString &address, const QString uniqueId, const QString haPrefix, bool haEnabled, bool names, bool remove = false); 90 | 91 | protected: 92 | 93 | quint8 m_version; 94 | QString m_name, m_manufacturerName, m_modelName, m_description, m_note; 95 | bool m_active, m_discovery, m_cloud; 96 | 97 | Availability m_availability; 98 | 99 | QMap m_options; 100 | QMap m_endpoints; 101 | 102 | QString exposeTitle(const Expose &expose); 103 | 104 | }; 105 | 106 | class AbstractMetaObject 107 | { 108 | 109 | public: 110 | 111 | AbstractMetaObject(const QString name) : m_name(name), m_parent(nullptr) {} 112 | 113 | inline QString name(void) { return m_name; } 114 | inline void setName(const QString &value) { m_name = value; } 115 | inline void setParent(AbstractEndpointObject *value) { m_parent = value; } 116 | 117 | QVariant option(const QString &name = QString(), const QVariant &defaultValue = QVariant()); 118 | 119 | protected: 120 | 121 | QString m_name; 122 | AbstractEndpointObject *m_parent; 123 | 124 | quint8 version(void); 125 | 126 | QString manufacturerName(void); 127 | QString modelName(void); 128 | 129 | QVariant meta(const QString &key, const QVariant &defaultValue = QVariant()); 130 | void setMeta(const QString &key, const QVariant &value); 131 | void clearMeta(const QString &key); 132 | 133 | }; 134 | 135 | #endif 136 | -------------------------------------------------------------------------------- /.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | .deploy_linux: 2 | stage: deploy 3 | variables: 4 | PACKAGE_FILE: homed-common_${CI_COMMIT_TAG}_${ARCHITECTURE}.deb 5 | script: 6 | - "cp -r deploy/apt deploy/data/DEBIAN" 7 | - "md5deep -lr deploy/data | grep -v DEBIAN | sed \"s+deploy/data/++g\" | sort -k2 > deploy/data/DEBIAN/md5sums" 8 | - "sed -i \"s+^Version:.*+Version: ${CI_COMMIT_TAG}+g\" deploy/data/DEBIAN/control" 9 | - "sed -i \"s+^Architecture:.*+Architecture: ${ARCHITECTURE}+g\" deploy/data/DEBIAN/control" 10 | - "fakeroot dpkg-deb --build deploy/data" 11 | - "mv deploy/data.deb ${PACKAGE_FILE}" 12 | - "reprepro -b /var/www/apt.homed.dev -C main includedeb debian ${PACKAGE_FILE}" 13 | artifacts: 14 | paths: 15 | - ${PACKAGE_FILE} 16 | expire_in: never 17 | rules: 18 | - if: $CI_COMMIT_TAG =~ /^\d.\d+.\d+$/ 19 | when: always 20 | - when: never 21 | 22 | .deploy_openwrt: 23 | stage: deploy 24 | variables: 25 | PACKAGE_FILE: homed-common_${CI_COMMIT_TAG}_${ARCHITECTURE}.ipk 26 | FEED_DIR: /var/www/opkg.homed.dev/${ARCHITECTURE} 27 | script: 28 | - "sed -i \"s+^Version:.*+Version: ${CI_COMMIT_TAG}+g\" deploy/opkg/control" 29 | - "sed -i \"s+^Architecture:.*+Architecture: ${ARCHITECTURE}+g\" deploy/opkg/control" 30 | - "echo \"2.0\" > debian-binary" 31 | - "fakeroot tar -czf control.tar.gz -C deploy/opkg ." 32 | - "fakeroot tar -czf data.tar.gz -C deploy/data ." 33 | - "fakeroot tar -czf ${PACKAGE_FILE} control.tar.gz data.tar.gz debian-binary" 34 | - "mkdir -p ${FEED_DIR}" 35 | - "rm -f ${FEED_DIR}/homed-common_*" 36 | - "cp ${PACKAGE_FILE} ${FEED_DIR}" 37 | - "/opt/scripts/opkgIndex.sh ${FEED_DIR} > ${FEED_DIR}/Packages" 38 | - "/opt/opkg/usign -S -m ${FEED_DIR}/Packages -s /opt/opkg/opkg.key -x ${FEED_DIR}/Packages.sig" 39 | - "gzip -fk ${FEED_DIR}/Packages" 40 | artifacts: 41 | paths: 42 | - ${PACKAGE_FILE} 43 | expire_in: never 44 | rules: 45 | - if: $CI_COMMIT_TAG =~ /^\d.\d+.\d+$/ 46 | when: always 47 | - when: never 48 | 49 | .deploy_entware: 50 | stage: deploy 51 | variables: 52 | PACKAGE_FILE: homed-common_${CI_COMMIT_TAG}_${ARCHITECTURE}.ipk 53 | FEED_DIR: /var/www/entware.homed.su/${ARCHITECTURE} 54 | script: 55 | - "mv deploy/data/usr deploy/data/opt" 56 | - "sed -i \"s+^Version:.*+Version: ${CI_COMMIT_TAG}+g\" deploy/entware/control" 57 | - "sed -i \"s+^Architecture:.*+Architecture: ${ARCHITECTURE}+g\" deploy/entware/control" 58 | - "echo \"2.0\" > debian-binary" 59 | - "fakeroot tar -czf control.tar.gz -C deploy/entware ." 60 | - "fakeroot tar -czf data.tar.gz -C deploy/data ." 61 | - "fakeroot tar -czf ${PACKAGE_FILE} control.tar.gz data.tar.gz debian-binary" 62 | - "mv deploy/data/opt deploy/data/usr" 63 | - "mkdir -p ${FEED_DIR}" 64 | - "rm -f ${FEED_DIR}/homed-common_*" 65 | - "cp ${PACKAGE_FILE} ${FEED_DIR}" 66 | - "/opt/scripts/opkgIndex.sh ${FEED_DIR} > ${FEED_DIR}/Packages" 67 | - "gzip -fk ${FEED_DIR}/Packages" 68 | artifacts: 69 | paths: 70 | - ${PACKAGE_FILE} 71 | expire_in: never 72 | rules: 73 | - if: $CI_COMMIT_TAG =~ /^\d.\d+.\d+$/ 74 | when: always 75 | - when: never 76 | 77 | Clone repository: 78 | script: "echo \"Common files for HOMEd services build\"" 79 | 80 | Clean Up Linux Packages: 81 | stage: deploy 82 | script: 83 | - "/opt/scripts/aptRemove.sh homed-common" 84 | rules: 85 | - if: $CI_COMMIT_TAG =~ /^\d.\d+.\d+$/ 86 | when: always 87 | - when: never 88 | 89 | Deploy Linux Package (amd64): 90 | extends: .deploy_linux 91 | variables: 92 | ARCHITECTURE: amd64 93 | 94 | Deploy Linux Package (aarch64): 95 | extends: .deploy_linux 96 | variables: 97 | ARCHITECTURE: aarch64 98 | 99 | Deploy Linux Package (arm64): 100 | extends: .deploy_linux 101 | variables: 102 | ARCHITECTURE: arm64 103 | 104 | Deploy Linux Package (armhf): 105 | extends: .deploy_linux 106 | variables: 107 | ARCHITECTURE: armhf 108 | 109 | Deploy OpenWRT Package (aarch64_generic): 110 | extends: .deploy_openwrt 111 | variables: 112 | ARCHITECTURE: aarch64_generic 113 | 114 | Deploy OpenWRT Package (arm_cortex-a7_neon-vfpv4): 115 | extends: .deploy_openwrt 116 | variables: 117 | ARCHITECTURE: arm_cortex-a7_neon-vfpv4 118 | 119 | Deploy OpenWRT Package (arm_cortex-a9_neon): 120 | extends: .deploy_openwrt 121 | variables: 122 | ARCHITECTURE: arm_cortex-a9_neon 123 | 124 | Deploy OpenWRT Package (mips_24kc): 125 | extends: .deploy_openwrt 126 | variables: 127 | ARCHITECTURE: mips_24kc 128 | 129 | Deploy OpenWRT Package (mipsel_24kc): 130 | extends: .deploy_openwrt 131 | variables: 132 | ARCHITECTURE: mipsel_24kc 133 | 134 | Deploy Keenetic NDMS Package (aarch64-3.10): 135 | extends: .deploy_entware 136 | variables: 137 | ARCHITECTURE: aarch64-3.10 138 | 139 | Deploy Keenetic NDMS Package (mips-3.4): 140 | extends: .deploy_entware 141 | variables: 142 | ARCHITECTURE: mips-3.4 143 | 144 | Deploy Keenetic NDMS Package (mipsel-3.4): 145 | extends: .deploy_entware 146 | variables: 147 | ARCHITECTURE: mipsel-3.4 148 | -------------------------------------------------------------------------------- /.gitlab-ci/deploy.yml: -------------------------------------------------------------------------------- 1 | .deploy_linux: 2 | stage: deploy 3 | variables: 4 | PACKAGE_FILE: ${NAME}_${CI_COMMIT_TAG}_${ARCHITECTURE}.deb 5 | script: 6 | - "[[ -n ${PACKAGE_EXTRA} ]] && sh -c \"${PACKAGE_EXTRA}\"" 7 | - "mkdir -p deploy/data/lib/systemd/system" 8 | - "mkdir -p deploy/data/usr/bin" 9 | - "cp -r deploy/apt deploy/data/DEBIAN" 10 | - "cp deploy/systemd/${NAME}.service deploy/data/lib/systemd/system" 11 | - "cp ${NAME}-linux-${ARCHITECTURE} deploy/data/usr/bin/${NAME}" 12 | - "md5deep -lr deploy/data | grep -v DEBIAN | sed \"s+deploy/data/++g\" | sort -k2 > deploy/data/DEBIAN/md5sums" 13 | - "sed -i \"s+^Version:.*+Version: ${CI_COMMIT_TAG}+g\" deploy/data/DEBIAN/control" 14 | - "sed -i \"s+^Architecture:.*+Architecture: ${ARCHITECTURE}+g\" deploy/data/DEBIAN/control" 15 | - "chmod +x deploy/data/DEBIAN/postinst" 16 | - "chmod +x deploy/data/DEBIAN/prerm" 17 | - "fakeroot dpkg-deb --build deploy/data" 18 | - "mv deploy/data.deb ${PACKAGE_FILE}" 19 | - "reprepro -b /var/www/apt.homed.dev -C main includedeb debian ${PACKAGE_FILE}" 20 | artifacts: 21 | paths: 22 | - ${PACKAGE_FILE} 23 | expire_in: never 24 | rules: 25 | - if: $CI_COMMIT_TAG =~ /^\d.\d+.\d+$/ 26 | when: always 27 | - when: never 28 | 29 | .deploy_openwrt: 30 | stage: deploy 31 | variables: 32 | PACKAGE_FILE: ${NAME}_${CI_COMMIT_TAG}_${ARCHITECTURE}.ipk 33 | FEED_DIR: /var/www/opkg.homed.dev/${ARCHITECTURE} 34 | script: 35 | - "[[ -n ${PACKAGE_EXTRA} ]] && sh -c \"${PACKAGE_EXTRA}\"" 36 | - "mkdir -p deploy/data/etc/init.d" 37 | - "mkdir -p deploy/data/usr/bin" 38 | - "cp -r deploy/luci/* deploy/data" 39 | - "cp deploy/procd/${NAME} deploy/data/etc/init.d" 40 | - "cp ${NAME}-openwrt-${ARCHITECTURE} deploy/data/usr/bin/${NAME}" 41 | - "sed -i \"s+^Version:.*+Version: ${CI_COMMIT_TAG}+g\" deploy/opkg/control" 42 | - "sed -i \"s+^Architecture:.*+Architecture: ${ARCHITECTURE}+g\" deploy/opkg/control" 43 | - "echo \"2.0\" > debian-binary" 44 | - "chmod +x deploy/data/etc/init.d/${NAME}" 45 | - "chmod +x deploy/opkg/postinst" 46 | - "chmod +x deploy/opkg/prerm" 47 | - "fakeroot tar -czf control.tar.gz -C deploy/opkg ." 48 | - "fakeroot tar -czf data.tar.gz -C deploy/data ." 49 | - "fakeroot tar -czf ${PACKAGE_FILE} control.tar.gz data.tar.gz debian-binary" 50 | - "mkdir -p ${FEED_DIR}" 51 | - "rm -f ${FEED_DIR}/${NAME}_*" 52 | - "cp ${PACKAGE_FILE} ${FEED_DIR}" 53 | - "/opt/scripts/opkgIndex.sh ${FEED_DIR} > ${FEED_DIR}/Packages" 54 | - "/opt/opkg/usign -S -m ${FEED_DIR}/Packages -s /opt/opkg/opkg.key -x ${FEED_DIR}/Packages.sig" 55 | - "gzip -fk ${FEED_DIR}/Packages" 56 | artifacts: 57 | paths: 58 | - ${PACKAGE_FILE} 59 | expire_in: never 60 | rules: 61 | - if: $CI_COMMIT_TAG =~ /^\d.\d+.\d+$/ 62 | when: always 63 | - when: never 64 | 65 | .deploy_entware: 66 | stage: deploy 67 | variables: 68 | PACKAGE_FILE: ${NAME}_${CI_COMMIT_TAG}_${ARCHITECTURE}.ipk 69 | FEED_DIR: /var/www/entware.homed.su/${ARCHITECTURE} 70 | script: 71 | - "[[ -n ${PACKAGE_EXTRA} ]] && sh -c \"${PACKAGE_EXTRA}\"" 72 | - "[[ -f deploy/data/etc/homed/${NAME}.conf ]] && sed -i -e \"s\\=/opt/${NAME}\\=/opt/var/lib/${NAME}\\g\" -e \"s\\=/usr/share\\=/opt/share\\g\" -e \"s\\=/var/log\\=/opt/var/log\\g\" deploy/data/etc/homed/${NAME}.conf && mkdir -p deploy/data/opt/etc/homed && mv deploy/data/etc/homed/${NAME}.conf deploy/data/opt/etc/homed && rm -r deploy/data/etc" 73 | - "[[ -d deploy/data/usr/share/${NAME} ]] && mkdir -p deploy/data/opt/share && mv deploy/data/usr/share/${NAME} deploy/data/opt/share && rm -r deploy/data/usr" 74 | - "[[ -d deploy/data/opt/${NAME} ]] && mkdir -p deploy/data/opt/var/lib && mv deploy/data/opt/${NAME} deploy/data/opt/var/lib/${NAME}" 75 | - "mkdir -p deploy/data/opt/etc/init.d" 76 | - "mkdir -p deploy/data/opt/bin" 77 | - "mv deploy/entware/S* deploy/data/opt/etc/init.d" 78 | - "cp ${NAME}-entware-${ARCHITECTURE} deploy/data/opt/bin/${NAME}" 79 | - "sed -i \"s+^Version:.*+Version: ${CI_COMMIT_TAG}+g\" deploy/entware/control" 80 | - "sed -i \"s+^Architecture:.*+Architecture: ${ARCHITECTURE}+g\" deploy/entware/control" 81 | - "echo \"2.0\" > debian-binary" 82 | - "chmod +x deploy/data/opt/etc/init.d/*" 83 | - "fakeroot tar -czf control.tar.gz -C deploy/entware ." 84 | - "fakeroot tar -czf data.tar.gz -C deploy/data ." 85 | - "fakeroot tar -czf ${PACKAGE_FILE} control.tar.gz data.tar.gz debian-binary" 86 | - "mkdir -p ${FEED_DIR}" 87 | - "rm -f ${FEED_DIR}/${NAME}_*" 88 | - "cp ${PACKAGE_FILE} ${FEED_DIR}" 89 | - "/opt/scripts/opkgIndex.sh ${FEED_DIR} > ${FEED_DIR}/Packages" 90 | - "gzip -fk ${FEED_DIR}/Packages" 91 | artifacts: 92 | paths: 93 | - ${PACKAGE_FILE} 94 | expire_in: never 95 | rules: 96 | - if: $CI_COMMIT_TAG =~ /^\d.\d+.\d+$/ 97 | when: always 98 | - when: never 99 | 100 | .deploy_docker: 101 | stage: deploy 102 | script: 103 | - "[[ -n ${DOCKER_EXTRA} ]] && sh -c \"${DOCKER_EXTRA}\"" 104 | - "cp ${NAME}-linux-amd64 deploy/docker/${NAME}-amd64" 105 | - "cp ${NAME}-linux-aarch64 deploy/docker/${NAME}-arm64" 106 | - "cp ${NAME}-linux-armhf deploy/docker/${NAME}-arm" 107 | - "docker buildx create --driver-opt network=host --name job_${CI_JOB_ID} --use" 108 | - "docker buildx build --platform linux/arm64,linux/arm/v7,linux/amd64 --push ${TAGS} deploy/docker/" 109 | - "docker buildx prune -af" 110 | - "docker buildx rm" 111 | 112 | Clean Up Linux Packages: 113 | stage: deploy 114 | script: 115 | - "/opt/scripts/aptRemove.sh ${NAME}" 116 | rules: 117 | - if: $CI_COMMIT_TAG =~ /^\d.\d+.\d+$/ 118 | when: always 119 | - when: never 120 | 121 | Deploy Linux Package (amd64): 122 | extends: .deploy_linux 123 | variables: 124 | ARCHITECTURE: amd64 125 | 126 | Deploy Linux Package (aarch64): 127 | extends: .deploy_linux 128 | variables: 129 | ARCHITECTURE: aarch64 130 | 131 | Deploy Linux Package (arm64): 132 | extends: .deploy_linux 133 | variables: 134 | ARCHITECTURE: arm64 135 | 136 | Deploy Linux Package (armhf): 137 | extends: .deploy_linux 138 | variables: 139 | ARCHITECTURE: armhf 140 | 141 | Deploy OpenWRT Package (aarch64_generic): 142 | extends: .deploy_openwrt 143 | variables: 144 | ARCHITECTURE: aarch64_generic 145 | 146 | Deploy OpenWRT Package (arm_cortex-a7_neon-vfpv4): 147 | extends: .deploy_openwrt 148 | variables: 149 | ARCHITECTURE: arm_cortex-a7_neon-vfpv4 150 | 151 | Deploy OpenWRT Package (arm_cortex-a9_neon): 152 | extends: .deploy_openwrt 153 | variables: 154 | ARCHITECTURE: arm_cortex-a9_neon 155 | 156 | Deploy OpenWRT Package (mips_24kc): 157 | extends: .deploy_openwrt 158 | variables: 159 | ARCHITECTURE: mips_24kc 160 | 161 | Deploy OpenWRT Package (mipsel_24kc): 162 | extends: .deploy_openwrt 163 | variables: 164 | ARCHITECTURE: mipsel_24kc 165 | 166 | Deploy Keenetic NDMS Package (aarch64-3.10): 167 | extends: .deploy_entware 168 | variables: 169 | ARCHITECTURE: aarch64-3.10 170 | 171 | Deploy Keenetic NDMS Package (mips-3.4): 172 | extends: .deploy_entware 173 | variables: 174 | ARCHITECTURE: mips-3.4 175 | 176 | Deploy Keenetic NDMS Package (mipsel-3.4): 177 | extends: .deploy_entware 178 | variables: 179 | ARCHITECTURE: mipsel-3.4 180 | 181 | Deploy Docker Images (release): 182 | extends: .deploy_docker 183 | variables: 184 | TAGS: --tag 127.0.0.1:5000/${NAME}:${CI_COMMIT_TAG} --tag 127.0.0.1:5000/${NAME}:latest 185 | rules: 186 | - if: $CI_COMMIT_TAG =~ /^\d.\d+.\d+$/ 187 | when: always 188 | - when: never 189 | 190 | Deploy Docker Images (development): 191 | extends: .deploy_docker 192 | variables: 193 | TAGS: --tag 127.0.0.1:5000/${NAME}:dev 194 | rules: 195 | - if: $CI_COMMIT_TAG == "dev" 196 | when: always 197 | - when: never 198 | -------------------------------------------------------------------------------- /homed.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "homed.h" 5 | #include "logger.h" 6 | 7 | HOMEd::HOMEd(const QString &version, const QString &configFile, bool multiple) : QObject(nullptr), m_mqtt(new QMqttClient(this)), m_statusTimer(new QTimer(this)), m_reconnectTimer(new QTimer(this)), m_watcher(new QFileSystemWatcher(this)), m_connected(false), m_first(true) 8 | { 9 | QDate date = QDate::currentDate(); 10 | QString instance; 11 | 12 | m_config = new QSettings(configFile.isEmpty() ? QString("/etc/homed/%1.conf").arg(QCoreApplication::applicationName()) : configFile, QSettings::IniFormat, this); 13 | m_watcher->addPath(m_config->fileName()); 14 | 15 | setLogEnabled(m_config->value("log/enabled", false).toBool()); 16 | setLogTimestams(m_config->value("log/timestamps", true).toBool()); 17 | setLogFile(m_config->value("log/file", "/var/log/homed.log").toString()); 18 | qInstallMessageHandler(logger); 19 | 20 | m_mqttPrefix = m_config->value("mqtt/prefix", "homed").toString(); 21 | m_interval = static_cast (m_config->value("mqtt/interval").toInt() * 1000); 22 | instance = m_config->value("mqtt/instance").toString(); 23 | 24 | if (date > QDate(date.year(), 12, 23) || date < QDate(date.year(), 1, 15)) 25 | logInfo << "Merry Christmas and a Happy New Year!" << "\xF0\x9F\x8E\x81\xF0\x9F\x8E\x84\xF0\x9F\x8D\xBA"; 26 | 27 | logInfo << "Starting version" << version.toUtf8().constData(); 28 | logInfo << "Configuration file is" << getConfig()->fileName(); 29 | logInfo << "MQTT prefix is" << m_mqttPrefix; 30 | 31 | m_serviceTopic = QCoreApplication::applicationName().split('-').last(); 32 | m_uniqueId = QString("homed-%1_%2").arg(m_serviceTopic, QString(m_mqttPrefix).replace('/', '-')); 33 | 34 | if (multiple && !instance.isEmpty()) 35 | { 36 | logInfo << "Instance name is" << instance; 37 | m_serviceTopic.append('/').append(instance); 38 | m_uniqueId.append('_').append(instance); 39 | } 40 | 41 | m_mqtt->setHostname(m_config->value("mqtt/host", "localhost").toString()); 42 | m_mqtt->setPort(static_cast (m_config->value("mqtt/port", 1883).toInt())); 43 | m_mqtt->setUsername(m_config->value("mqtt/username").toString()); 44 | m_mqtt->setPassword(m_config->value("mqtt/password").toString()); 45 | 46 | m_mqtt->setWillTopic(mqttTopic("service/%1").arg(m_serviceTopic)); 47 | m_mqtt->setWillMessage(QJsonDocument(QJsonObject {{"status", "offline"}}).toJson(QJsonDocument::Compact)); 48 | m_mqtt->setWillRetain(true); 49 | 50 | connect(m_mqtt, &QMqttClient::connected, this, &HOMEd::connected, Qt::QueuedConnection); 51 | connect(m_mqtt, &QMqttClient::disconnected, this, &HOMEd::disconnected, Qt::QueuedConnection); 52 | connect(m_mqtt, &QMqttClient::messageReceived, this, &HOMEd::mqttReceived, Qt::QueuedConnection); 53 | 54 | connect(m_reconnectTimer, &QTimer::timeout, this, &HOMEd::reconnect, Qt::QueuedConnection); 55 | connect(m_statusTimer, &QTimer::timeout, this, &HOMEd::publishStatus, Qt::QueuedConnection); 56 | connect(m_watcher, &QFileSystemWatcher::fileChanged, this, &HOMEd::fileChanged, Qt::QueuedConnection); 57 | 58 | m_reconnectTimer->setSingleShot(true); 59 | m_statusTimer->setSingleShot(true); 60 | 61 | m_mqtt->connectToHost(); 62 | } 63 | 64 | void HOMEd::quit(void) 65 | { 66 | logInfo << "Goodbye!"; 67 | mqttPublishStatus(false); 68 | m_mqtt->disconnectFromHost(); 69 | } 70 | 71 | void HOMEd::mqttSubscribe(const QString &topic) 72 | { 73 | m_mqtt->subscribe(topic, MQTT_DEFAULT_QOS); 74 | } 75 | 76 | void HOMEd::mqttUnsubscribe(const QString &topic) 77 | { 78 | m_mqtt->unsubscribe(topic); 79 | } 80 | 81 | void HOMEd::mqttPublish(const QString &topic, const QJsonObject &json, bool retain) 82 | { 83 | m_mqtt->publish(topic, json.isEmpty() ? QByteArray() : QJsonDocument(json).toJson(QJsonDocument::Compact), MQTT_DEFAULT_QOS, retain); 84 | } 85 | 86 | void HOMEd::mqttPublishString(const QString &topic, const QString &message, bool retain) 87 | { 88 | m_mqtt->publish(topic, message.toUtf8(), MQTT_DEFAULT_QOS, retain); 89 | } 90 | 91 | void HOMEd::mqttPublishDiscovery(const QString &name, const QString &version, const QString &haPrefix, bool permitJoin) 92 | { 93 | QList list = {"connectivity", "lastSeen", "version", "permitJoin", "restartService"}; 94 | QJsonObject identity; 95 | 96 | identity.insert("identifiers", QJsonArray {m_uniqueId}); 97 | identity.insert("name", QString("HOMEd %1 (%2)").arg(name, m_mqttPrefix)); 98 | identity.insert("model", QString("HOMEd %1 Service (%2)").arg(name, m_mqttPrefix)); 99 | identity.insert("sw_version", version); 100 | 101 | for (int i = 0; i < list.count(); i++) 102 | { 103 | QString component, item = list.at(i); 104 | QJsonObject json; 105 | 106 | switch (i) 107 | { 108 | case 0: // connectivity 109 | component = "binary_sensor"; 110 | json.insert("device_class", "connectivity"); 111 | json.insert("state_topic", mqttTopic("service/%1").arg(m_serviceTopic)); 112 | json.insert("value_template", "{{ value_json.status }}"); 113 | json.insert("payload_on", "online"); 114 | json.insert("payload_off", "offline"); 115 | break; 116 | 117 | case 1: // lastSeen 118 | 119 | if (!m_interval) 120 | continue; 121 | 122 | component = "sensor"; 123 | json.insert("device_class", "timestamp"); 124 | json.insert("icon", "mdi:clock"); 125 | json.insert("state_topic", mqttTopic("service/%1").arg(m_serviceTopic)); 126 | json.insert("value_template", "{{ value_json.timestamp | is_defined | timestamp_local }}"); 127 | break; 128 | 129 | case 2: // version 130 | component = "sensor"; 131 | json.insert("icon", "mdi:tag"); 132 | json.insert("state_topic", mqttTopic("status/%1").arg(m_serviceTopic)); 133 | json.insert("value_template", "{{ value_json.version }}"); 134 | break; 135 | 136 | case 3: // permitJoin 137 | 138 | if (!permitJoin) 139 | continue; 140 | 141 | component = "switch"; 142 | json.insert("icon", "mdi:human-greeting"); 143 | json.insert("state_topic", mqttTopic("status/%1").arg(m_serviceTopic)); 144 | json.insert("command_topic", mqttTopic("command/%1").arg(m_serviceTopic)); 145 | json.insert("value_template", "{{ value_json.permitJoin }}"); 146 | json.insert("state_on", true); 147 | json.insert("state_off", false); 148 | json.insert("payload_on", "{\"action\": \"setPermitJoin\", \"enabled\": true}"); 149 | json.insert("payload_off", "{\"action\": \"setPermitJoin\", \"enabled\": false}"); 150 | break; 151 | 152 | case 4: // restartService 153 | component = "button"; 154 | json.insert("icon", "mdi:restart"); 155 | json.insert("command_topic", mqttTopic("command/%1").arg(m_serviceTopic)); 156 | json.insert("payload_press", "{\"action\": \"restartService\"}"); 157 | break; 158 | } 159 | 160 | if (i) 161 | { 162 | json.insert("availability_topic", mqttTopic("service/%1").arg(m_serviceTopic)); 163 | json.insert("availability_template", "{{ value_json.status }}"); 164 | } 165 | 166 | json.insert("device", identity); 167 | json.insert("entity_category", i < 3 ? "diagnostic" : "config"); 168 | json.insert("name", QString(item).replace(QRegExp("([A-Z])"), " \\1").replace(0, 1, item.at(0).toUpper())); 169 | json.insert("unique_id", QString("%1_%2").arg(m_uniqueId, item)); 170 | 171 | mqttPublish(QString("%1/%2/%3/%4/config").arg(haPrefix, component, m_uniqueId, item), json, true); 172 | } 173 | } 174 | 175 | void HOMEd::mqttPublishStatus(bool online) 176 | { 177 | QJsonObject json = {{"status", online ? "online" : "offline"}}; 178 | 179 | if (online && m_interval) 180 | { 181 | if (!m_statusTimer->isActive()) 182 | m_statusTimer->start(m_interval); 183 | 184 | json.insert("timestamp", QDateTime::currentSecsSinceEpoch()); 185 | } 186 | 187 | mqttPublish(mqttTopic("service/%1").arg(m_serviceTopic), json, true); 188 | } 189 | 190 | QString HOMEd::mqttTopic(const QString &topic) 191 | { 192 | return QString("%1/%2").arg(m_mqttPrefix, topic); 193 | } 194 | 195 | void HOMEd::connected(void) 196 | { 197 | m_connected = true; 198 | logInfo << "MQTT connected to" << QString("%1:%2").arg(m_mqtt->hostname()).arg(m_mqtt->port()); 199 | mqttConnected(); 200 | } 201 | 202 | void HOMEd::disconnected(void) 203 | { 204 | m_statusTimer->stop(); 205 | m_reconnectTimer->start(MQTT_RECONNECT_INTERVAL); 206 | 207 | if (!m_connected && !m_first) 208 | return; 209 | 210 | m_connected = false; 211 | m_first = false; 212 | 213 | logWarning << "MQTT disconnected"; 214 | mqttDisconnected(); 215 | } 216 | 217 | void HOMEd::reconnect(void) 218 | { 219 | m_mqtt->connectToHost(); 220 | } 221 | 222 | void HOMEd::publishStatus(void) 223 | { 224 | mqttPublishStatus(); 225 | } 226 | 227 | void HOMEd::fileChanged(void) 228 | { 229 | logWarning << "Configuration file changed, restarting..."; 230 | QCoreApplication::exit(EXIT_RESTART); 231 | } 232 | -------------------------------------------------------------------------------- /endpoint.cpp: -------------------------------------------------------------------------------- 1 | #include "endpoint.h" 2 | #include "expose.h" 3 | 4 | void AbstractDeviceObject::publishExposes(HOMEd *controller, const QString &address, const QString uniqueId, const QString haPrefix, bool haEnabled, bool names, bool remove) 5 | { 6 | QMap data, endpointName = m_options.value("endpointName").toMap(); 7 | QList trigger = {"action", "event", "scene"}; 8 | 9 | for (auto it = m_endpoints.begin(); it != m_endpoints.end(); it++) 10 | { 11 | AbstractEndpointObject *endpoint = reinterpret_cast (it.value().data()); 12 | 13 | for (int i = 0; i < endpoint->exposes().count(); i++) 14 | { 15 | const Expose &expose = endpoint->exposes().at(i); 16 | QVariant option = expose->option(); 17 | 18 | if (haEnabled && expose->discovery()) 19 | { 20 | QString id = expose->multiple() ? QString::number(it.key()) : QString(), title = exposeTitle(expose), topic = names ? m_name : address; 21 | QList object = {expose->name()}; 22 | QJsonObject json, identity; 23 | QJsonArray availability; 24 | 25 | if (!id.isEmpty()) 26 | { 27 | title = endpointName.contains(id) ? endpointName.value(id).toString().append(0x20).append(title) : title.append(0x20).append(id); 28 | topic.append('/').append(id); 29 | object.append(id); 30 | } 31 | 32 | if (m_discovery && !remove) 33 | { 34 | expose->setStateTopic(controller->mqttTopic("fd/%1/%2").arg(controller->serviceTopic(), topic)); 35 | expose->setCommandTopic(controller->mqttTopic("td/%1/%2").arg(controller->serviceTopic(), topic)); 36 | 37 | json = expose->request(); 38 | 39 | identity.insert("identifiers", QJsonArray {QString(uniqueId)}); 40 | identity.insert("name", m_name); 41 | identity.insert("via_device", controller->uniqueId()); 42 | 43 | if (!m_description.isEmpty()) 44 | identity.insert("model", m_description); 45 | 46 | availability.append(QJsonObject {{"topic", controller->mqttTopic("device/%1/%2").arg(controller->serviceTopic(), names ? m_name : address)}, {"value_template", "{{ value_json.status }}"}}); 47 | availability.append(QJsonObject {{"topic", controller->mqttTopic("service/%1").arg(controller->serviceTopic())}, {"value_template", "{{ value_json.status }}"}}); 48 | 49 | json.insert("availability", availability); 50 | json.insert("availability_mode", "all"); 51 | json.insert("device", identity); 52 | json.insert("name", title); 53 | json.insert("unique_id", QString("%1_%2").arg(uniqueId, object.join('_'))); 54 | } 55 | 56 | controller->mqttPublish(QString("%1/%2/%3/%4/config").arg(haPrefix, expose->component(), uniqueId, object.join('_')), json, true); 57 | 58 | if (trigger.contains(expose->name())) 59 | { 60 | QVariant data = option.toMap().value("enum"); 61 | QList list = data.type() == QVariant::Map ? QVariant(data.toMap().values()).toStringList() : data.toStringList(); 62 | 63 | for (int i = 0; i < list.count(); i++) 64 | { 65 | QString subtype = list.at(i); 66 | QList event = {subtype}; 67 | 68 | subtype.replace(QRegExp("([A-Z])"), " \\1").replace(0, 1, subtype.at(0).toUpper()); 69 | json = QJsonObject(); 70 | 71 | if (!id.isEmpty()) 72 | { 73 | if (endpointName.contains(id)) 74 | subtype.prepend(0x20).prepend(endpointName.value(id).toString()); 75 | else 76 | subtype.append(0x20).append(id); 77 | 78 | event.append(id); 79 | } 80 | 81 | if (m_discovery && !remove) 82 | { 83 | json.insert("automation_type", "trigger"); 84 | json.insert("device", identity); 85 | json.insert("payload", event.at(0)); 86 | json.insert("subtype", subtype); 87 | json.insert("topic", controller->mqttTopic("fd/%1/%2").arg(controller->serviceTopic(), topic)); 88 | json.insert("type", expose->name()); 89 | json.insert("value_template", QString("{{ value_json.%1 }}").arg(expose->name())); 90 | } 91 | 92 | controller->mqttPublish(QString("%1/device_automation/%2/%3/config").arg(haPrefix, uniqueId, event.join('_')), json, true); 93 | } 94 | 95 | json = QJsonObject(); 96 | 97 | if (m_discovery && !remove) 98 | { 99 | json.insert("availability", availability); 100 | json.insert("availability_mode", "all"); 101 | json.insert("device", identity); 102 | json.insert("event_types", QJsonArray::fromStringList(list)); 103 | json.insert("name", title); 104 | json.insert("state_topic", controller->mqttTopic("fd/%1/%2").arg(controller->serviceTopic(), topic)); 105 | json.insert("unique_id", QString("%1_%2").arg(uniqueId, object.join('_'))); 106 | json.insert("value_template", QString("{% if value_json.%1 is defined %}{\"event_type\":\"{{ value_json.%1 }}\"}{% endif %}").arg(expose->name())); 107 | } 108 | 109 | controller->mqttPublish(QString("%1/event/%2/%3/config").arg(haPrefix, uniqueId, object.join('_')), json, true); 110 | } 111 | } 112 | 113 | if (!remove) 114 | { 115 | QString id = QString::number(it.key()), key = expose->multiple() ? id : "common", yandexType = expose->option("yandexType").toString(); 116 | QMap map = data.value(key).toMap(), options = map.value("options").toMap(); 117 | QList items = map.value("items").toStringList(); 118 | 119 | items.append(expose->name()); 120 | map.insert("items", QVariant(items)); 121 | 122 | if (expose->name().startsWith("light") && option.toStringList().contains("colorTemperature")) 123 | { 124 | QVariant colorTemperature = expose->option("colorTemperature"); 125 | options.insert("colorTemperature", colorTemperature.isValid() ? colorTemperature : QMap {{"min", 153}, {"max", 500}}); 126 | } 127 | 128 | if (expose->name() == "thermostat") 129 | { 130 | QVariant systemMode = expose->option("systemMode"), operationMode = expose->option("operationMode"), targetTemperature = expose->option("targetTemperature"), runningStatus = expose->option("runningStatus"), programTransitions = expose->option("programTransitions"), programType = expose->option("programType"); 131 | 132 | if (systemMode.isValid()) 133 | options.insert("systemMode", systemMode); 134 | 135 | if (operationMode.isValid()) 136 | options.insert("operationMode", operationMode); 137 | 138 | if (targetTemperature.isValid()) 139 | options.insert("targetTemperature", targetTemperature); 140 | 141 | if (runningStatus.isValid()) 142 | options.insert("runningStatus", runningStatus); 143 | 144 | if (programTransitions.isValid()) 145 | options.insert("programTransitions", programTransitions); 146 | 147 | if (programType.isValid()) 148 | options.insert("programType", programType); 149 | } 150 | 151 | if (option.isValid()) 152 | options.insert(expose->name(), option); 153 | 154 | if (expose->multiple() && endpointName.contains(id)) 155 | options.insert("name", endpointName.value(id)); 156 | 157 | if (!yandexType.isEmpty()) 158 | options.insert("yandexType", yandexType); 159 | 160 | if (!options.isEmpty()) 161 | map.insert("options", options); 162 | 163 | data.insert(key, map); 164 | } 165 | } 166 | } 167 | 168 | controller->mqttPublish(controller->mqttTopic("expose/%1/%2").arg(controller->serviceTopic(), names ? m_name : address), QJsonObject::fromVariantMap(data), true); 169 | } 170 | 171 | QString AbstractDeviceObject::exposeTitle(const Expose &expose) 172 | { 173 | QString title = expose->option().toMap().value("title").toString(); 174 | 175 | if (title.isEmpty()) 176 | { 177 | QList list = expose->name().replace('_', 0x20).replace(QRegExp("([A-Z])"), " \\1").toLower().split(0x20); 178 | QMap replacement = {{"co2", "CO2"}, {"eco2", "eCO2"}, {"pm", "PM"}, {"pm1", "PM1"}, {"pm4", "PM4"}, {"pm10", "PM10"}, {"pm25", "PM2.5"}, {"uv", "UV"}, {"voc", "VOC"}}; 179 | 180 | if (replacement.contains(list.value(0))) 181 | list.replace(0, replacement.value(list.value(0))); 182 | 183 | return list.join(0x20).replace(0, 1, list.value(0).at(0).toUpper()); 184 | } 185 | else 186 | { 187 | QList list = expose->name().split('_'); 188 | return QRegExp("\\d+").exactMatch(list.value(1)) ? title.append(0x20).append(list.value(1)) : title; 189 | } 190 | } 191 | 192 | QVariant AbstractMetaObject::option(const QString &name, const QVariant &defaultValue) 193 | { 194 | QVariant value; 195 | 196 | if (m_parent) 197 | { 198 | AbstractDeviceObject *device = reinterpret_cast (m_parent->device().data()); 199 | QString optionName = name.isEmpty() ? m_name : name; 200 | QList list = optionName.split('_'); 201 | 202 | if (list.count() < 2) 203 | optionName.append(QString("_%2").arg(m_parent->id())); 204 | 205 | value = device->options().contains(optionName) ? device->options().value(optionName) : device->options().value(list.at(0), defaultValue); 206 | } 207 | 208 | return value; 209 | } 210 | 211 | quint8 AbstractMetaObject::version(void) 212 | { 213 | return m_parent ? reinterpret_cast (m_parent->device().data())->version() : 0; 214 | } 215 | 216 | QString AbstractMetaObject::manufacturerName(void) 217 | { 218 | return m_parent ? reinterpret_cast (m_parent->device().data())->manufacturerName() : QString(); 219 | } 220 | 221 | QString AbstractMetaObject::modelName(void) 222 | { 223 | return m_parent ? reinterpret_cast (m_parent->device().data())->modelName() : QString(); 224 | } 225 | 226 | QVariant AbstractMetaObject::meta(const QString &key, const QVariant &defaultValue) 227 | { 228 | return m_parent ? m_parent->meta().value(key, defaultValue) : defaultValue; 229 | } 230 | 231 | void AbstractMetaObject::setMeta(const QString &key, const QVariant &value) 232 | { 233 | if (!m_parent) 234 | return; 235 | 236 | m_parent->meta().insert(key, value); 237 | } 238 | 239 | void AbstractMetaObject::clearMeta(const QString &key) 240 | { 241 | if (!m_parent) 242 | return; 243 | 244 | m_parent->meta().remove(key); 245 | } 246 | -------------------------------------------------------------------------------- /parser.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "parser.h" 5 | 6 | Expression::Expression(QString string) : m_result(NAN) 7 | { 8 | QRegExp error("([^0-9a-z\\+\\-\\*\\/\\%\\^\\(\\)\\.\\,\\ ])"), number("([0-9]+\\.?[0-9]*)"), negative(QString("(^\\-|[\\+\\-\\*\\/\\^\\(]-)").append(number.pattern())), expression(number.pattern().append("|([()])|([\\+\\-\\*\\/\\%\\^\\,])|(round|ceil|floor|sqrt|exp|min|max|random)")); 9 | QVector items; 10 | QStack operationStack; 11 | QStack priorityStack; 12 | int position = 0, offset = 0; 13 | 14 | string.remove(0x0A); 15 | string.remove(0x0D); 16 | string.remove(0x20); 17 | 18 | if (string.isEmpty() || error.indexIn(string) != -1 || string.count("(") != string.count(")") || string.contains("()")) 19 | return; 20 | 21 | while ((position = negative.indexIn(string, position)) != -1) 22 | { 23 | QString value = negative.cap(); 24 | string.replace(position, value.length(), position ? QString("%1(0%2)").arg(value.at(0), value.mid(1)) : QString("(0%1)").arg(value)); 25 | position += negative.matchedLength(); 26 | } 27 | 28 | position = 0; 29 | 30 | while ((position = expression.indexIn(string, position)) != -1) 31 | { 32 | QString value = expression.cap(); 33 | 34 | if (number.indexIn(value) != -1) 35 | items.append({Type::Number, value}); 36 | else 37 | items.append({itemType(value), value}); 38 | 39 | position += expression.matchedLength(); 40 | } 41 | 42 | for (int i = 0; i < items.count(); i++) 43 | { 44 | const Item &item = items.at(i); 45 | int priority; 46 | 47 | switch (item.type) 48 | { 49 | case Type::Empty: return; 50 | case Type::Number: m_items.append(item); continue; 51 | case Type::OpenBracket: offset += 10; continue; 52 | case Type::CloseBracket: offset -= 10; continue; 53 | default: break; 54 | } 55 | 56 | priority = itemPriority(item.type) + offset; 57 | 58 | if (!operationStack.isEmpty() && (priority < priorityStack.top() || (priority == priorityStack.top() && ((item.type != Type::Add && item.type != Type::Multiply) || item.value != operationStack.top().value)))) 59 | { 60 | for (int i = 0, count = operationStack.count(); i < count; i++) 61 | { 62 | if (priorityStack.top() < priority) 63 | break; 64 | 65 | m_items.append(operationStack.pop()); 66 | priorityStack.pop(); 67 | } 68 | } 69 | 70 | operationStack.push(item); 71 | priorityStack.push(priority); 72 | } 73 | 74 | for (int i = 0, count = operationStack.count(); i < count; i++) 75 | m_items.append(operationStack.pop()); 76 | 77 | if (m_items.count() == 1 && m_items.value(0).type == Type::Number) 78 | { 79 | m_result = m_items.value(0).value.toDouble(); 80 | return; 81 | } 82 | 83 | calculate(); 84 | } 85 | 86 | Expression::Type Expression::itemType(const QString &value) 87 | { 88 | if (value == "(") return Type::OpenBracket; 89 | if (value == ")") return Type::CloseBracket; 90 | if (value == ",") return Type::Comma; 91 | if (value == "+") return Type::Add; 92 | if (value == "-") return Type::Subtract; 93 | if (value == "*") return Type::Multiply; 94 | if (value == "/") return Type::Divide; 95 | if (value == "%") return Type::Remainder; 96 | if (value == "^") return Type::Pow; 97 | if (value == "round") return Type::Round; 98 | if (value == "ceil") return Type::Ceil; 99 | if (value == "floor") return Type::Floor; 100 | if (value == "sqrt") return Type::Sqrt; 101 | if (value == "exp") return Type::Exp; 102 | if (value == "min") return Type::Min; 103 | if (value == "max") return Type::Max; 104 | if (value == "random") return Type::Random; 105 | 106 | return Type::Empty; 107 | } 108 | 109 | int Expression::itemPriority(Type type) 110 | { 111 | switch (type) 112 | { 113 | case Type::Comma: return 1; 114 | case Type::Add: return 1; 115 | case Type::Subtract: return 1; 116 | case Type::Multiply: return 2; 117 | case Type::Divide: return 2; 118 | case Type::Remainder: return 2; 119 | case Type::Pow: return 3; 120 | default: return 4; 121 | } 122 | } 123 | 124 | void Expression::calculate(void) 125 | { 126 | QVector items; 127 | QVector index; 128 | QVector result; 129 | int count = 0, i = 0, a = 0, b = 0, c = 1; 130 | 131 | for (int i = 0; i < m_items.count(); i++) 132 | { 133 | const Item &item = m_items.at(i); 134 | 135 | if (item.type != Type::Number) 136 | index.append(i); 137 | 138 | switch (item.type) 139 | { 140 | case Type::Comma: 141 | case Type::Add: 142 | case Type::Subtract: 143 | case Type::Multiply: 144 | case Type::Divide: 145 | case Type::Remainder: 146 | case Type::Pow: 147 | count++; 148 | break; 149 | 150 | default: 151 | break; 152 | } 153 | 154 | items.append(item.type); 155 | result.append(item.type != Type::Number ? NAN : item.value.toDouble()); 156 | } 157 | 158 | if (index.isEmpty() || count != m_items.count() - index.count() - 1) 159 | return; 160 | 161 | while (i < index.count()) 162 | { 163 | if (items.at(c) != Type::Empty && items.at(c) != Type::Number) 164 | { 165 | switch (items.at(index.at(i++))) 166 | { 167 | case Type::Add: result.replace(a, result.at(a) + result.at(b)); items.replace(b, Type::Empty); break; 168 | case Type::Subtract: result.replace(a, result.at(a) - result.at(b)); items.replace(b, Type::Empty); break; 169 | case Type::Multiply: result.replace(a, result.at(a) * result.at(b)); items.replace(b, Type::Empty); break; 170 | case Type::Divide: result.replace(a, result.at(a) / result.at(b)); items.replace(b, Type::Empty); break; 171 | case Type::Remainder: result.replace(a, fmod(result.at(a), result.at(b))); items.replace(b, Type::Empty); break; 172 | case Type::Pow: result.replace(a, pow(result.at(a), result.at(b))); items.replace(b, Type::Empty); break; 173 | case Type::Round: result.replace(b, round(result.at(b))); break; 174 | case Type::Ceil: result.replace(b, ceil(result.at(b))); break; 175 | case Type::Floor: result.replace(b, floor(result.at(b))); break; 176 | case Type::Sqrt: result.replace(b, sqrt(result.at(b))); break; 177 | case Type::Exp: result.replace(b, exp(result.at(b))); break; 178 | case Type::Min: result.replace(a, qMin(result.at(a), result.at(b))); items.replace(b, Type::Empty); break; 179 | case Type::Max: result.replace(a, qMax(result.at(a), result.at(b))); items.replace(b, Type::Empty); break; 180 | 181 | case Type::Random: 182 | { 183 | quint32 x = static_cast (result.at(a)), y = static_cast (result.at(b)); 184 | result.replace(a, QRandomGenerator::global()->bounded(qMin(x, y), qMax(x, y))); 185 | items.replace(b, Type::Empty); 186 | break; 187 | } 188 | 189 | default: break; 190 | } 191 | 192 | items.replace(c, Type::Empty); 193 | } 194 | 195 | b = c++; 196 | 197 | while (items.at(b) == Type::Empty) 198 | b--; 199 | 200 | a = b > 0 ? b - 1 : 0; 201 | 202 | while (items.at(a) == Type::Empty) 203 | a--; 204 | } 205 | 206 | m_result = result.at(0); 207 | } 208 | 209 | QString Parser::formatValue(const QString &string) 210 | { 211 | QRegExp regexp("\\((.*)\\)"); 212 | 213 | if (regexp.indexIn(string) != -1) 214 | { 215 | QList actionList = {"fromHex", "toHex", "time"}; 216 | 217 | switch (actionList.indexOf(string.mid(0, string.indexOf(0x28)))) 218 | { 219 | case 0: // fromHex 220 | { 221 | QByteArray data = QByteArray::fromHex(regexp.cap(1).toUtf8()); 222 | QList list; 223 | 224 | for (int i = 0; i < data.length(); i++) 225 | list.append(QString::number(static_cast (data.at(i)))); 226 | 227 | return list.join(','); 228 | } 229 | 230 | case 1: // toHex 231 | { 232 | QList list = regexp.cap(1).split(','); 233 | QByteArray data; 234 | 235 | for (int i = 0; i < list.count(); i++) 236 | data.append(static_cast (list.at(i).toInt())); 237 | 238 | return QString(data.toHex()).toUpper(); 239 | } 240 | 241 | case 2: // time 242 | { 243 | bool check; 244 | QList list = regexp.cap(1).split('|'); 245 | qint64 value = list.value(1).toLongLong(&check); 246 | QDateTime dateTime = check ? QDateTime::fromSecsSinceEpoch(value) : QDateTime::currentDateTime(); 247 | return list.value(0).isEmpty() ? QString::number(dateTime.currentSecsSinceEpoch()) : dateTime.toString(list.value(0).trimmed()); 248 | } 249 | 250 | default: 251 | break; 252 | } 253 | } 254 | 255 | return string; 256 | } 257 | 258 | QVariant Parser::jsonValue(const QByteArray &data, const QString &path) 259 | { 260 | QJsonDocument document = QJsonDocument::fromJson(data); 261 | QList list = path.split('.'); 262 | QJsonValue value; 263 | 264 | for (int i = 0; i < list.count(); i++) 265 | { 266 | QString key = list.at(i); 267 | int index = -1; 268 | 269 | if (key.endsWith(']')) 270 | { 271 | int position = key.indexOf('['); 272 | index = key.mid(position + 1, key.length() - position - 2).toInt(); 273 | key = key.mid(0, position); 274 | } 275 | 276 | if (!key.isEmpty()) 277 | value = document.object().value(key); 278 | 279 | if (index >= 0) 280 | value = value.isArray() ? value.toArray().at(index) : document.array().at(index); 281 | 282 | if (i < list.count() - 1) 283 | document = value.isArray() ? QJsonDocument(value.toArray()) : QJsonDocument(value.toObject()); 284 | } 285 | 286 | return value.toVariant(); 287 | } 288 | 289 | 290 | QString Parser::urlValue(const QByteArray &string, const QString &key) 291 | { 292 | QList list = string.split('&'); 293 | 294 | for (int i = 0; i < list.count(); i++) 295 | { 296 | QList item = list.at(i).split('='); 297 | 298 | if (item.value(0) != key) 299 | continue; 300 | 301 | return QUrl::fromPercentEncoding(item.value(1)); 302 | } 303 | 304 | return QString(); 305 | } 306 | 307 | QString Parser::xmlValue(const QByteArray &string, const QString &key) 308 | { 309 | QXmlStreamReader reader(string); 310 | 311 | while (!reader.atEnd()) 312 | { 313 | reader.readNext(); 314 | 315 | if (!reader.isStartElement() || reader.name() != key) 316 | continue; 317 | 318 | return reader.readElementText(); 319 | } 320 | 321 | return QString(); 322 | } 323 | 324 | QVariant Parser::stringValue(const QString &string) 325 | { 326 | bool check; 327 | double value = string.toDouble(&check); 328 | 329 | if (check) 330 | return value; 331 | 332 | if (string == "true" || string == "false") 333 | return string == "true" ? true : false; 334 | 335 | return string.isEmpty() ? QVariant() : string; 336 | } 337 | -------------------------------------------------------------------------------- /expose.cpp: -------------------------------------------------------------------------------- 1 | #include "expose.h" 2 | 3 | void ExposeObject::registerMetaTypes(void) 4 | { 5 | qRegisterMetaType ("binaryExpose"); 6 | qRegisterMetaType ("sensorExpose"); 7 | qRegisterMetaType ("toggleExpose"); 8 | qRegisterMetaType ("numberExpose"); 9 | qRegisterMetaType ("selectExpose"); 10 | qRegisterMetaType ("buttonExpose"); 11 | qRegisterMetaType ("switchExpose"); 12 | qRegisterMetaType ("lightExpose"); 13 | qRegisterMetaType ("coverExpose"); 14 | qRegisterMetaType ("lockExpose"); 15 | qRegisterMetaType ("thermostatExpose"); 16 | } 17 | 18 | QJsonObject BinaryObject::request(void) 19 | { 20 | QList diagnostic = {"batteryLow", "tamper"}; 21 | QMap options = option().toMap(); 22 | QJsonObject json; 23 | 24 | if (diagnostic.contains(m_name) || options.value("diagnostic").toBool()) 25 | json.insert("entity_category", "diagnostic"); 26 | 27 | if (options.contains("class")) 28 | json.insert("device_class", options.value("class").toString()); 29 | 30 | if (options.contains("icon")) 31 | json.insert("icon", options.value("icon").toString()); 32 | 33 | json.insert("force_update", true); 34 | json.insert("value_template", QString("{{ value_json.%1 }}").arg(m_name)); 35 | json.insert("payload_on", true); 36 | json.insert("payload_off", false); 37 | json.insert("state_topic", m_stateTopic); 38 | 39 | return json; 40 | } 41 | 42 | QJsonObject SensorObject::request(void) 43 | { 44 | QList valueTemplate = {QString("value_json.%1").arg(m_name)}, forceUpdate = {"action", "event", "scene"}, diagnostic = {"battery", "messageCount", "linkQuality"}; 45 | QMap options = option().toMap(); 46 | QJsonObject json; 47 | 48 | for (int i = 0; i < forceUpdate.count(); i++) 49 | { 50 | if (!m_name.startsWith(forceUpdate.at(i))) 51 | continue; 52 | 53 | valueTemplate.append("is_defined"); 54 | json.insert("force_update", true); 55 | break; 56 | } 57 | 58 | if (options.contains("round")) 59 | valueTemplate.append(QString("round(%1)").arg(options.value("round").toInt())); 60 | 61 | if (diagnostic.contains(m_name) || options.value("diagnostic").toBool()) 62 | json.insert("entity_category", "diagnostic"); 63 | 64 | if (options.contains("class")) 65 | json.insert("device_class", options.value("class").toString()); 66 | 67 | if (options.contains("state")) 68 | json.insert("state_class", options.value("state").toString()); 69 | 70 | if (options.contains("unit")) 71 | json.insert("unit_of_measurement", options.value("unit").toString()); 72 | 73 | if (options.contains("icon")) 74 | json.insert("icon", options.value("icon").toString()); 75 | 76 | if (m_name == "linkQuality") 77 | json.insert("icon", "mdi:signal"); 78 | 79 | json.insert("value_template", QString("{{ %1 }}").arg(valueTemplate.join(" | "))); 80 | json.insert("state_topic", m_stateTopic); 81 | 82 | return json; 83 | } 84 | 85 | QJsonObject ToggleObject::request(void) 86 | { 87 | QMap options = option().toMap(); 88 | QJsonObject json; 89 | 90 | if (!options.value("control").toBool()) 91 | json.insert("entity_category", "config"); 92 | 93 | if (options.contains("icon")) 94 | json.insert("icon", options.value("icon").toString()); 95 | 96 | json.insert("value_template", QString("{{ value_json.%1 }}").arg(m_name)); 97 | json.insert("state_on", true); 98 | json.insert("state_off", false); 99 | json.insert("state_topic", m_stateTopic); 100 | 101 | json.insert("payload_on", QString("{\"%1\":true}").arg(m_name)); 102 | json.insert("payload_off", QString("{\"%1\":false}").arg(m_name)); 103 | json.insert("command_topic", m_commandTopic); 104 | 105 | return json; 106 | } 107 | 108 | QJsonObject NumberObject::request(void) 109 | { 110 | QMap options = option().toMap(); 111 | QJsonObject json; 112 | 113 | if (!options.value("control").toBool()) 114 | json.insert("entity_category", "config"); 115 | 116 | if (options.contains("min")) 117 | json.insert("min", options.value("min").toDouble()); 118 | 119 | if (options.contains("max")) 120 | json.insert("max", options.value("max").toDouble()); 121 | 122 | if (options.contains("step")) 123 | json.insert("step", options.value("step").toDouble()); 124 | 125 | if (options.contains("unit")) 126 | json.insert("unit_of_measurement", options.value("unit").toString()); 127 | 128 | if (options.contains("icon")) 129 | json.insert("icon", options.value("icon").toString()); 130 | 131 | json.insert("value_template", QString("{{ value_json.%1 }}").arg(m_name)); 132 | json.insert("state_topic", m_stateTopic); 133 | 134 | json.insert("command_template", QString("{\"%1\":{{ value }}}").arg(m_name)); 135 | json.insert("command_topic", m_commandTopic); 136 | 137 | return json; 138 | } 139 | 140 | QJsonObject SelectObject::request(void) 141 | { 142 | QMap options = option().toMap(); 143 | QVariant data = options.value("enum"); 144 | QJsonArray array; 145 | QJsonObject json; 146 | 147 | if (!options.value("control").toBool()) 148 | json.insert("entity_category", "config"); 149 | 150 | if (options.contains("icon")) 151 | json.insert("icon", options.value("icon").toString()); 152 | 153 | switch (data.type()) 154 | { 155 | case QVariant::Map: 156 | { 157 | QMap map = data.toMap(); 158 | 159 | for (auto it = map.begin(); it != map.end(); it++) 160 | array.append(it.value().toString()); 161 | 162 | break; 163 | } 164 | 165 | case QVariant::List: array = QJsonArray::fromStringList(data.toStringList()); break; 166 | default: break; 167 | } 168 | 169 | json.insert("options", array); 170 | 171 | json.insert("value_template", QString("{{ value_json.%1 }}").arg(m_name)); 172 | json.insert("state_topic", m_stateTopic); 173 | 174 | json.insert("command_template", QString("{\"%1\":\"{{ value }}\"}").arg(m_name)); 175 | json.insert("command_topic", m_commandTopic); 176 | 177 | return json; 178 | } 179 | 180 | QJsonObject ButtonObject::request(void) 181 | { 182 | QMap options = option().toMap(); 183 | QJsonObject json; 184 | 185 | if (!options.value("control").toBool()) 186 | json.insert("entity_category", "config"); 187 | 188 | if (options.contains("icon")) 189 | json.insert("icon", options.value("icon").toString()); 190 | 191 | json.insert("payload_press", QString("{\"%1\":true}").arg(m_name)); 192 | json.insert("command_topic", m_commandTopic); 193 | 194 | return json; 195 | } 196 | 197 | QJsonObject SwitchObject::request(void) 198 | { 199 | QString name = QString(m_name).replace("switch", "status"); 200 | QJsonObject json; 201 | 202 | json.insert("device_class", option().toString() == "outlet" ? "outlet" : "switch"); 203 | 204 | json.insert("value_template", QString("{{ value_json.%1 }}").arg(name)); 205 | json.insert("state_on", "on"); 206 | json.insert("state_off", "off"); 207 | json.insert("state_topic", m_stateTopic); 208 | 209 | json.insert("payload_on", QString("{\"%1\":\"on\"}").arg(name)); 210 | json.insert("payload_off", QString("{\"%1\":\"off\"}").arg(name)); 211 | json.insert("command_topic", m_commandTopic); 212 | 213 | return json; 214 | } 215 | 216 | QJsonObject LightObject::request(void) 217 | { 218 | QList list = m_name.split('_'), options = option().toStringList(); 219 | QJsonObject json; 220 | QString suffix; 221 | 222 | if (QRegExp("\\d+").exactMatch(list.value(1))) 223 | suffix = QString("_%1").arg(list.value(1)); 224 | 225 | if (options.contains("level")) 226 | { 227 | json.insert("brightness_value_template", QString("{{ value_json.level%1 }}").arg(suffix)); 228 | json.insert("brightness_state_topic", m_stateTopic); 229 | 230 | json.insert("brightness_command_template",QString("{\"level%1\":{{ value }}}").arg(suffix)); 231 | json.insert("brightness_command_topic", m_commandTopic); 232 | } 233 | 234 | if (options.contains("color")) 235 | { 236 | json.insert("rgb_value_template", QString("{{ value_json.color%1 | join(',') }}").arg(suffix)); 237 | json.insert("rgb_state_topic", m_stateTopic); 238 | 239 | json.insert("rgb_command_template",QString("{\"color%1\":[{{ red }},{{ green }},{{ blue }}]}").arg(suffix)); 240 | json.insert("rgb_command_topic", m_commandTopic); 241 | } 242 | 243 | if (options.contains("colorTemperature")) 244 | { 245 | QMap colorTemperature = option(QString("colorTemperature%1").arg(suffix)).toMap(); 246 | 247 | json.insert("color_temp_value_template", QString("{{ value_json.colorTemperature%1 }}").arg(suffix)); 248 | json.insert("color_temp_state_topic", m_stateTopic); 249 | 250 | json.insert("color_temp_command_template",QString("{\"colorTemperature%1\":{{ value }}}").arg(suffix)); 251 | json.insert("color_temp_command_topic", m_commandTopic); 252 | 253 | json.insert("min_mireds", colorTemperature.value("min", 153).toInt()); 254 | json.insert("max_mireds", colorTemperature.value("max", 500).toInt()); 255 | } 256 | 257 | if (options.contains("colorMode")) 258 | { 259 | json.insert("color_mode_value_template", QString("{{ 'rgb' if value_json.colorMode%1 else 'color_temp' }}").arg(suffix)); 260 | json.insert("color_mode_state_topic", m_stateTopic); 261 | } 262 | 263 | json.insert("state_value_template", QString("{{ '{\"status%1\":\"on\"}' if value_json.status%1 == 'on' else '{\"status%1\":\"off\"}' }}").arg(suffix)); 264 | json.insert("state_topic", m_stateTopic); 265 | 266 | json.insert("payload_on", QString("{\"status%1\":\"on\"}").arg(suffix)); 267 | json.insert("payload_off", QString("{\"status%1\":\"off\"}").arg(suffix)); 268 | json.insert("command_topic", m_commandTopic); 269 | 270 | return json; 271 | } 272 | 273 | QJsonObject CoverObject::request(void) 274 | { 275 | QList list = m_name.split('_'); 276 | QJsonObject json; 277 | QString suffix; 278 | 279 | if (QRegExp("\\d+").exactMatch(list.value(1))) 280 | suffix = QString("_%1").arg(list.value(1)); 281 | 282 | json.insert("device_class", option().toString() == "blind" ? "blind" : "curtain"); 283 | 284 | json.insert("value_template", QString("{{ value_json.cover%1 }}").arg(suffix)); 285 | json.insert("state_open", "open"); 286 | json.insert("state_closed", "closed"); 287 | json.insert("state_topic", m_stateTopic); 288 | 289 | json.insert("position_template", QString("{{ value_json.position%1 }}").arg(suffix)); 290 | json.insert("position_topic", m_stateTopic); 291 | 292 | json.insert("payload_open", QString("{\"cover%1\":\"open\"}").arg(suffix)); 293 | json.insert("payload_close", QString("{\"cover%1\":\"close\"}").arg(suffix)); 294 | json.insert("payload_stop", QString("{\"cover%1\":\"stop\"}").arg(suffix)); 295 | json.insert("command_topic", m_commandTopic); 296 | 297 | json.insert("set_position_template", QString("{\"position%1\":{{ position }}}").arg(suffix)); 298 | json.insert("set_position_topic", m_commandTopic); 299 | 300 | return json; 301 | } 302 | 303 | QJsonObject LockObject::request(void) 304 | { 305 | QString name = QString(m_name).replace("lock", "status"); 306 | QJsonObject json; 307 | 308 | if (option().toString() == "valve") 309 | json.insert("icon", "mdi:pipe-valve"); 310 | 311 | json.insert("value_template", QString("{{ value_json.%1 }}").arg(name)); 312 | json.insert("state_locked", "off"); 313 | json.insert("state_unlocked", "on"); 314 | json.insert("state_topic", m_stateTopic); 315 | 316 | json.insert("payload_lock", QString("{\"%1\":\"off\"}").arg(name)); 317 | json.insert("payload_unlock", QString("{\"%1\":\"on\"}").arg(name)); 318 | json.insert("command_topic", m_commandTopic); 319 | 320 | return json; 321 | } 322 | 323 | QJsonObject ThermostatObject::request(void) 324 | { 325 | QList operationMode = option("operationMode").toMap().value("enum").toStringList(), fanMode = option("fanMode").toMap().value("enum").toStringList(), systemMode = option("systemMode").toMap().value("enum").toStringList(); 326 | QMap targetTemperature = option("targetTemperature").toMap(); 327 | QJsonObject json; 328 | 329 | if (systemMode.contains("fan")) 330 | systemMode.replace(systemMode.indexOf("fan"), "fan_only"); 331 | 332 | if (systemMode.isEmpty()) 333 | systemMode.append("heat"); 334 | 335 | if (option("runningStatus").toBool()) 336 | { 337 | QList list = {"heat", "cool", "fan_only"}; 338 | QString actionTemplate; 339 | 340 | for (int i = 0; i < list.count(); i++) 341 | { 342 | if (!systemMode.contains(list.at(i))) 343 | continue; 344 | 345 | if (!actionTemplate.isEmpty() && i) 346 | actionTemplate.append(QString(" if value_json.systemMode == \"%1\" ").arg(list.at(i - 1))); 347 | 348 | actionTemplate.append(QString("else \"%1\"").arg(list.at(i) != "fan_only" ? QString(list.at(i)).append("ing") : "fan")); 349 | } 350 | 351 | json.insert("action_template", QString("{{ \"idle\" if value_json.running == false %1 }}").arg(actionTemplate)); 352 | json.insert("action_topic", m_stateTopic); 353 | } 354 | 355 | if (!fanMode.isEmpty()) 356 | { 357 | json.insert("fan_modes", QJsonArray::fromStringList(fanMode)); 358 | 359 | json.insert("fan_mode_state_template", "{{ value_json.fanMode }}"); 360 | json.insert("fan_mode_state_topic", m_stateTopic); 361 | 362 | json.insert("fan_mode_command_template", "{\"fanMode\":\"{{ value }}\"}"); 363 | json.insert("fan_mode_command_topic", m_commandTopic); 364 | } 365 | 366 | if (!operationMode.isEmpty()) 367 | { 368 | json.insert("preset_modes", QJsonArray::fromStringList(operationMode)); 369 | 370 | json.insert("preset_mode_value_template", "{{ value_json.operationMode }}"); 371 | json.insert("preset_mode_state_topic", m_stateTopic); 372 | 373 | json.insert("preset_mode_command_template", "{\"operationMode\":\"{{ value }}\"}"); 374 | json.insert("preset_mode_command_topic", m_commandTopic); 375 | } 376 | 377 | if (targetTemperature.contains("min")) 378 | json.insert("min_temp", targetTemperature.value("min").toDouble()); 379 | 380 | if (targetTemperature.contains("max")) 381 | json.insert("max_temp", targetTemperature.value("max").toDouble()); 382 | 383 | if (targetTemperature.contains("step")) 384 | json.insert("temp_step", targetTemperature.value("step").toDouble()); 385 | 386 | json.insert("modes", QJsonArray::fromStringList(systemMode)); 387 | 388 | json.insert("mode_state_template", "{{ \"fan_only\" if value_json.systemMode == \"fan\" else value_json.systemMode }}"); 389 | json.insert("mode_state_topic", m_stateTopic); 390 | 391 | json.insert("mode_command_template", "{\"systemMode\":\"{{ \"fan\" if value == \"fan_only\" else value }}\"}"); 392 | json.insert("mode_command_topic", m_commandTopic); 393 | 394 | json.insert("current_temperature_template", "{{ value_json.temperature }}"); 395 | json.insert("current_temperature_topic", m_stateTopic); 396 | 397 | json.insert("temperature_state_template", "{{ value_json.targetTemperature }}"); 398 | json.insert("temperature_state_topic", m_stateTopic); 399 | 400 | json.insert("temperature_command_template", "{\"targetTemperature\":{{ value }}}"); 401 | json.insert("temperature_command_topic", m_commandTopic); 402 | 403 | return json; 404 | } 405 | -------------------------------------------------------------------------------- /deploy/data/usr/share/homed-common/expose.json: -------------------------------------------------------------------------------- 1 | { 2 | "alarm": {"type": "binary", "icon": "mdi:bell"}, 3 | "batteryLow": {"type": "binary", "class": "battery"}, 4 | "carbonMonoxide": {"type": "binary", "icon": "mdi:molecule-co"}, 5 | "contact": {"type": "binary", "class": "door"}, 6 | "fault": {"type": "binary", "icon": "mdi:alert"}, 7 | "gas": {"type": "binary", "class": "gas"}, 8 | "motion": {"type": "binary", "class": "motion"}, 9 | "noise": {"type": "binary", "icon": "mdi:ear-hearing"}, 10 | "occupancy": {"type": "binary", "class": "occupancy"}, 11 | "smoke": {"type": "binary", "class": "smoke"}, 12 | "sos": {"type": "binary", "icon": "mdi:lifebuoy"}, 13 | "tamper": {"type": "binary", "class": "tamper"}, 14 | "vibration": {"type": "binary", "class": "vibration"}, 15 | "waterLeak": {"type": "binary", "class": "moisture"}, 16 | "windowOpen": {"type": "binary", "icon": "mdi:mdi:window-open-variant"}, 17 | 18 | "action": {"type": "sensor", "icon": "mdi:gesture-double-tap"}, 19 | "analogInput": {"type": "sensor", "icon": "mdi:speedometer"}, 20 | "battery": {"type": "sensor", "class": "battery", "unit": "%", "round": 1}, 21 | "batteryStatus": {"type": "sensor", "icon": "mdi:battery"}, 22 | "co2": {"type": "sensor", "class": "carbon_dioxide", "state": "measurement", "unit": "ppm"}, 23 | "concentration": {"type": "sensor", "unit": "ppm", "icon": "mdi:speedometer"}, 24 | "condition": {"type": "sensor", "icon": "mdi:cloud-outline"}, 25 | "count": {"type": "sensor", "icon": "mdi:counter"}, 26 | "current": {"type": "sensor", "class": "current", "state": "measurement", "unit": "A", "round": 3}, 27 | "dewPoint": {"type": "sensor", "unit": "°C", "icon": "mdi:thermometer-water"}, 28 | "dosePerHour": {"type": "sensor", "unit": "μR/h", "icon": "mdi:radioactive"}, 29 | "eco2": {"type": "sensor", "class": "carbon_dioxide", "state": "measurement", "unit": "ppm"}, 30 | "energy": {"type": "sensor", "class": "energy", "state": "total_increasing", "unit": "kWh", "round": 2}, 31 | "energyT1": {"type": "sensor", "class": "energy", "state": "total_increasing", "unit": "kWh", "round": 2}, 32 | "energyT2": {"type": "sensor", "class": "energy", "state": "total_increasing", "unit": "kWh", "round": 2}, 33 | "energyT3": {"type": "sensor", "class": "energy", "state": "total_increasing", "unit": "kWh", "round": 2}, 34 | "energyT4": {"type": "sensor", "class": "energy", "state": "total_increasing", "unit": "kWh", "round": 2}, 35 | "event": {"type": "sensor", "icon": "mdi:bell"}, 36 | "eventsPerMinute": {"type": "sensor", "icon": "mdi:radioactive"}, 37 | "fallStatus": {"type": "sensor", "icon": "mdi:alert"}, 38 | "feelsLike": {"type": "sensor", "unit": "°C", "icon": "mdi:thermometer"}, 39 | "flow": {"type": "sensor", "class": "volume_flow_rate", "state": "measurement", "unit": "m³/h"}, 40 | "formaldehyde": {"type": "sensor", "class": "volatile_organic_compounds", "state": "measurement", "unit": "µg/m³"}, 41 | "frequency": {"type": "sensor", "class": "frequency", "state": "measurement", "unit": "Hz", "round": 1}, 42 | "illuminance": {"type": "sensor", "class": "illuminance", "state": "measurement", "unit": "lx"}, 43 | "illumination": {"type": "sensor", "icon": "mdi:brightness-5"}, 44 | "humidity": {"type": "sensor", "class": "humidity", "state": "measurement", "unit": "%", "round": 1}, 45 | "humidityAlarm": {"type": "sensor", "icon": "mdi:bell"}, 46 | "moisture": {"type": "sensor", "class": "moisture", "state": "measurement", "unit": "%", "round": 1}, 47 | "motionSpeed": {"type": "sensor", "icon": "mdi:motion"}, 48 | "motionStatus": {"type": "sensor", "icon": "mdi:motion"}, 49 | "precipitation": {"type": "sensor", "unit": "mm", "icon": "mdi:weather-hail"}, 50 | "pm1": {"type": "sensor", "class": "pm1", "state": "measurement", "unit": "µg/m³", "round": 1, "icon": "mdi:molecule"}, 51 | "pm4": {"type": "sensor", "class": "pm4", "state": "measurement", "unit": "µg/m³", "round": 1, "icon": "mdi:molecule"}, 52 | "pm10": {"type": "sensor", "class": "pm10", "state": "measurement", "unit": "µg/m³", "round": 1, "icon": "mdi:molecule"}, 53 | "pm25": {"type": "sensor", "class": "pm25", "state": "measurement", "unit": "µg/m³", "round": 1, "icon": "mdi:molecule"}, 54 | "pmSize": {"type": "sensor", "unit": "µm", "round": 2, "icon": "mdi:molecule"}, 55 | "position": {"type": "sensor", "icon": "mdi:valve", "unit": "%"}, 56 | "power": {"type": "sensor", "class": "power", "state": "measurement", "unit": "W", "round": 2}, 57 | "presenceStatus": {"type": "sensor", "icon": "mdi:home"}, 58 | "pressure": {"type": "sensor", "class": "pressure", "state": "measurement", "unit": "kPa", "round": 1}, 59 | "producedEnergy": {"type": "sensor", "class": "energy", "state": "total_increasing", "unit": "kWh", "round": 2}, 60 | "scene": {"type": "sensor", "icon": "mdi:gesture-tap-button"}, 61 | "staticDwellAlarm": {"type": "sensor", "icon": "mdi:bell"}, 62 | "targetDistance": {"type": "sensor", "class": "distance", "unit": "m", "state": "measurement", "round": 1}, 63 | "temperature": {"type": "sensor", "class": "temperature", "state": "measurement", "unit": "°C", "round": 1}, 64 | "temperatureAlarm": {"type": "sensor", "icon": "mdi:bell"}, 65 | "test": {"type": "sensor", "icon": "mdi:eyedropper"}, 66 | "uvIndex": {"type": "sensor", "icon": "mdi:sun-wireless"}, 67 | "voc": {"type": "sensor", "class": "volatile_organic_compounds_parts", "state": "measurement", "unit": "ppb"}, 68 | "voltage": {"type": "sensor", "class": "voltage", "state": "measurement", "unit": "V", "round": 1}, 69 | "volume": {"type": "sensor", "class": "volume", "state": "total_increasing", "unit": "L"}, 70 | "windDirection": {"type": "sensor", "icon": "mdi:compass-outline"}, 71 | "windSpeed": {"type": "sensor", "unit": "m/s", "icon": "mdi:weather-windy"}, 72 | 73 | "autoBrightness": {"type": "toggle", "icon": "mdi:brightness-4"}, 74 | "backlight": {"type": "toggle", "icon": "mdi:brightness-4"}, 75 | "boost": {"type": "toggle", "control": true, "icon": "mdi:fire"}, 76 | "buzzerFeedback": {"type": "toggle", "icon": "mdi:music"}, 77 | "calibration": {"type": "toggle", "icon": "mdi:swap-horizontal-bold"}, 78 | "childLock": {"type": "toggle", "control": true, "icon": "mdi:lock"}, 79 | "co2AutoCalibration": {"type": "toggle", "icon": "mdi:molecule-co2"}, 80 | "co2LongChart": {"type": "toggle", "icon": "mdi:chart-box"}, 81 | "co2Relay": {"type": "toggle", "icon": "mdi:molecule-co2"}, 82 | "co2RelayInvert": {"type": "toggle", "icon": "mdi:molecule-co2"}, 83 | "ecoMode": {"type": "toggle", "control": true, "icon": "mdi:leaf"}, 84 | "enableDisplay": {"type": "toggle", "icon": "mdi:monitor"}, 85 | "frostProtection": {"type": "toggle", "control": true, "icon": "mdi:snowflake"}, 86 | "humidityRelay": {"type": "toggle", "icon": "mdi:water-percent"}, 87 | "humidityRelayInvert": {"type": "toggle", "icon": "mdi:water-percent"}, 88 | "indicator": {"type": "toggle", "icon": "mdi:led-on"}, 89 | "interlock": {"type": "toggle", "icon": "mdi:lock"}, 90 | "ledFeedback": {"type": "toggle", "icon": "mdi:led-on"}, 91 | "pm25Relay": {"type": "toggle", "icon": "mdi:molecule"}, 92 | "pm25RelayInvert": {"type": "toggle", "icon": "mdi:molecule"}, 93 | "pressureLongChart": {"type": "toggle", "icon": "mdi:chart-box"}, 94 | "reverse": {"type": "toggle", "icon": "mdi:swap-horizontal-bold"}, 95 | "showSmiley": {"type": "toggle", "icon": "mdi:emoticon"}, 96 | "statusMemory": {"type": "toggle", "icon": "mdi:memory"}, 97 | "strobe": {"type": "toggle", "icon": "mdi:alarm-light"}, 98 | "temperatureRelay": {"type": "toggle", "icon": "mdi:thermometer"}, 99 | "temperatureRelayInvert": {"type": "toggle", "icon": "mdi:thermometer"}, 100 | "touchControl": {"type": "toggle", "icon": "mdi:gesture-tap-button"}, 101 | "trigger": {"type": "toggle", "icon": "mdi:garage"}, 102 | "tumbleSwitch": {"type": "toggle", "icon": "mdi:dip-switch"}, 103 | "vocRelay": {"type": "toggle", "icon": "mdi:molecule"}, 104 | "vocRelayInvert": {"type": "toggle", "icon": "mdi:molecule"}, 105 | "windowDetection": {"type": "toggle", "icon": "mdi:mdi:window-open-variant"}, 106 | 107 | "altitude": {"type": "number", "unit": "m", "icon": "mdi:altimeter"}, 108 | "analogOutput": {"type": "number", "icon": "mdi:speedometer"}, 109 | "awayDays": {"type": "number", "icon": "mdi:calendar-week"}, 110 | "awayTemperature": {"type": "number", "unit": "°C", "icon": "mdi:thermometer"}, 111 | "boostTimeout": {"type": "number", "control": true, "unit": "sec", "icon": "mdi:timer"}, 112 | "co2High": {"type": "number", "unit": "ppm", "icon": "mdi:molecule-co2"}, 113 | "co2Low": {"type": "number", "unit": "ppm", "icon": "mdi:molecule-co2"}, 114 | "co2ManualCalibration": {"type": "number", "unit": "ppm", "icon": "mdi:molecule-co2"}, 115 | "coldPreset": {"type": "number", "unit": "L", "icon": "mdi:counter"}, 116 | "comfortTemperature": {"type": "number", "unit": "°C", "icon": "mdi:thermometer"}, 117 | "delay": {"type": "number", "unit": "sec", "icon": "mdi:timer"}, 118 | "detectionDelay": {"type": "number", "unit": "sec", "icon": "mdi:timer"}, 119 | "distanceMax": {"type": "number", "unit": "m", "icon": "mdi:arrow-left-right"}, 120 | "distanceMin": {"type": "number", "unit": "m", "icon": "mdi:arrow-left-right"}, 121 | "duration": {"type": "number", "unit": "sec", "icon": "mdi:timer"}, 122 | "dutyCycle": {"type": "number", "icon": "mdi:alarm-light"}, 123 | "ecoTemperature": {"type": "number", "unit": "°C", "icon": "mdi:thermometer"}, 124 | "externalTemperature": {"type": "number", "unit": "°C", "icon": "mdi:thermometer"}, 125 | "fadingTime": {"type": "number", "unit": "sec", "icon": "mdi:timer"}, 126 | "fallSensitivity": {"type": "number", "icon": "mdi:dumbbell"}, 127 | "hotPreset": {"type": "number", "unit": "L", "icon": "mdi:counter"}, 128 | "humidityHigh": {"type": "number", "unit": "%", "icon": "mdi:water-percent"}, 129 | "humidityLow": {"type": "number", "unit": "%", "icon": "mdi:water-percent"}, 130 | "humidityOffset": {"type": "number", "unit": "%", "icon": "mdi:water-percent"}, 131 | "hysteresis": {"type": "number", "unit": "°C", "icon": "mdi:thermometer"}, 132 | "illuminanceDelay": {"type": "number", "unit": "min", "icon": "mdi:timer"}, 133 | "indicatorLevel": {"type": "number", "icon": "mdi:led-on"}, 134 | "lowerLimit": {"type": "number", "unit": "%", "icon": "mdi:arrow-collapse-down"}, 135 | "melody": {"type": "number", "icon": "mdi:music-note"}, 136 | "moistureLow": {"type": "number", "unit": "%", "icon": "mdi:water-percent"}, 137 | "moistureHigh": {"type": "number", "unit": "%", "icon": "mdi:water-percent"}, 138 | "motionSensitivity": {"type": "number", "icon": "mdi:dumbbell"}, 139 | "occupancyTimeout": {"type": "number", "unit": "sec", "icon": "mdi:timer"}, 140 | "pattern": {"type": "number", "control": true, "icon": "mdi:swap-horizontal-bold"}, 141 | "pm25High": {"type": "number", "unit": "µg/m³", "icon": "mdi:molecule"}, 142 | "pm25Low": {"type": "number", "unit": "µg/m³", "icon": "mdi:molecule"}, 143 | "pressureOffset": {"type": "number", "unit": "kPa", "icon": "mdi:gauge"}, 144 | "pulseVolume": {"type": "number", "unit": "L", "icon": "mdi:counter"}, 145 | "readInterval": {"type": "number", "unit": "sec", "icon": "mdi:timer"}, 146 | "reportingDelay": {"type": "number", "unit": "sec", "icon": "mdi:timer"}, 147 | "sensitivity": {"type": "number", "icon": "mdi:dumbbell"}, 148 | "sensorCount": {"type": "number", "icon": "mdi:dip-switch"}, 149 | "speed": {"type": "number", "icon": "mdi:speedometer"}, 150 | "temperatureHigh": {"type": "number", "unit": "°C", "icon": "mdi:thermometer"}, 151 | "temperatureLow": {"type": "number", "unit": "°C", "icon": "mdi:thermometer"}, 152 | "temperatureOffset": {"type": "number", "unit": "°C", "icon": "mdi:thermometer"}, 153 | "threshold": {"type": "number", "unit": "μR/h", "icon": "mdi:radioactive"}, 154 | "timer": {"type": "number", "control": true, "unit": "min", "icon": "mdi:timer"}, 155 | "transmitPower": {"type": "number", "unit": "dBm", "icon": "mdi:antenna"}, 156 | "tumbleAlarmTime": {"type": "number", "unit": "min", "icon": "mdi:timer"}, 157 | "upperLimit": {"type": "number", "unit": "%", "icon": "mdi:arrow-collapse-up"}, 158 | "vocHigh": {"type": "number", "unit": "ppb", "icon": "mdi:molecule"}, 159 | "vocLow": {"type": "number", "unit": "ppb", "icon": "mdi:molecule"}, 160 | 161 | "buttonMode": {"type": "select", "enum": ["relay", "decoupled"]}, 162 | "detectionMode": {"type": "select", "enum": ["undirected", "directed"]}, 163 | "displayMode": {"type": "select", "enum": ["celsius", "fahrenheit"]}, 164 | "distanceMode": {"type": "select", "enum": ["far", "middle", "near"], "icon": "mdi:arrow-left-right"}, 165 | "fanMode": {"type": "select", "enum": ["off", "low", "medium", "high"], "icon": "mdi:fan"}, 166 | "indicatorMode": {"type": "select", "enum": ["off", "default", "inverted", "on"], "icon": "mdi:lightbulb-on"}, 167 | "leftMode": {"type": "select", "enum": ["leftRelay", "rightRelay", "decoupled"]}, 168 | "lightType": {"type": "select", "enum": ["led", "incandescent", "halogen"], "icon": "mdi:lightbulb-on"}, 169 | "operationMode": {"type": "select", "enum": ["command", "event"]}, 170 | "powerMode": {"type": "select", "enum": ["high", "medium", "low"]}, 171 | "powerOnStatus": {"type": "select", "enum": {"0": "off", "1": "on", "2": "toggle", "255": "previous"}}, 172 | "radarScene": {"type": "select", "enum": ["default", "bathroom", "bedroom", "sleeping"]}, 173 | "rightMode": {"type": "select", "enum": ["leftRelay", "rightRelay", "decoupled"]}, 174 | "sensitivityMode": {"type": "select", "enum": ["low", "medium", "high"], "icon": "mdi:dumbbell"}, 175 | "sensorType": {"type": "select", "enum": ["internal", "both", "external"]}, 176 | "setLowerLimit": {"type": "select", "enum": ["clear", "set"], "icon": "mdi:arrow-collapse-down"}, 177 | "setUpperLimit": {"type": "select", "enum": ["clear", "set"], "icon": "mdi:arrow-collapse-up"}, 178 | "sirenLevel": {"type": "select", "enum": ["low", "medium", "high", "max"], "icon": "mdi:volume-high"}, 179 | "sirenMode": {"type": "select", "enum": ["stop", "burglar", "fire", "emergency", "policePanic", "firePanic", "emergencyPanic"], "icon": "mdi:volume-high"}, 180 | "strobeLevel": {"type": "select", "enum": ["low", "medium", "high", "max"], "icon": "mdi:alarm-light"}, 181 | "switchMode": {"type": "select", "enum": ["on", "off", "toggle"]}, 182 | "switchType": {"type": "select", "enum": ["toggle", "momentary", "multifunction"]}, 183 | "timeoutMode": {"type": "select", "enum": ["10s", "30s", "60s", "120s"], "icon": "mdi:timer"}, 184 | "volumeMode": {"type": "select", "enum": ["low", "medium", "high"], "icon": "mdi:volume-high"}, 185 | "weekMode": {"type": "select", "enum": ["5+2", "6+1", "7+0"], "icon": "mdi:calendar-week"}, 186 | 187 | "co2FactoryReset": {"type": "button"}, 188 | "co2ForceCalibration": {"type": "button"}, 189 | "resetLimits": {"type": "button"}, 190 | "resetPresence": {"type": "button"} 191 | } 192 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | homed-common 635 | Copyright (C) 2022 HOMEd / Services 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 2022 HOMEd / Services 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------