Skip to content

Commit

Permalink
[MQTT] Move TaskValue VType Discovery to each plugin where needed. So…
Browse files Browse the repository at this point in the history
…me other code improvements
  • Loading branch information
tonhuisman committed Jan 12, 2025
1 parent 5240af6 commit 3666157
Show file tree
Hide file tree
Showing 120 changed files with 2,007 additions and 881 deletions.
15 changes: 15 additions & 0 deletions src/_P002_ADC.ino
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
// #################################### Plugin 002: Analog ###############################################
// #######################################################################################################

/** Changelog:
* 2025-01-12 tonhuisman: Add support for MQTT AutoDiscovery
*/

# define PLUGIN_002
# define PLUGIN_ID_002 2
# define PLUGIN_NAME_002 "Analog input - internal"
Expand Down Expand Up @@ -48,6 +52,17 @@ boolean Plugin_002(uint8_t function, struct EventStruct *event, String& string)
break;
}

# if FEATURE_MQTT_DISCOVER
case PLUGIN_GET_DISCOVERY_VTYPES:
{
for (uint8_t i = 0; i < event->Par5; ++i) {
event->ParN[i] = static_cast<int>(Sensor_VType::SENSOR_TYPE_ANALOG_ONLY);
}
success = true;
break;
}
# endif // if FEATURE_MQTT_DISCOVER

case PLUGIN_WEBFORM_LOAD:
{
P002_data_struct *P002_data =
Expand Down
10 changes: 10 additions & 0 deletions src/_P003_Pulse.ino
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// tolerate less good signals. After a pulse and debounce time it verifies the signal 3 times.

/** Changelog:
* 2025-01-12 tonhuisman: Add support for MQTT AutoDiscovery (not supported yet for Pulse Counters)
* 2024-08-12 tonhuisman: Improved handling of 'Ignore multiple Delta = 0' by peeking the Delta value.
* 2024-08-10 tonhuisman: Changed option to 'Ignore multiple Delta = 0', and allow Interval = 0, combined with Delta = 0, to send a pulse
* immediately to the Controllers and generate events.
Expand Down Expand Up @@ -144,6 +145,15 @@ boolean Plugin_003(uint8_t function, struct EventStruct *event, String& string)
break;
}

# if FEATURE_MQTT_DISCOVER
case PLUGIN_GET_DISCOVERY_VTYPES:
{
event->Par1 = static_cast<int>(Sensor_VType::SENSOR_TYPE_NONE); // Not yet supported
success = true;
break;
}
# endif // if FEATURE_MQTT_DISCOVER

case PLUGIN_WEBFORM_LOAD:
{
addFormNumericBox(F("Debounce Time"), F("debounce")
Expand Down
12 changes: 12 additions & 0 deletions src/_P004_Dallas.ino
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// Maxim Integrated (ex Dallas) DS18B20 datasheet : https://datasheets.maximintegrated.com/en/ds/DS18B20.pdf

/** Changelog:
* 2025-01-12 tonhuisman: Add support for MQTT AutoDiscovery
* 2024-05-11 tonhuisman: Add Get Config Value support for sensor statistics: Read success, Read retry, Read failed,
* Read init failed, Resolution and Address (formatted)
* [<taskname>#sensorstats,<sensorindex>,success|retry|failed|initfailed|resolution|address]
Expand Down Expand Up @@ -92,6 +93,17 @@ boolean Plugin_004(uint8_t function, struct EventStruct *event, String& string)
break;
}

# if FEATURE_MQTT_DISCOVER
case PLUGIN_GET_DISCOVERY_VTYPES:
{
for (uint8_t i = 0; i < event->Par5; ++i) {
event->ParN[i] = static_cast<int>(Sensor_VType::SENSOR_TYPE_TEMP_ONLY);
}
success = true;
break;
}
# endif // if FEATURE_MQTT_DISCOVER

case PLUGIN_SET_DEFAULTS:
{
PCONFIG(P004_SENSOR_TYPE_INDEX) = static_cast<uint8_t>(Sensor_VType::SENSOR_TYPE_SINGLE);
Expand Down
12 changes: 12 additions & 0 deletions src/_P007_PCF8591.ino
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// #######################################################################################################

/** Changelog:
* 2025-01-12 tonhuisman: Add support for MQTT AutoDiscovery
* 2023-11-24 tonhuisman: Add Device flag for I2CMax100kHz as this sensor won't work at 400 kHz
* 2022-05-08 tonhuisman: Use ESPEasy core I2C functions where possible
* Add support for use of the Analog output pin and 'analogout,<value>' command
Expand Down Expand Up @@ -79,6 +80,17 @@ boolean Plugin_007(uint8_t function, struct EventStruct *event, String& string)
break;
}

# if FEATURE_MQTT_DISCOVER
case PLUGIN_GET_DISCOVERY_VTYPES:
{
for (uint8_t i = 0; i < event->Par5; ++i) {
event->ParN[i] = static_cast<int>(Sensor_VType::SENSOR_TYPE_ANALOG_ONLY);
}
success = true;
break;
}
# endif // if FEATURE_MQTT_DISCOVER

case PLUGIN_SET_DEFAULTS:
{
PCONFIG(P007_SENSOR_TYPE_INDEX) = static_cast<uint8_t>(Sensor_VType::SENSOR_TYPE_SINGLE);
Expand Down
10 changes: 10 additions & 0 deletions src/_P008_RFID.ino
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

/*
History:
2025-01-12 tonhuisman: Add support for MQTT AutoDiscovery (not supported yet for RFID)
2023-01-22 tonhuisman: Disable some strings in BUILD_NO_DEBUG builds to reduce size, minor optimizations
2022-12-04 tonhuisman: Fix initialization issue (hanginging ESP...) when GPIO pins are not configured correctly
2022-12-03 tonhuisman: Add Get Config values for tag value and bits received
Expand Down Expand Up @@ -75,6 +76,15 @@ boolean Plugin_008(uint8_t function, struct EventStruct *event, String& string)
break;
}

# if FEATURE_MQTT_DISCOVER
case PLUGIN_GET_DISCOVERY_VTYPES:
{
event->Par1 = static_cast<int>(Sensor_VType::SENSOR_TYPE_NONE); // Not yet supported
success = true;
break;
}
# endif // if FEATURE_MQTT_DISCOVER

case PLUGIN_SET_DEFAULTS:
{
P008_DATA_BITS = 26; // Minimal nr. of bits
Expand Down
14 changes: 14 additions & 0 deletions src/_P010_BH1750.ino
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
// #################################### Plugin-010: LuxRead ############################################
// #######################################################################################################

/** Changelog:
* 2025-01-12 tonhuisman: Add support for MQTT AutoDiscovery
*/

# include <AS_BH1750.h>

Expand Down Expand Up @@ -47,6 +50,17 @@ boolean Plugin_010(uint8_t function, struct EventStruct *event, String& string)
break;
}

# if FEATURE_MQTT_DISCOVER
case PLUGIN_GET_DISCOVERY_VTYPES:
{
for (uint8_t i = 0; i < event->Par5; ++i) {
event->ParN[i] = static_cast<int>(Sensor_VType::SENSOR_TYPE_LUX_ONLY);
}
success = true;
break;
}
# endif // if FEATURE_MQTT_DISCOVER

case PLUGIN_I2C_HAS_ADDRESS:
case PLUGIN_WEBFORM_SHOW_I2C_PARAMS:
{
Expand Down
10 changes: 10 additions & 0 deletions src/_P011_PME.ino
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// #######################################################################################################

/** Changelog:
* 2025-01-12 tonhuisman: Add support for MQTT AutoDiscovery (not supported for PME)
* 2024-04-14 tonhuisman: Add support for Get Config Values, to obtain a port state/value without instantiating a task for each pin.
* Only a single, enabled, task is required to handle the Get Config Values.
* Variables: [<TaskName>#D<port>] and [<TaskName>#A,<port>]
Expand Down Expand Up @@ -64,6 +65,15 @@ boolean Plugin_011(uint8_t function, struct EventStruct *event, String& string)
break;
}

# if FEATURE_MQTT_DISCOVER
case PLUGIN_GET_DISCOVERY_VTYPES:
{
event->Par1 = static_cast<int>(Sensor_VType::SENSOR_TYPE_NONE); // Not yet supported
success = true;
break;
}
# endif // if FEATURE_MQTT_DISCOVER

case PLUGIN_I2C_HAS_ADDRESS:
{
success = (event->Par1 == PLUGIN_011_I2C_ADDRESS);
Expand Down
11 changes: 11 additions & 0 deletions src/_P013_HCSR04.ino
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// #######################################################################################################

/** Changelog:
* 2025-01-12 tonhuisman: Add support for MQTT AutoDiscovery
* 2023-02-25 tonhuisman: Make Interval optional, and also disable the added feature P013_FEATURE_INTERVALEVENT, as setting Interval
* to 0 is effectively the same. (Small code reduction)
* Changed second value label for Combined mode to State
Expand Down Expand Up @@ -101,6 +102,16 @@ boolean Plugin_013(uint8_t function, struct EventStruct *even
}
# endif // if P013_FEATURE_COMBINED_MODE

# if FEATURE_MQTT_DISCOVER
case PLUGIN_GET_DISCOVERY_VTYPES:
{
event->Par1 = static_cast<int>(Sensor_VType::SENSOR_TYPE_DISTANCE_ONLY);
event->Par2 = static_cast<int>(Sensor_VType::SENSOR_TYPE_SWITCH);
success = true;
break;
}
# endif // if FEATURE_MQTT_DISCOVER

case PLUGIN_SET_DEFAULTS:
{
P013_FILTER_SIZE = P013_DEFAULT_FILTER_SIZE;
Expand Down
23 changes: 19 additions & 4 deletions src/_P014_SI70xx.ino
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
// #######################################################################################################
// ######################## Plugin 014 SI70xx I2C Temperature Humidity Sensor ###########################
// #######################################################################################################
// 2015-10-12 Charles-Henri Hallard, see my projects and blog at https://hallard.me
// 2022-07-22 MFD, Adding support for SI7013 with ADC and lots of refactoring
// 2023-07-11 tonhuisman, Add missing PLUGIN_SET_DEFAULTS handling, to set default Temperature/Humidity output values
// Use internationally usable dates for changelog

/** Changelog:
* 2025-01-12 tonhuisman: Add support for MQTT AutoDiscovery
* Update changelog
* 2023-07-11 tonhuisman, Add missing PLUGIN_SET_DEFAULTS handling, to set default Temperature/Humidity output values
* Use internationally usable dates for changelog
* 2022-07-22 MFD, Adding support for SI7013 with ADC and lots of refactoring
* 2015-10-12 Charles-Henri Hallard, see my projects and blog at https://hallard.me
*/


/*
Expand Down Expand Up @@ -72,6 +77,16 @@ boolean Plugin_014(uint8_t function, struct EventStruct *event, String& string)
break;
}

# if FEATURE_MQTT_DISCOVER
case PLUGIN_GET_DISCOVERY_VTYPES:
{
event->Par1 = static_cast<int>(Sensor_VType::SENSOR_TYPE_TEMP_HUM);
event->Par2 = static_cast<int>(Sensor_VType::SENSOR_TYPE_ANALOG_ONLY);
success = true;
break;
}
# endif // if FEATURE_MQTT_DISCOVER

case PLUGIN_SET_DEFAULTS:
{
P014_VALUES_COUNT = getValueCountFromSensorType(Sensor_VType::SENSOR_TYPE_TEMP_HUM);
Expand Down
14 changes: 14 additions & 0 deletions src/_P015_TSL2561.ino
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
// this plugin is based on the sparkfun library
// written based on version 1.1.0 from https://github.com/sparkfun/SparkFun_TSL2561_Arduino_Library

/** Changelog:
* 2025-01-12 tonhuisman: Add support for MQTT AutoDiscovery (not supported yet for Pulse Counters)
*/

# include "src/PluginStructs/P015_data_struct.h"

Expand Down Expand Up @@ -63,6 +66,17 @@ boolean Plugin_015(uint8_t function, struct EventStruct *event, String& string)
break;
}

# if FEATURE_MQTT_DISCOVER
case PLUGIN_GET_DISCOVERY_VTYPES:
{
event->Par1 = static_cast<int>(Sensor_VType::SENSOR_TYPE_LUX_ONLY);
event->Par2 = static_cast<int>(Sensor_VType::SENSOR_TYPE_IR_ONLY);
event->Par3 = static_cast<int>(Sensor_VType::SENSOR_TYPE_LUX_ONLY);
success = true;
break;
}
# endif // if FEATURE_MQTT_DISCOVER

case PLUGIN_I2C_HAS_ADDRESS:
case PLUGIN_WEBFORM_SHOW_I2C_PARAMS:
{
Expand Down
11 changes: 11 additions & 0 deletions src/_P016_IR.ino
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@
# endif // ifndef P016_SEND_IR_TO_CONTROLLER

// History
// @tonhuisman: 2025-01-12
// ADD: support for MQTT AutoDiscovery (not supported for IR receive)
// @uwekaditz: 2024-01-23
// CHG: Use the new property addToQueue in ExecuteCommand_all() due to the lack of resources
// NEW: Heap and memory can be reported (P016_CHECK_HEAP)
Expand Down Expand Up @@ -228,6 +230,15 @@ boolean Plugin_016(uint8_t function, struct EventStruct *event, String& string)
break;
}

# if FEATURE_MQTT_DISCOVER
case PLUGIN_GET_DISCOVERY_VTYPES:
{
event->Par1 = static_cast<int>(Sensor_VType::SENSOR_TYPE_NONE); // Not yet supported
success = true;
break;
}
# endif // if FEATURE_MQTT_DISCOVER

case PLUGIN_GET_DEVICEGPIONAMES:
{
event->String1 = formatGpioName_input(F("IR"));
Expand Down
12 changes: 12 additions & 0 deletions src/_P017_PN532.ino
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
// #################################### Plugin-017: PN532 RFID reader ####################################
// #######################################################################################################

/** Changelog:
* 2025-01-12 tonhuisman: Add support for MQTT AutoDiscovery (not supported for RFID)
*/

/*
################## WARNING!!!!! ################
Expand Down Expand Up @@ -106,6 +109,15 @@ boolean Plugin_017(uint8_t function, struct EventStruct *event, String& string)
break;
}

# if FEATURE_MQTT_DISCOVER
case PLUGIN_GET_DISCOVERY_VTYPES:
{
event->Par1 = static_cast<int>(Sensor_VType::SENSOR_TYPE_NONE); // Not yet supported
success = true;
break;
}
# endif // if FEATURE_MQTT_DISCOVER

case PLUGIN_I2C_HAS_ADDRESS:
{
success = (event->Par1 == 0x24);
Expand Down
12 changes: 12 additions & 0 deletions src/_P018_Dust.ino
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// #######################################################################################################

/** Changelog:
* 2025-01-12 tonhuisman: Add support for MQTT AutoDiscovery
* 2025-01-03 tonhuisman: Small code size improvements, source formatted using Uncrustify
*/

Expand Down Expand Up @@ -58,6 +59,17 @@ boolean Plugin_018(uint8_t function, struct EventStruct *event, String& string)
break;
}

# if FEATURE_MQTT_DISCOVER
case PLUGIN_GET_DISCOVERY_VTYPES:
{
for (uint8_t i = 0; i < event->Par5; ++i) {
event->ParN[i] = static_cast<int>(Sensor_VType::SENSOR_TYPE_DUSTPM2_5_ONLY);
}
success = true;
break;
}
# endif // if FEATURE_MQTT_DISCOVER

case PLUGIN_INIT:
{
Plugin_018_init = true;
Expand Down
10 changes: 10 additions & 0 deletions src/_P020_Ser2Net.ino
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/************
* Changelog:
* 2025-01-12 tonhuisman: Add support for MQTT AutoDiscovery (not supported yet for Ser2Net or P1 gateway)
* 2023-08-26 tonhuisman: P044 mode: Set RX time-out default to 50 msec for better receive pace of P1 data
* 2023-08-17 tonhuisman: P1 data: Allow some extra reading timeout between the data and the checksum, as some meters need more time to
* calculate the CRC. Add CR/LF before sending P1 data.
Expand Down Expand Up @@ -99,12 +100,21 @@ boolean Plugin_020(uint8_t function, struct EventStruct *event, String& string)
dev.VType = Sensor_VType::SENSOR_TYPE_STRING;
break;
}

case PLUGIN_GET_DEVICENAME:
{
string = P020_Emulate_P044 ? F(PLUGIN_NAME_020_044) : F(PLUGIN_NAME_020);
break;
}

# if FEATURE_MQTT_DISCOVER
case PLUGIN_GET_DISCOVERY_VTYPES:
{
event->Par1 = static_cast<int>(Sensor_VType::SENSOR_TYPE_NONE); // Not yet supported
success = true;
break;
}
# endif // if FEATURE_MQTT_DISCOVER

case PLUGIN_SET_DEFAULTS:
{
Expand Down
Loading

0 comments on commit 3666157

Please sign in to comment.