Removed repeating code

This commit is contained in:
Ollo 2020-12-21 17:07:15 +01:00
parent f8052bd9b0
commit 6f5c5536cc
2 changed files with 24 additions and 17 deletions

View File

@ -24,6 +24,13 @@
* @{
**/
#define NUMBER_TYPE "number"
#define TEMPERATUR_SENSOR_LIPO "lipo"
#define TEMPERATUR_SENSOR_WATER "water"
#define TEMPERATUR_SENSOR_OUTSIDE "temp"
#define TEMPERATURE_NAME "Temperature"
#define TEMPERATURE_UNIT "°C"
HomieNode plant0("plant0", "Plant 0", "Plant"); /**< dynamic Homie information for first plant */
HomieNode plant1("plant1", "Plant 1", "Plant"); /**< dynamic Homie information for second plant */
HomieNode plant2("plant2", "Plant 2", "Plant"); /**< dynamic Homie information for first plant */

View File

@ -303,12 +303,12 @@ void mode2MQTT()
float lipoTempCurrent = lipoTempSensor.getMedian();
if (lipoTempCurrent != NAN)
{
sensorTemp.setProperty("lipo").send(String(lipoTempCurrent));
sensorTemp.setProperty(TEMPERATUR_SENSOR_LIPO).send(String(lipoTempCurrent));
}
float t2 = waterTempSensor.getMedian();
if (t2 != NAN)
{
sensorTemp.setProperty("water").send(String(t2));
sensorTemp.setProperty(TEMPERATUR_SENSOR_WATER).send(String(t2));
}
//give mqtt time, use via publish callback instead?
@ -724,36 +724,36 @@ void systemInit()
{
mPlants[i].advertise();
}
sensorTemp.advertise("lipo")
.setName("Temperature")
.setDatatype("number")
.setUnit("°C");
sensorTemp.advertise("water")
.setName("Temperature")
.setDatatype("number")
.setUnit("°C");
sensorTemp.advertise(TEMPERATUR_SENSOR_LIPO)
.setName(TEMPERATURE_NAME)
.setDatatype(NUMBER_TYPE)
.setUnit(TEMPERATURE_UNIT);
sensorTemp.advertise(TEMPERATUR_SENSOR_WATER)
.setName(TEMPERATURE_NAME)
.setDatatype(NUMBER_TYPE)
.setUnit(TEMPERATURE_UNIT);
sensorLipo.advertise("percent")
.setName("Percent")
.setDatatype("number")
.setDatatype(NUMBER_TYPE)
.setUnit("%");
sensorLipo.advertise("volt")
.setName("Volt")
.setDatatype("number")
.setDatatype(NUMBER_TYPE)
.setUnit("V");
sensorSolar.advertise("percent")
.setName("Percent")
.setDatatype("number")
.setDatatype(NUMBER_TYPE)
.setUnit("%");
sensorSolar.advertise("volt")
.setName("Volt")
.setDatatype("number")
.setDatatype(NUMBER_TYPE)
.setUnit("V");
sensorWater.advertise("remaining").setDatatype("number").setUnit("%");
startupReason.advertise("startupReason").setDatatype("number").setUnit("Enum");
sensorWater.advertise("remaining").setDatatype(NUMBER_TYPE).setUnit("%");
startupReason.advertise("startupReason").setDatatype(NUMBER_TYPE).setUnit("Enum");
}
stayAlive.advertise("alive").setName("Alive").setDatatype("number").settable(aliveHandler);
stayAlive.advertise("alive").setName("Alive").setDatatype(NUMBER_TYPE).settable(aliveHandler);
}
bool mode1()