Describe interfaces with PROGMEM descriptor rows; drop the switch tables
AlexaInterfaces.h/.cpp hold one row per interface in program memory (28: namespace, version, property names, flags, type), each row and string an object of its own, so the linker keeps only the rows a sketch names. addCapability(AlexaInterfaceType) is an always-inline switch that folds to one row; a type without a row is refused with an error. The Event handler gets its type from the capabilities of the device. Versions follow the interface pages (EndpointHealth 3.1, ThermostatController 3.2), HumiditySensor is new, the two withdrawn interfaces and AlexaInterfaceUtils are gone. Display category names are in flash. The discovery objects of the five examples are unchanged: 14 new host tests compare them with what the previous commit announced. basicLight on a D1 mini: static RAM 34,508 -> 30,788, flash 338,533 -> 330,509; it links two rows, EndpointHealth and PowerController. Host tests: 47 -> 61. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
parent
d534f23f27
commit
8b11cc2394
13 changed files with 909 additions and 777 deletions
108
readme.md
108
readme.md
|
|
@ -149,71 +149,43 @@ Boards that run 1.1.0 or older keep working: the backend still publishes the tok
|
|||
---
|
||||
|
||||
## Interface Types
|
||||
| Alexa Interface Type | Status |
|
||||
|-----------------------------------------------------|-------------|
|
||||
| AlexaInterfaceType::ENDPOINT_HEALTH | Fully Supported |
|
||||
| AlexaInterfaceType::POWER_CONTROLLER | Fully Supported |
|
||||
| AlexaInterfaceType::BRIGHTNESS_CONTROLLER | Fully Supported |
|
||||
| AlexaInterfaceType::TOGGLE_CONTROLLER | Fully Supported |
|
||||
| AlexaInterfaceType::TEMPERATURE_SENSOR | Fully Supported |
|
||||
| AlexaInterfaceType::COLOR_TEMPERATURE_CONTROLLER | Fully Supported |
|
||||
| AlexaInterfaceType::AUTOMATION_MANAGEMENT | Supported* |
|
||||
| AlexaInterfaceType::CHANNEL_CONTROLLER | Supported* |
|
||||
| AlexaInterfaceType::COLOR_CONTROLLER | Supported* |
|
||||
| AlexaInterfaceType::CONTACT_SENSOR | Supported* |
|
||||
| AlexaInterfaceType::APPLICATION_STATE_REPORTER | Supported* |
|
||||
| AlexaInterfaceType::AUDIO_PLAY_QUEUE | Supported* |
|
||||
| AlexaInterfaceType::AUTHORIZATION_CONTROLLER | Supported* |
|
||||
| AlexaInterfaceType::AUTOMOTIVE_VEHICLE_DATA | Supported* |
|
||||
| AlexaInterfaceType::CAMERA_LIVE_VIEW_CONTROLLER | Supported* |
|
||||
| AlexaInterfaceType::CAMERA_STREAM_CONTROLLER | Supported* |
|
||||
| AlexaInterfaceType::COMMISSIONABLE | Supported* |
|
||||
| AlexaInterfaceType::CONSENT_MANAGEMENT_CONSENT_REQUIRED_REPORTER | Supported* |
|
||||
| AlexaInterfaceType::COOKING | Supported* |
|
||||
| AlexaInterfaceType::DATA_CONTROLLER | Supported* |
|
||||
| AlexaInterfaceType::DEVICE_USAGE_ESTIMATION | Supported* |
|
||||
| AlexaInterfaceType::DEVICE_USAGE_METER | Supported* |
|
||||
| AlexaInterfaceType::DOORBELL_EVENT_SOURCE | Supported* |
|
||||
| AlexaInterfaceType::EQUALIZER_CONTROLLER | Supported* |
|
||||
| AlexaInterfaceType::INPUT_CONTROLLER | Supported* |
|
||||
| AlexaInterfaceType::INVENTORY_LEVEL_SENSOR | Supported* |
|
||||
| AlexaInterfaceType::INVENTORY_LEVEL_USAGE_SENSOR | Supported* |
|
||||
| AlexaInterfaceType::INVENTORY_USAGE_SENSOR | Supported* |
|
||||
| AlexaInterfaceType::KEYPAD_CONTROLLER | Supported* |
|
||||
| AlexaInterfaceType::LAUNCHER | Supported* |
|
||||
| AlexaInterfaceType::LOCK_CONTROLLER | Supported* |
|
||||
| AlexaInterfaceType::MEDIA_PLAYBACK | Supported* |
|
||||
| AlexaInterfaceType::MEDIA_SEARCH | Supported* |
|
||||
| AlexaInterfaceType::MODE_CONTROLLER | Supported* |
|
||||
| AlexaInterfaceType::MOTION_SENSOR | Supported* |
|
||||
| AlexaInterfaceType::PERCENTAGE_CONTROLLER | Supported* |
|
||||
| AlexaInterfaceType::PLAYBACK_CONTROLLER | Supported* |
|
||||
| AlexaInterfaceType::PLAYBACK_STATE_REPORTER | Supported* |
|
||||
| AlexaInterfaceType::PROACTIVE_NOTIFICATION_SOURCE | Supported* |
|
||||
| AlexaInterfaceType::RANGE_CONTROLLER | Supported* |
|
||||
| AlexaInterfaceType::RECORD_CONTROLLER | Supported* |
|
||||
| AlexaInterfaceType::REMOTE_VIDEO_PLAYER | Supported* |
|
||||
| AlexaInterfaceType::RTC_SESSION_CONTROLLER | Supported* |
|
||||
| AlexaInterfaceType::SCENE_CONTROLLER | Supported* |
|
||||
| AlexaInterfaceType::SECURITY_PANEL_CONTROLLER | Supported* |
|
||||
| AlexaInterfaceType::SEEK_CONTROLLER | Supported* |
|
||||
| AlexaInterfaceType::SIMPLE_EVENT_SOURCE | Supported* |
|
||||
| AlexaInterfaceType::SMART_VISION_OBJECT_DETECTION_SENSOR | Supported* |
|
||||
| AlexaInterfaceType::SMART_VISION_SNAPSHOT_PROVIDER | Supported* |
|
||||
| AlexaInterfaceType::SPEAKER | Supported* |
|
||||
| AlexaInterfaceType::STEP_SPEAKER | Supported* |
|
||||
| AlexaInterfaceType::THERMOSTAT_CONTROLLER | Supported* |
|
||||
| AlexaInterfaceType::THERMOSTAT_CONTROLLER_CONFIGURATION | Supported* |
|
||||
| AlexaInterfaceType::THERMOSTAT_CONTROLLER_HVAC_COMPONENTS | Supported* |
|
||||
| AlexaInterfaceType::THERMOSTAT_CONTROLLER_SCHEDULE | Supported* |
|
||||
| AlexaInterfaceType::TIME_HOLD_CONTROLLER | Supported* |
|
||||
| AlexaInterfaceType::UI_CONTROLLER | Supported* |
|
||||
| AlexaInterfaceType::USER_PREFERENCE | Supported* |
|
||||
| AlexaInterfaceType::VIDEO_RECORDER | Supported* |
|
||||
| AlexaInterfaceType::WAKE_ON_LAN_CONTROLLER | Supported* |
|
||||
|
||||
The library describes these interfaces. `addCapability()` takes the row, `AlexaInterfaces::PowerController`, or the type as 1.x sketches write it, `AlexaInterfaceType::POWER_CONTROLLER`. A sketch links the rows it names and no others.
|
||||
|
||||
(*Partial support or limited implementation advanced configuration is required)
|
||||
| Row in `AlexaInterfaces` | `AlexaInterfaceType::` | Version | Properties | Report helper |
|
||||
|---|---|---|---|---|
|
||||
| `EndpointHealth` | `ENDPOINT_HEALTH` | 3.1 | connectivity | `AddHealthProp` |
|
||||
| `PowerController` | `POWER_CONTROLLER` | 3 | powerState | `AddPowerControllerProp` |
|
||||
| `BrightnessController` | `BRIGHTNESS_CONTROLLER` | 3 | brightness | `AddBrightnessControllerProp` |
|
||||
| `ColorTemperatureController` | `COLOR_TEMPERATURE_CONTROLLER` | 3 | colorTemperatureInKelvin | `AddColorTemperatureControllerProp` |
|
||||
| `ToggleController` | `TOGGLE_CONTROLLER` | 3 | toggleState | `AddToggleControllerProp` |
|
||||
| `TemperatureSensor` | `TEMPERATURE_SENSOR` | 3 | temperature | `AddTemperatureSensorProp` |
|
||||
| `ColorController` | `COLOR_CONTROLLER` | 3 | color | `AddContextProp` |
|
||||
| `PowerLevelController` | `POWER_LEVEL_CONTROLLER` | 3 | powerLevel | `AddContextProp` |
|
||||
| `PercentageController` | `PERCENTAGE_CONTROLLER` | 3 | percentage | `AddContextProp` |
|
||||
| `RangeController` | `RANGE_CONTROLLER` | 3 | rangeValue | `AddContextProp` |
|
||||
| `ModeController` | `MODE_CONTROLLER` | 3 | mode | `AddContextProp` |
|
||||
| `ThermostatController` | `THERMOSTAT_CONTROLLER` | 3.2 | targetSetpoint, lowerSetpoint, upperSetpoint, thermostatMode | `AddContextProp` |
|
||||
| `HumiditySensor` | `HUMIDITY_SENSOR` | 3 | relativeHumidity | `AddContextProp` |
|
||||
| `LockController` | `LOCK_CONTROLLER` | 3 | lockState | `AddContextProp` |
|
||||
| `ContactSensor` | `CONTACT_SENSOR` | 3 | detectionState | `AddContextProp` |
|
||||
| `MotionSensor` | `MOTION_SENSOR` | 3 | detectionState | `AddContextProp` |
|
||||
| `TimeHoldController` | `TIME_HOLD_CONTROLLER` | 3 | holdStartTime, holdEndTime | `AddContextProp` |
|
||||
| `Speaker` | `SPEAKER` | 3 | volume, muted | `AddContextProp` |
|
||||
| `PlaybackStateReporter` | `PLAYBACK_STATE_REPORTER` | 3 | playbackState | `AddContextProp` |
|
||||
| `InputController` | `INPUT_CONTROLLER` | 3 | input | `AddContextProp` |
|
||||
| `ChannelController` | `CHANNEL_CONTROLLER` | 3 | channel | `AddContextProp` |
|
||||
| `InventoryLevelSensor` | `INVENTORY_LEVEL_SENSOR` | 3 | level | `AddContextProp` |
|
||||
| `PlaybackController` | `PLAYBACK_CONTROLLER` | 3 | none | |
|
||||
| `WakeOnLANController` | `WAKE_ON_LAN_CONTROLLER` | 3 | none | |
|
||||
| `SceneController` | `SCENE_CONTROLLER` | 3 | no `properties` object | |
|
||||
| `DoorbellEventSource` | `DOORBELL_EVENT_SOURCE` | 3 | no `properties` object | |
|
||||
| `StepSpeaker` | `STEP_SPEAKER` | 3 | no `properties` object | |
|
||||
| `SimpleEventSource` | `SIMPLE_EVENT_SOURCE` | 1.0 | no `properties` object | |
|
||||
|
||||
The interfaces below the first six are announced with their version and properties; what else their discovery object needs (the configuration of a thermostat, the presets of a range) and their events are not built by the library yet.
|
||||
|
||||
Every other value of `AlexaInterfaceType` (`COOKING`, `LAUNCHER`, `SECURITY_PANEL_CONTROLLER`, ...) names an interface the library has no row for. `addCapability()` adds nothing for it, prints `[Alex2ESP] error: <endpointId>: capability not added: ...` and returns `nullptr`.
|
||||
|
||||
---
|
||||
|
||||
|
|
@ -256,10 +228,16 @@ Behaviour changes:
|
|||
- A report is sent through the client that created its device. An `AlexaDevice` or an `AlexaStatusMessage` that a sketch constructs itself has no client: `send()` returns `false` and prints `report for <endpointId> not sent: its device was not created by getDevice()`, where 1.1.0 queued the report. Use `getDevice()` and `buildStatusMessage()`. Both constructors take the client as an optional last argument, an `AlexaTransport*`.
|
||||
- New: `Alex2ESP::setLogLevel()`, `Alex2ESP::setTimeSource()`, `AlexaDevice::hasEndpointId()`, `AlexaLog`, `AlexaSendResult`, and `AlexaTransport`, the interface a device sends and stamps its reports through. `Alex2ESP` implements it with `publish(topic, document)`, which sends a `JsonDocument` on the session of the library under the same checks as a report and returns an `AlexaSendResult`, and `timestamp(buffer, size)`, which writes the current time as `timeOfSample` has it.
|
||||
- Removed: the queues and buffers of `AlexaUtils` (`enqueue`, `dequeue`, `dequeueVals`, `enqueueReceive`, `dequeueReceive`, `isQueueEmpty`, `isQueueFull`, `isReceiveQueueEmpty`, `isReceiveQueueFull`, `receivePayload`, `nextMessageId`) and its `log`/`logln`, which printed nothing unless the library was edited; `AlexaUtils::printMemoryInfo()` stays. `MAX_STATUS_REPORT_SIZE` (the limit is `ALEX2ESP_MAX_MESSAGE`). The library no longer includes `ESP8266HTTPClient`.
|
||||
- Interfaces are described by rows in program memory, `AlexaInterfaces::PowerController` and 27 more (see Interface Types), in place of the `switch` tables of `AlexaInterfaceUtils`, whose strings took RAM in every sketch. `addCapability()` takes a row or, as before, an `AlexaInterfaceType`; a sketch links only the rows it names. The discovery objects of the five examples are the same byte for byte.
|
||||
- Versions and properties follow the interface pages of Alexa: `EndpointHealth` is announced as 3.1 (1.1.0: 3.3) and `ThermostatController` as 3.2 with its four properties (1.1.0: 3, none). `Speaker`, `StepSpeaker`, `PlaybackStateReporter`, `InventoryLevelSensor` and `WakeOnLANController` are announced as 3 (1.1.0: 1), `SimpleEventSource` as 1.0. The interfaces that 1.1.0 announced with an empty list of properties have their properties (`lockState`, `detectionState`, `mode`, `rangeValue`, `percentage`, ...). `SceneController`, `DoorbellEventSource`, `StepSpeaker` and `SimpleEventSource` are announced without a `properties` object.
|
||||
- New: `AlexaInterfaceType::HUMIDITY_SENSOR` with its row, `AlexaInterfaces::HumiditySensor`. `AlexaDevice::getInterfaceType(namespace)`.
|
||||
- `addCapability()` with a type that has no row adds nothing, prints an error and returns `nullptr`. 1.1.0 announced such an interface as version 1 without properties.
|
||||
- The handler of `Event` gets the type of the capability of its device that the directive names, and `AlexaInterfaceType::UNKNOWN` for a namespace the device has no capability for. 1.1.0 looked the namespace up among all interfaces.
|
||||
- Removed: `AlexaInterfaceType::AUTHORIZATION_CONTROLLER` and `AUTOMOTIVE_VEHICLE_DATA`, which Alexa has withdrawn. `AlexaInterfaceUtils` (`toString`, `fromString`, `getVersion`, `getProps`): a row has the namespace, the version and the properties, `alexaInterfaceRow(type)` gives the row of a type. The constructor of `AlexaInterface` takes a row. `DisplayCategory` and `AlexaInterfaceType` are one byte wide.
|
||||
|
||||
Memory: `examples/basicLight.cpp` for a D1 mini takes 34,508 bytes of static RAM (1.1.0: 52,768) and 338,533 bytes of flash (1.1.0: 350,885), as PlatformIO reports them (espressif8266 4.2.1, Arduino core 3.1.2). The static RAM was the five 2 KB queue slots, three more 2 KB buffers and the two HTTP clients. SNTP and the time stamp are 1.8 KB of the flash figure.
|
||||
Memory: `examples/basicLight.cpp` for a D1 mini takes 30,788 bytes of static RAM (1.1.0: 52,768) and 330,509 bytes of flash (1.1.0: 350,885), as PlatformIO reports them (espressif8266 4.2.1, Arduino core 3.1.2). 18,260 bytes of the static RAM were the five 2 KB queue slots, three more 2 KB buffers and the two HTTP clients; 3,720 were the names, versions and properties of all interfaces and the names of the display categories, which are in flash now. SNTP and the time stamp are 1.8 KB of the flash figure.
|
||||
|
||||
Tests: `pio test -e native` in the repository runs 47 host tests of the receive and publish logic (reassembly of fragments, the directives that wait for `loop()`, repeated directives, the size limits, a heap without room, the wait between reconnects, topics, time stamps). No board is needed.
|
||||
Tests: `pio test -e native` in the repository runs 61 host tests: 47 of the receive and publish logic (reassembly of fragments, the directives that wait for `loop()`, repeated directives, the size limits, a heap without room, the wait between reconnects, topics, time stamps) and 14 of discovery (the discovery object of every example against what 1.1.0 announced, the 28 rows against the interface pages, a type without a row). No board is needed.
|
||||
|
||||
Packaging: `library.json`, `library.properties` and the `softwareVersion` and `firmwareVersion` that a device reports in discovery say 1.2.0; the library has the number in one place, `ALEX2ESP_VERSION` in `src/AlexaVersion.h`. The `platformio.ini` of the repository is for the host tests; a sketch does not need it.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue