mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-23 10:46:31 +00:00
refactor adding units to sensor message
This commit is contained in:
parent
f0a393908f
commit
db9b95bbe7
@ -845,6 +845,19 @@ String GetSwitchText(uint32_t i) {
|
||||
return switch_text;
|
||||
}
|
||||
|
||||
void MqttAppendSensorUnits(void)
|
||||
{
|
||||
if (ResponseContains_P(PSTR(D_JSON_PRESSURE))) {
|
||||
ResponseAppend_P(PSTR(",\"" D_JSON_PRESSURE_UNIT "\":\"%s\""), PressureUnit().c_str());
|
||||
}
|
||||
if (ResponseContains_P(PSTR(D_JSON_TEMPERATURE))) {
|
||||
ResponseAppend_P(PSTR(",\"" D_JSON_TEMPERATURE_UNIT "\":\"%c\""), TempUnit());
|
||||
}
|
||||
if (ResponseContains_P(PSTR(D_JSON_SPEED)) && Settings->flag2.speed_conversion) {
|
||||
ResponseAppend_P(PSTR(",\"" D_JSON_SPEED_UNIT "\":\"%s\""), SpeedUnit().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
bool MqttShowSensor(bool call_show_sensor)
|
||||
{
|
||||
ResponseAppendTime();
|
||||
@ -893,15 +906,7 @@ bool MqttShowSensor(bool call_show_sensor)
|
||||
}
|
||||
|
||||
bool json_data_available = (ResponseLength() - json_data_start);
|
||||
if (ResponseContains_P(PSTR(D_JSON_PRESSURE))) {
|
||||
ResponseAppend_P(PSTR(",\"" D_JSON_PRESSURE_UNIT "\":\"%s\""), PressureUnit().c_str());
|
||||
}
|
||||
if (ResponseContains_P(PSTR(D_JSON_TEMPERATURE))) {
|
||||
ResponseAppend_P(PSTR(",\"" D_JSON_TEMPERATURE_UNIT "\":\"%c\""), TempUnit());
|
||||
}
|
||||
if (ResponseContains_P(PSTR(D_JSON_SPEED)) && Settings->flag2.speed_conversion) {
|
||||
ResponseAppend_P(PSTR(",\"" D_JSON_SPEED_UNIT "\":\"%s\""), SpeedUnit().c_str());
|
||||
}
|
||||
MqttAppendSensorUnits();
|
||||
ResponseJsonEnd();
|
||||
|
||||
if (call_show_sensor && json_data_available) { XdrvCall(FUNC_SHOW_SENSOR); }
|
||||
|
@ -2883,9 +2883,7 @@ void MI32ShowSomeSensors(){
|
||||
}
|
||||
cnt++;
|
||||
}
|
||||
if (ResponseContains_P(PSTR(D_JSON_TEMPERATURE))) {
|
||||
ResponseAppend_P(PSTR(",\"" D_JSON_TEMPERATURE_UNIT "\":\"%c\""), TempUnit());
|
||||
}
|
||||
MqttAppendSensorUnits();
|
||||
ResponseAppend_P(PSTR("}"));
|
||||
//AddLog(LOG_LEVEL_DEBUG,PSTR("M32: %s: show some %d %s"),D_CMND_MI32, MI32.mqttCurrentSlot, ResponseData());
|
||||
MqttPublishPrefixTopicRulesProcess_P(TELE, PSTR(D_RSLT_SENSOR), Settings->flag.mqtt_sensor_retain);
|
||||
@ -3274,9 +3272,7 @@ void MI32ShowTriggeredSensors(){
|
||||
}
|
||||
}
|
||||
if (cnt){ // if we got one, then publish
|
||||
if (ResponseContains_P(PSTR(D_JSON_TEMPERATURE))) {
|
||||
ResponseAppend_P(PSTR(",\"" D_JSON_TEMPERATURE_UNIT "\":\"%c\""), TempUnit());
|
||||
}
|
||||
MqttAppendSensorUnits();
|
||||
ResponseAppend_P(PSTR("}"));
|
||||
if(
|
||||
#ifdef USE_HOME_ASSISTANT
|
||||
|
Loading…
x
Reference in New Issue
Block a user