Add enforce Hass discovery as light group

Add command SetOption30 to enforce Hass discovery as light group (#1784)
This commit is contained in:
Theo Arends 2018-06-29 11:15:27 +02:00
parent bcafce2dd0
commit 1c6f752ba8
6 changed files with 18 additions and 7 deletions

View File

@ -1,4 +1,6 @@
/* 6.0.0b
* Add command SetOption30 to enforce Hass discovery as light group (#1784)
* Add decimal values support for commands ADD, SUB, MULT and SCALE (#3083, #3089)
* Add experimental (untested) TM1638 switch support (#2226)
* Change number of switches from 4 to 8 (#2885, #3086)
*

View File

@ -55,7 +55,7 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu
uint32_t knx_enable_enhancement : 1; // bit 27 (v5.14.0a) KNX
uint32_t rf_receive_decimal : 1; // bit 28 (v6.0.0a)
uint32_t ir_receive_decimal : 1; // bit 29 (v6.0.0a)
uint32_t spare30 : 1;
uint32_t hass_light : 1; // bit 30 (v6.0.0b)
uint32_t spare31 : 1;
};
} SysBitfield;

View File

@ -573,7 +573,7 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len)
XsnsCall(FUNC_COMMAND);
// if (!XsnsCall(FUNC_COMMAND)) type = NULL;
}
else if ((CMND_SETOPTION == command_code) && ((index <= 29) || ((index > 31) && (index <= P_MAX_PARAM8 + 31)))) {
else if ((CMND_SETOPTION == command_code) && (index <= P_MAX_PARAM8 + 31)) {
if (index <= 31) {
ptype = 0; // SetOption0 .. 31
} else {
@ -611,6 +611,7 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len)
// case 27: // knx_enable_enhancement
case 28: // rf_receive_decimal
case 29: // ir_receive_decimal
case 30: // hass_light
bitWrite(Settings.flag.data, index, payload);
}
if (12 == index) { // stop_flash_rotate
@ -618,7 +619,7 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len)
SettingsSave(2);
}
#ifdef USE_HOME_ASSISTANT
if (19 == index) { // hass_discovery
if ((19 == index) || (30 == index)) { // hass_discovery or hass_light
HAssDiscovery(1);
}
#endif // USE_HOME_ASSISTANT

View File

@ -869,6 +869,12 @@ void GetFeatures()
#ifdef USE_LM75AD
feature_sns1 |= 0x20000000; // xsns_26_lm75ad.ino
#endif
#ifdef USE_APDS9960
feature_sns1 |= 0x40000000; // xsns_27_apds9960.ino
#endif
#ifdef USE_TM1638
feature_sns1 |= 0x80000000; // xsns_28_tm1638.ino
#endif
/*********************************************************************************************/

View File

@ -71,18 +71,20 @@ void HAssDiscoverRelay()
char sidx[8];
char stopic[TOPSZ];
bool is_light = false;
bool is_topic_light = false;
for (int i = 1; i <= MAX_RELAYS; i++) {
is_light = ((i == devices_present) && (light_type));
is_topic_light = Settings.flag.hass_light;
mqtt_data[0] = '\0'; // Clear retained message
snprintf_P(sidx, sizeof(sidx), PSTR("_%d"), i);
// Clear "other" topic first in case the device has been reconfigured
snprintf_P(stopic, sizeof(stopic), PSTR(HOME_ASSISTANT_DISCOVERY_PREFIX "/%s/%s%s/config"), (is_light) ? "switch" : "light", mqtt_topic, sidx);
snprintf_P(stopic, sizeof(stopic), PSTR(HOME_ASSISTANT_DISCOVERY_PREFIX "/%s/%s%s/config"), (is_topic_light) ? "switch" : "light", mqtt_topic, sidx);
MqttPublish(stopic, true);
// Clear or Set topic
snprintf_P(stopic, sizeof(stopic), PSTR(HOME_ASSISTANT_DISCOVERY_PREFIX "/%s/%s%s/config"), (is_light) ? "light" : "switch", mqtt_topic, sidx);
snprintf_P(stopic, sizeof(stopic), PSTR(HOME_ASSISTANT_DISCOVERY_PREFIX "/%s/%s%s/config"), (is_topic_light) ? "light" : "switch", mqtt_topic, sidx);
if (Settings.flag.hass_discovery && (i <= devices_present)) {
char name[33];

View File

@ -79,7 +79,7 @@ a_setoption = [
"KNX enhancement",
"RF receive decimal",
"IR receive decimal",
"",""]
"Enforce HASS light group",""]
a_features = [[
"","","USE_I2C","USE_SPI",
@ -107,7 +107,7 @@ a_features = [[
"USE_INA219","USE_SHT3X","USE_MHZ19","USE_TSL2561",
"USE_SENSEAIR","USE_PMS5003","USE_MGS","USE_NOVA_SDS",
"USE_SGP30","USE_SR04","USE_SDM120","USE_SI1145",
"USE_SDM630","USE_LM75AD","",""
"USE_SDM630","USE_LM75AD","USE_APDS9960","USE_TM1638"
],[
"","","","",
"","","","",