mirror of
https://github.com/mrcory/arduino-home-assistant.git
synced 2026-08-02 15:24:26 -04:00
codebase cleanup
This commit is contained in:
+1
-11
@@ -1,14 +1,4 @@
|
||||
// Turns on debug information of the ArduinoHA core.
|
||||
// Please note that you need to initialize serial interface manually
|
||||
// by calling Serial.begin([baudRate]) before initializing ArduinoHA.
|
||||
#define ARDUINOHA_DEBUG
|
||||
|
||||
// You can easily reduce amount of required resources by removing unused components from the library.
|
||||
// Here is the list of available defines:
|
||||
|
||||
// #define NO_HA_BINARY_SENSOR
|
||||
// #define NO_HA_TRIGGERS
|
||||
// #define NO_HA_TAG_SCANNER
|
||||
// #define NO_HA_SWITCH
|
||||
|
||||
// In order to get them working just put proper #define before including the ArduinoHA.h header
|
||||
// #define ARDUINOHA_DEBUG
|
||||
|
||||
+18
-18
@@ -48,54 +48,54 @@ uint16_t HADevice::calculateSerializedLength() const
|
||||
return size;
|
||||
}
|
||||
|
||||
uint16_t HADevice::serialize(char* output) const
|
||||
uint16_t HADevice::serialize(char* dst) const
|
||||
{
|
||||
static const char QuotationSign[] PROGMEM = {"\""};
|
||||
|
||||
{
|
||||
static const char DataBefore[] PROGMEM = {"{\"ids\":\""};
|
||||
|
||||
strcpy_P(output, DataBefore);
|
||||
strcat(output, _uniqueId);
|
||||
strcat_P(output, QuotationSign);
|
||||
strcpy_P(dst, DataBefore);
|
||||
strcat(dst, _uniqueId);
|
||||
strcat_P(dst, QuotationSign);
|
||||
}
|
||||
|
||||
if (_manufacturer != nullptr) {
|
||||
static const char DataBefore[] PROGMEM = {",\"mf\":\""};
|
||||
|
||||
strcat_P(output, DataBefore);
|
||||
strcat(output, _manufacturer);
|
||||
strcat_P(output, QuotationSign);
|
||||
strcat_P(dst, DataBefore);
|
||||
strcat(dst, _manufacturer);
|
||||
strcat_P(dst, QuotationSign);
|
||||
}
|
||||
|
||||
if (_model != nullptr) {
|
||||
static const char DataBefore[] PROGMEM = {",\"mdl\":\""};
|
||||
|
||||
strcat_P(output, DataBefore);
|
||||
strcat(output, _model);
|
||||
strcat_P(output, QuotationSign);
|
||||
strcat_P(dst, DataBefore);
|
||||
strcat(dst, _model);
|
||||
strcat_P(dst, QuotationSign);
|
||||
}
|
||||
|
||||
if (_name != nullptr) {
|
||||
static const char DataBefore[] PROGMEM = {",\"name\":\""};
|
||||
|
||||
strcat_P(output, DataBefore);
|
||||
strcat(output, _name);
|
||||
strcat_P(output, QuotationSign);
|
||||
strcat_P(dst, DataBefore);
|
||||
strcat(dst, _name);
|
||||
strcat_P(dst, QuotationSign);
|
||||
}
|
||||
|
||||
if (_softwareVersion != nullptr) {
|
||||
static const char DataBefore[] PROGMEM = {",\"sw\":\""};
|
||||
|
||||
strcat_P(output, DataBefore);
|
||||
strcat(output, _softwareVersion);
|
||||
strcat_P(output, QuotationSign);
|
||||
strcat_P(dst, DataBefore);
|
||||
strcat(dst, _softwareVersion);
|
||||
strcat_P(dst, QuotationSign);
|
||||
}
|
||||
|
||||
{
|
||||
static const char Data[] PROGMEM = {"}"};
|
||||
strcat_P(output, Data);
|
||||
strcat_P(dst, Data);
|
||||
}
|
||||
|
||||
return strlen(output) + 1; // size with null terminator
|
||||
return strlen(dst) + 1; // size with null terminator
|
||||
}
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ public:
|
||||
{ _softwareVersion = softwareVersion; }
|
||||
|
||||
uint16_t calculateSerializedLength() const;
|
||||
uint16_t serialize(char* output) const;
|
||||
uint16_t serialize(char* dst) const;
|
||||
|
||||
private:
|
||||
const char* _uniqueId;
|
||||
|
||||
+1
-1
@@ -101,7 +101,7 @@ bool HAMqtt::isConnected()
|
||||
|
||||
void HAMqtt::addDeviceType(BaseDeviceType* deviceType)
|
||||
{
|
||||
BaseDeviceType** data = realloc(
|
||||
BaseDeviceType** data = (BaseDeviceType**)realloc(
|
||||
_devicesTypes,
|
||||
sizeof(BaseDeviceType*) * (_devicesTypesNb + 1)
|
||||
);
|
||||
|
||||
+6
-3
@@ -25,11 +25,11 @@ void HAUtils::byteArrayToStr(
|
||||
)
|
||||
{
|
||||
const uint16_t& finalLength = (length * 2);
|
||||
const char* map = "0123456789abcdef"; // todo: move to progmem
|
||||
static const char map[] PROGMEM = {"0123456789abcdef"};
|
||||
|
||||
for (uint8_t i = 0; i < length; i++) {
|
||||
dst[i*2] = map[((char)src[i] & 0XF0) >> 4];
|
||||
dst[i*2+1] = map[((char)src[i] & 0x0F)];
|
||||
dst[i*2] = pgm_read_byte(&map[((char)src[i] & 0XF0) >> 4]);
|
||||
dst[i*2+1] = pgm_read_byte(&map[((char)src[i] & 0x0F)]);
|
||||
}
|
||||
|
||||
dst[finalLength] = '\0';
|
||||
@@ -72,5 +72,8 @@ uint8_t HAUtils::getValueTypeLength(const ValueType& type)
|
||||
|
||||
case ValueTypeFloat:
|
||||
return sizeof(float);
|
||||
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#ifndef NO_HA_BINARY_SENSOR
|
||||
|
||||
#include "HABinarySensor.h"
|
||||
#include "../ArduinoHADefines.h"
|
||||
#include "../HAMqtt.h"
|
||||
@@ -266,5 +264,3 @@ bool HABinarySensor::writeSerializedTrigger(const char* serializedDevice) const
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#ifndef HABINARYSENSOR_H
|
||||
#ifndef NO_HA_BINARY_SENSOR
|
||||
#define HABINARYSENSOR_H
|
||||
|
||||
#include "BaseDeviceType.h"
|
||||
@@ -72,4 +71,3 @@ private:
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -320,7 +320,7 @@ bool HASensor<T>::valueToStr(char* dst, T value) const
|
||||
if (_valueType == HAUtils::ValueTypeUnknown) {
|
||||
return false;
|
||||
}
|
||||
Serial.println(value);
|
||||
|
||||
switch (_valueType) {
|
||||
case HAUtils::ValueTypeUint8:
|
||||
case HAUtils::ValueTypeUint16:
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#ifndef HASENSOR_H
|
||||
#ifndef NO_HA_SENSOR
|
||||
#define HASENSOR_H
|
||||
|
||||
#include "BaseDeviceType.h"
|
||||
@@ -77,4 +76,3 @@ private:
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#ifndef NO_HA_SWITCH
|
||||
|
||||
#include "HASwitch.h"
|
||||
#include "../ArduinoHADefines.h"
|
||||
#include "../HAMqtt.h"
|
||||
@@ -337,5 +335,3 @@ bool HASwitch::writeSerializedTrigger(const char* serializedDevice) const
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#ifndef HASWITCH_H
|
||||
#ifndef NO_HA_SWITCH
|
||||
#define HASWITCH_H
|
||||
|
||||
#include "BaseDeviceType.h"
|
||||
@@ -95,4 +94,3 @@ private:
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#ifndef NO_HA_TAG_SCANNER
|
||||
|
||||
#include "HATagScanner.h"
|
||||
#include "../ArduinoHADefines.h"
|
||||
#include "../HAMqtt.h"
|
||||
@@ -165,5 +163,3 @@ bool HATagScanner::writeSerializedTrigger(const char* serializedDevice) const
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#ifndef HATAGSCANNER_H
|
||||
#ifndef NO_HA_TAG_SCANNER
|
||||
#define HATAGSCANNER_H
|
||||
|
||||
#include "BaseDeviceType.h"
|
||||
@@ -37,4 +36,3 @@ private:
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#ifndef NO_HA_TRIGGERS
|
||||
|
||||
#include "HATriggers.h"
|
||||
#include "../ArduinoHADefines.h"
|
||||
#include "../HAMqtt.h"
|
||||
@@ -285,5 +283,3 @@ bool HATriggers::writeSerializedTrigger(
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#ifndef HATRIGGERS_H
|
||||
#ifndef NO_HA_TRIGGERS
|
||||
#define HATRIGGERS_H
|
||||
|
||||
#include "BaseDeviceType.h"
|
||||
@@ -53,4 +52,3 @@ private:
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user