Fork of the espurna firmware for `mhsw` switches
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
1.8 KiB

api: rework plain and JSON implementations (#2405) - match paths through a custom AsyncWebHandler instead of using generic not-found fallback handler - allow MQTT-like patterns when registering paths (`simple/path`, `path/+/something`, `path/#`) Replaces `relay/0`, `relay/1` etc. with `relay/+`. Magnitudes are plain paths, but using `/+` in case there's more than 1 magnitude of the same type. - restore `std::function` as callback container (no more single-byte arg nonsense). Still, limit to 1 type per handler type - adds JSON handlers which will receive JsonObject root as both input and output. Same logic as plain - GET returns resource data, PUT updates it. - breaking change to `apiAuthenticate(request)`, it no longer will do `request->send(403)` and expect this to be handled externally. - allow `Api-Key` header containing the key, works for both GET & PUT plain requests. The only way to set apikey for JSON. - add `ApiRequest::param` to retrieve both GET and PUT params (aka args), remove ApiBuffer - remove `API_BUFFER_SIZE`. Allow custom form-data key=value pairs for requests, allow to send basic `String`. - add `API_JSON_BUFFER_SIZE` for the JSON buffer (both input and output) - `/apis` replaced with `/api/list`, no longer uses custom handler and is an `apiRegister` callback - `/api/rpc` custom handler replaced with an `apiRegister` callback WIP further down: - no more `webLog` for API requests, unless `webAccessLog` / `WEB_ACCESS_LOG` is set to `1`. This also needs to happen to the other handlers. - migrate to ArduinoJson v6, since it become apparent it is actually a good upgrade :) - actually make use of JSON endpoints more, right now it's just existing GET for sensors and relays - fork ESPAsyncWebServer to cleanup path parsing and temporary objects attached to the request (also, fix things a lot of things based on PRs there...)
4 years ago
  1. // -----------------------------------------------------------------------------
  2. // Lights
  3. // -----------------------------------------------------------------------------
  4. #pragma once
  5. #include "espurna.h"
  6. // TODO: lowercase
  7. namespace Light {
  8. constexpr size_t ChannelsMax = 5;
  9. constexpr long VALUE_MIN = LIGHT_MIN_VALUE;
  10. constexpr long VALUE_MAX = LIGHT_MAX_VALUE;
  11. constexpr long BRIGHTNESS_MIN = LIGHT_MIN_BRIGHTNESS;
  12. constexpr long BRIGHTNESS_MAX = LIGHT_MAX_BRIGHTNESS;
  13. constexpr long PWM_MIN = LIGHT_MIN_PWM;
  14. constexpr long PWM_MAX = LIGHT_MAX_PWM;
  15. constexpr long PWM_LIMIT = LIGHT_LIMIT_PWM;
  16. enum Communications : unsigned char {
  17. COMMS_NONE = 0,
  18. COMMS_NORMAL = 1 << 0,
  19. COMMS_GROUP = 1 << 1
  20. };
  21. }
  22. size_t lightChannels();
  23. unsigned int lightTransitionTime();
  24. void lightTransitionTime(unsigned long ms);
  25. void lightColor(const char* color, bool rgb);
  26. void lightColor(const String& color, bool rgb);
  27. void lightColor(const String& color);
  28. void lightColor(const char* color);
  29. void lightColor(unsigned long color);
  30. String lightColor(bool rgb);
  31. String lightColor();
  32. void lightState(unsigned char i, bool state);
  33. bool lightState(unsigned char i);
  34. void lightState(bool state);
  35. bool lightState();
  36. void lightBrightness(long brightness);
  37. long lightBrightness();
  38. long lightChannel(unsigned char id);
  39. void lightChannel(unsigned char id, long value);
  40. void lightBrightnessStep(long steps, long multiplier = LIGHT_STEP);
  41. void lightChannelStep(unsigned char id, long steps, long multiplier = LIGHT_STEP);
  42. void lightUpdate(bool save, bool forward, bool group_forward);
  43. void lightUpdate(bool save, bool forward);
  44. bool lightHasColor();
  45. bool lightUseCCT();
  46. void lightMQTT();
  47. void lightSetupChannels(unsigned char size);
  48. void lightSetup();