From d9b9e1449dd485c52c404f6770bfc4ca95fd0121 Mon Sep 17 00:00:00 2001 From: copyrights <219009+copyrights@users.noreply.github.com> Date: Thu, 23 May 2019 05:53:33 +0200 Subject: [PATCH] MQTT and HA brightness (#1730) * MQTT and HA brightness shall only be depended on LIGHT_PROVIDER != LIGHT_PROVIDER_NONE * remove unnecessary changes --- code/espurna/homeassistant.ino | 5 +++-- code/espurna/light.ino | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/code/espurna/homeassistant.ino b/code/espurna/homeassistant.ino index 553de28b..079e58d9 100644 --- a/code/espurna/homeassistant.ino +++ b/code/espurna/homeassistant.ino @@ -98,9 +98,10 @@ void _haSendSwitch(unsigned char i, JsonObject& config) { if (i == 0) { + config["brightness_state_topic"] = mqttTopic(MQTT_TOPIC_BRIGHTNESS, false); + config["brightness_command_topic"] = mqttTopic(MQTT_TOPIC_BRIGHTNESS, true); + if (lightHasColor()) { - config["brightness_state_topic"] = mqttTopic(MQTT_TOPIC_BRIGHTNESS, false); - config["brightness_command_topic"] = mqttTopic(MQTT_TOPIC_BRIGHTNESS, true); config["rgb_state_topic"] = mqttTopic(MQTT_TOPIC_COLOR_RGB, false); config["rgb_command_topic"] = mqttTopic(MQTT_TOPIC_COLOR_RGB, true); config["color_temp_command_topic"] = mqttTopic(MQTT_TOPIC_MIRED, true); diff --git a/code/espurna/light.ino b/code/espurna/light.ino index 5e58b5b3..51ab46b9 100644 --- a/code/espurna/light.ino +++ b/code/espurna/light.ino @@ -539,8 +539,9 @@ void _lightMQTTCallback(unsigned int type, const char * topic, const char * payl if (type == MQTT_CONNECT_EVENT) { + mqttSubscribe(MQTT_TOPIC_BRIGHTNESS); + if (_light_has_color) { - mqttSubscribe(MQTT_TOPIC_BRIGHTNESS); mqttSubscribe(MQTT_TOPIC_MIRED); mqttSubscribe(MQTT_TOPIC_KELVIN); mqttSubscribe(MQTT_TOPIC_COLOR_RGB);