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 plant0("plant0", "Plant 0", "Plant"); /**< dynamic Homie information for first plant */
HomieNode plant1("plant1", "Plant 1", "Plant"); /**< dynamic Homie information for second 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 */ HomieNode plant2("plant2", "Plant 2", "Plant"); /**< dynamic Homie information for first plant */

View File

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