mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-24 11:46:34 +00:00
Update discovery and device classes for binary_input
This commit is contained in:
parent
6879cf12f5
commit
2fa975f21c
@ -481,7 +481,7 @@ void dispatch_screenshot(const char*, const char* filename)
|
||||
memcpy_P(tempfile, PSTR("/screenshot.bmp"), sizeof(tempfile));
|
||||
guiTakeScreenshot(tempfile);
|
||||
} else if(strlen(filename) > 31 || filename[0] != '/') { // Invalid filename
|
||||
LOG_WARNING(TAG_MSGR, "Invalid filename %s", filename);
|
||||
LOG_WARNING(TAG_MSGR, F("D_FILE_SAVE_FAILED"), filename);
|
||||
} else { // Valid filename
|
||||
guiTakeScreenshot(filename);
|
||||
}
|
||||
@ -803,24 +803,27 @@ void dispatch_send_discovery(const char*, const char*)
|
||||
{
|
||||
#if HASP_USE_MQTT > 0
|
||||
|
||||
StaticJsonDocument<512> doc;
|
||||
char data[512];
|
||||
haspGetVersion(data, sizeof(data));
|
||||
StaticJsonDocument<1024> doc;
|
||||
|
||||
doc[F("node")] = haspDevice.get_hostname();
|
||||
doc[F("model")] = haspDevice.get_model();
|
||||
doc[F("manufacturer")] = F(D_MANUFACTURER);
|
||||
doc[F("hwid")] = haspDevice.get_hardware_id();
|
||||
doc[F("version")] = data;
|
||||
doc[F("numPages")] = haspPages.count();
|
||||
doc[F("node")] = haspDevice.get_hostname();
|
||||
doc[F("mdl")] = haspDevice.get_model();
|
||||
doc[F("mf")] = F(D_MANUFACTURER);
|
||||
doc[F("hwid")] = haspDevice.get_hardware_id();
|
||||
doc[F("pages")] = haspPages.count();
|
||||
|
||||
JsonArray relay = doc.createNestedArray(F("relay"));
|
||||
JsonArray led = doc.createNestedArray(F("led"));
|
||||
JsonObject input = doc.createNestedObject(F("input"));
|
||||
JsonArray relay = doc.createNestedArray(F("power"));
|
||||
JsonArray led = doc.createNestedArray(F("light"));
|
||||
JsonArray dimmer = doc.createNestedArray(F("dim"));
|
||||
|
||||
#if HASP_USE_GPIO > 0
|
||||
gpio_discovery(relay, led);
|
||||
gpio_discovery(input, relay, led, dimmer);
|
||||
#endif
|
||||
|
||||
char data[1024];
|
||||
haspGetVersion(data, sizeof(data));
|
||||
doc[F("sw")] = data;
|
||||
|
||||
size_t len = serializeJson(doc, data);
|
||||
switch(mqtt_send_discovery(data, len)) {
|
||||
case MQTT_ERR_OK:
|
||||
|
@ -793,11 +793,16 @@ hasp_gpio_config_t gpioGetPinConfig(uint8_t num)
|
||||
return gpioConfig[num];
|
||||
}
|
||||
|
||||
void gpio_discovery(JsonArray& relay, JsonArray& led)
|
||||
void gpio_discovery(JsonObject& input, JsonArray& relay, JsonArray& light, JsonArray& dimmer)
|
||||
{
|
||||
char description[20];
|
||||
|
||||
for(uint8_t i = 0; i < HASP_NUM_GPIO_CONFIG; i++) {
|
||||
switch(gpioConfig[i].type) {
|
||||
case hasp_gpio_type_t::LIGHT_RELAY:
|
||||
light.add(gpioConfig[i].pin);
|
||||
break;
|
||||
|
||||
case hasp_gpio_type_t::POWER_RELAY:
|
||||
relay.add(gpioConfig[i].pin);
|
||||
break;
|
||||
@ -807,16 +812,94 @@ void gpio_discovery(JsonArray& relay, JsonArray& led)
|
||||
case hasp_gpio_type_t::SERIAL_DIMMER:
|
||||
case hasp_gpio_type_t::SERIAL_DIMMER_AU:
|
||||
case hasp_gpio_type_t::SERIAL_DIMMER_EU:
|
||||
led.add(gpioConfig[i].pin);
|
||||
dimmer.add(gpioConfig[i].pin);
|
||||
break;
|
||||
|
||||
// pwm.add(gpioConfig[i].pin);
|
||||
case SWITCH:
|
||||
strcpy_P(description, PSTR("none"));
|
||||
break;
|
||||
case BATTERY:
|
||||
strcpy_P(description, PSTR("battery"));
|
||||
break;
|
||||
case BATTERY_CHARGING:
|
||||
strcpy_P(description, PSTR("battery_charging"));
|
||||
break;
|
||||
case COLD:
|
||||
strcpy_P(description, PSTR("cold"));
|
||||
break;
|
||||
case CONNECTIVITY:
|
||||
strcpy_P(description, PSTR("connectivity"));
|
||||
break;
|
||||
case DOOR:
|
||||
strcpy_P(description, PSTR("door"));
|
||||
break;
|
||||
case GARAGE_DOOR:
|
||||
strcpy_P(description, PSTR("garage_door"));
|
||||
break;
|
||||
case GAS:
|
||||
strcpy_P(description, PSTR("gas"));
|
||||
break;
|
||||
case HEAT:
|
||||
strcpy_P(description, PSTR("heat"));
|
||||
break;
|
||||
case LIGHT:
|
||||
strcpy_P(description, PSTR("light"));
|
||||
break;
|
||||
case LOCK:
|
||||
strcpy_P(description, PSTR("lock"));
|
||||
break;
|
||||
case MOISTURE:
|
||||
strcpy_P(description, PSTR("moisture"));
|
||||
break;
|
||||
case MOTION:
|
||||
strcpy_P(description, PSTR("motion"));
|
||||
break;
|
||||
case MOVING:
|
||||
strcpy_P(description, PSTR("moving"));
|
||||
break;
|
||||
case OCCUPANCY:
|
||||
strcpy_P(description, PSTR("occupancy"));
|
||||
break;
|
||||
case OPENING:
|
||||
strcpy_P(description, PSTR("opening"));
|
||||
break;
|
||||
case PLUG:
|
||||
strcpy_P(description, PSTR("plug"));
|
||||
break;
|
||||
case POWER:
|
||||
strcpy_P(description, PSTR("power"));
|
||||
break;
|
||||
case PRESENCE:
|
||||
strcpy_P(description, PSTR("presence"));
|
||||
break;
|
||||
case PROBLEM:
|
||||
strcpy_P(description, PSTR("problem"));
|
||||
break;
|
||||
case SAFETY:
|
||||
strcpy_P(description, PSTR("safety"));
|
||||
break;
|
||||
case SMOKE:
|
||||
strcpy_P(description, PSTR("smoke"));
|
||||
break;
|
||||
case SOUND:
|
||||
strcpy_P(description, PSTR("sound"));
|
||||
break;
|
||||
case VIBRATION:
|
||||
strcpy_P(description, PSTR("vibration"));
|
||||
break;
|
||||
case WINDOW:
|
||||
strcpy_P(description, PSTR("window"));
|
||||
break;
|
||||
|
||||
case hasp_gpio_type_t::FREE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if(gpioConfig[i].type >= hasp_gpio_type_t::SWITCH && gpioConfig[i].type <= hasp_gpio_type_t::WINDOW) {
|
||||
JsonArray arr = input[description];
|
||||
if(arr.isNull()) arr = input.createNestedArray(description);
|
||||
arr.add(gpioConfig[i].pin);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -44,7 +44,7 @@ bool gpio_set_pin_state(uint8_t pin, bool power, int32_t val);
|
||||
|
||||
void gpio_set_moodlight(moodlight_t& moodlight);
|
||||
|
||||
void gpio_discovery(JsonArray& relay, JsonArray& led);
|
||||
void gpio_discovery(JsonObject& input, JsonArray& relay, JsonArray& light, JsonArray& dimmer);
|
||||
|
||||
bool gpioSavePinConfig(uint8_t config_num, uint8_t pin, uint8_t type, uint8_t group, uint8_t pinfunc, bool inverted);
|
||||
bool gpioIsSystemPin(uint8_t gpio);
|
||||
@ -93,6 +93,7 @@ enum hasp_gpio_type_t {
|
||||
HAPTIC = 0x41,
|
||||
|
||||
/* Inputs */
|
||||
SWITCH = 0xA0, // Binary Sensors
|
||||
BATTERY = 0xA1,
|
||||
BATTERY_CHARGING = 0xA2,
|
||||
COLD = 0xA3,
|
||||
@ -105,18 +106,26 @@ enum hasp_gpio_type_t {
|
||||
LOCK = 0xAA,
|
||||
MOISTURE = 0xAB,
|
||||
MOTION = 0xAC,
|
||||
OCCUPANCY = 0xAD,
|
||||
OPENING = 0xAE,
|
||||
PLUG = 0xAF,
|
||||
PRESENCE = 0xB0,
|
||||
PROBLEM = 0xB1,
|
||||
SAFETY = 0xB2,
|
||||
SMOKE = 0xB3,
|
||||
SOUND = 0xB4,
|
||||
VIBRATION = 0xB5,
|
||||
WINDOW = 0xB6,
|
||||
MOVING = 0xAD,
|
||||
OCCUPANCY = 0xAE,
|
||||
OPENING = 0xAF,
|
||||
PLUG = 0xB0,
|
||||
POWER = 0xB1,
|
||||
PRESENCE = 0xB2,
|
||||
PROBLEM = 0xB3,
|
||||
SAFETY = 0xB4,
|
||||
SMOKE = 0xB5,
|
||||
SOUND = 0xB6,
|
||||
VIBRATION = 0xB7,
|
||||
WINDOW = 0xB8,
|
||||
|
||||
SWITCH = 0xC0, // Binary Sensors
|
||||
AWNING = 0xB9,
|
||||
BLIND = 0xBA,
|
||||
CURTAIN = 0xBB,
|
||||
DAMPER = 0xBC,
|
||||
GATE = 0xBD,
|
||||
SHADE = 0xBE,
|
||||
SHUTTER = 0xBF,
|
||||
|
||||
BUTTON = 0xF0,
|
||||
BUTTON_TOGGLE_ON = 0xF1,
|
||||
|
Loading…
x
Reference in New Issue
Block a user