Fix wrong telemetry message when SetOption68 1 (#6191)

This commit is contained in:
Stephan Hadinger 2019-08-16 18:33:41 +02:00
parent 697ec3fc7f
commit 4aeaff66aa
2 changed files with 52 additions and 37 deletions

View File

@ -629,13 +629,13 @@ void MqttShowState(void)
ResponseAppend_P(PSTR(",\"" D_JSON_HEAPSIZE "\":%d,\"SleepMode\":\"%s\",\"Sleep\":%u,\"LoadAvg\":%u,\"MqttCount\":%u"), ResponseAppend_P(PSTR(",\"" D_JSON_HEAPSIZE "\":%d,\"SleepMode\":\"%s\",\"Sleep\":%u,\"LoadAvg\":%u,\"MqttCount\":%u"),
ESP.getFreeHeap()/1024, GetTextIndexed(stemp1, sizeof(stemp1), Settings.flag3.sleep_normal, kSleepMode), sleep, loop_load_avg, MqttConnectCount()); ESP.getFreeHeap()/1024, GetTextIndexed(stemp1, sizeof(stemp1), Settings.flag3.sleep_normal, kSleepMode), sleep, loop_load_avg, MqttConnectCount());
for (uint32_t i = 0; i < devices_present; i++) { for (uint32_t i = 1; i <= devices_present; i++) {
#ifdef USE_LIGHT #ifdef USE_LIGHT
if (i == light_device -1) { if (i >= light_device) {
LightState(1); if (i == light_device) { LightState(1); } // call it only once
} else { } else {
#endif #endif
ResponseAppend_P(PSTR(",\"%s\":\"%s\""), GetPowerDevice(stemp1, i +1, sizeof(stemp1), Settings.flag.device_index_enable), GetStateText(bitRead(power, i))); ResponseAppend_P(PSTR(",\"%s\":\"%s\""), GetPowerDevice(stemp1, i, sizeof(stemp1), Settings.flag.device_index_enable), GetStateText(bitRead(power, i-1)));
#ifdef USE_SONOFF_IFAN #ifdef USE_SONOFF_IFAN
if (IsModuleIfan()) { if (IsModuleIfan()) {
ResponseAppend_P(PSTR(",\"" D_CMND_FANSPEED "\":%d"), GetFanspeed()); ResponseAppend_P(PSTR(",\"" D_CMND_FANSPEED "\":%d"), GetFanspeed());

View File

@ -1592,8 +1592,10 @@ void LightState(uint8_t append)
} else { } else {
Response_P(PSTR("{")); Response_P(PSTR("{"));
} }
if (!light_pwm_multi_channels) {
GetPowerDevice(scommand, light_device, sizeof(scommand), Settings.flag.device_index_enable); GetPowerDevice(scommand, light_device, sizeof(scommand), Settings.flag.device_index_enable);
ResponseAppend_P(PSTR("\"%s\":\"%s\",\"" D_CMND_DIMMER "\":%d"), scommand, GetStateText(light_power), light_state.getDimmer()); ResponseAppend_P(PSTR("\"%s\":\"%s\",\"" D_CMND_DIMMER "\":%d"), scommand, GetStateText(light_power), light_state.getDimmer());
if (light_subtype > LST_SINGLE) { if (light_subtype > LST_SINGLE) {
ResponseAppend_P(PSTR(",\"" D_CMND_COLOR "\":\"%s\""), LightGetColor(scolor)); ResponseAppend_P(PSTR(",\"" D_CMND_COLOR "\":\"%s\""), LightGetColor(scolor));
uint16_t hue; uint16_t hue;
@ -1617,6 +1619,7 @@ void LightState(uint8_t append)
if ((LST_COLDWARM == light_subtype) || (LST_RGBWC == light_subtype)) { if ((LST_COLDWARM == light_subtype) || (LST_RGBWC == light_subtype)) {
ResponseAppend_P(PSTR(",\"" D_CMND_COLORTEMPERATURE "\":%d"), light_state.getCT()); ResponseAppend_P(PSTR(",\"" D_CMND_COLORTEMPERATURE "\":%d"), light_state.getCT());
} }
if (append) { if (append) {
if (light_subtype >= LST_RGB) { if (light_subtype >= LST_RGB) {
ResponseAppend_P(PSTR(",\"" D_CMND_SCHEME "\":%d"), Settings.light_scheme); ResponseAppend_P(PSTR(",\"" D_CMND_SCHEME "\":%d"), Settings.light_scheme);
@ -1626,7 +1629,19 @@ void LightState(uint8_t append)
} }
ResponseAppend_P(PSTR(",\"" D_CMND_FADE "\":\"%s\",\"" D_CMND_SPEED "\":%d,\"" D_CMND_LEDTABLE "\":\"%s\""), ResponseAppend_P(PSTR(",\"" D_CMND_FADE "\":\"%s\",\"" D_CMND_SPEED "\":%d,\"" D_CMND_LEDTABLE "\":\"%s\""),
GetStateText(Settings.light_fade), Settings.light_speed, GetStateText(Settings.light_correction)); GetStateText(Settings.light_fade), Settings.light_speed, GetStateText(Settings.light_correction));
} else { }
} else { // light_pwm_multi_channels
for (uint32_t i = 0; i < light_subtype; i++) {
GetPowerDevice(scommand, light_device + i, sizeof(scommand), 1);
uint32_t light_power_masked = light_power & (1 << i); // the light_power value for this device
light_power_masked = light_power_masked ? 1 : 0; // convert to on/off
ResponseAppend_P(PSTR("\"%s\":\"%s\",\"" D_CMND_CHANNEL "%d\":%d"), scommand, GetStateText(light_power_masked), light_device + i,
changeUIntScale(light_current_color[i], 0, 255, 0, 100));
}
ResponseAppend_P(PSTR(",\"" D_CMND_COLOR "\":\"%s\""), LightGetColor(scolor));
} // light_pwm_multi_channels
if (!append) {
ResponseJsonEnd(); ResponseJsonEnd();
} }
} }
@ -2227,7 +2242,7 @@ void CmndWhite(void)
void CmndChannel(void) void CmndChannel(void)
{ {
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= light_subtype )) { if ((XdrvMailbox.index >= light_device) && (XdrvMailbox.index < light_device + light_subtype )) {
bool coldim = false; bool coldim = false;
// Set "Channel" directly - this allows Color and Direct PWM control to coexist // Set "Channel" directly - this allows Color and Direct PWM control to coexist
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 100)) { if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 100)) {