mirror of
https://github.com/rstrouse/ESPSomfy-RTS.git
synced 2026-10-31 22:02:17 +01:00
The p_* setters and emitState() no longer publish or emit straight away:
they set SHADE_CHANGED_* / GROUP_CHANGED_* bits on the shade or group.
At the end of every loop() pass SomfyShadeController::sendChanges()
publishes the MQTT topics whose bits are set and sends one shadeState or
groupState, then clears the bits. emitState(evt) with an event name and
emitState(num) for one client still go out at once.
publishShadeTopics() (ShadeChanges.cpp, tested natively) writes the topics
from a shade snapshot; publishState() on connect uses it too. That fixes
MQTT position and target, a constant 50 since c94819e, and direction, a
constant 0 on connect. position and tiltPosition are now retained when
they change, as they were on connect, and a group whose flags change sends
one groupState instead of two. somfy_flags_t moves to ShadeTypes.h.
8 new native tests, 327 in all. Flash: esp32devdbg +196 bytes, esp32dev
+228 bytes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
44 lines
1.9 KiB
C
44 lines
1.9 KiB
C
#ifndef SHADE_CHANGES_H
|
|
#define SHADE_CHANGES_H
|
|
#include <stdint.h>
|
|
#include "ModelSnapshot.h"
|
|
|
|
// What changed about a shade since the change fan-out last sent it out, as
|
|
// bits. The shade's setters and emitState() set them; once per loop() pass the
|
|
// fan-out sends one shadeState for the shade, publishes the MQTT topics whose
|
|
// bits are set, and clears them. Kept free of the shade model and MQTT so it
|
|
// can be unit tested on the PC (pio test -e native).
|
|
enum : uint16_t {
|
|
SHADE_CHANGED_POSITION = 0x0001,
|
|
SHADE_CHANGED_TILT_POSITION = 0x0002,
|
|
SHADE_CHANGED_DIRECTION = 0x0004,
|
|
SHADE_CHANGED_TILT_DIRECTION = 0x0008,
|
|
SHADE_CHANGED_TARGET = 0x0010,
|
|
SHADE_CHANGED_TILT_TARGET = 0x0020,
|
|
SHADE_CHANGED_MY_POS = 0x0040,
|
|
SHADE_CHANGED_MY_TILT_POS = 0x0080,
|
|
SHADE_CHANGED_ROLLING_CODE = 0x0100,
|
|
SHADE_CHANGED_SUN_FLAG = 0x0200,
|
|
SHADE_CHANGED_SUNNY = 0x0400,
|
|
SHADE_CHANGED_WINDY = 0x0800,
|
|
// Something only the socket's shadeState carries changed.
|
|
SHADE_CHANGED_STATE = 0x1000
|
|
};
|
|
// The bits that have an MQTT topic.
|
|
#define SHADE_CHANGED_TOPICS 0x0FFF
|
|
// The same for a group: its direction topic, and groupState for the socket.
|
|
enum : uint8_t {
|
|
GROUP_CHANGED_DIRECTION = 0x01,
|
|
GROUP_CHANGED_STATE = 0x02
|
|
};
|
|
|
|
// Publishes one MQTT topic: its name under shades/<id>/, its value and whether
|
|
// the broker keeps it.
|
|
typedef void (*topic_sink_t)(const char *topic, int32_t value, bool retain, void *ctx);
|
|
// Publishes the topics of the changed bits with the shade's values, positions
|
|
// as clients see them.
|
|
void publishShadeTopics(uint16_t changed, const shade_snapshot_t &shade, topic_sink_t sink, void *ctx);
|
|
// The topics a shade publishes in full when MQTT connects: the tilt ones only
|
|
// with a tilt, the sun ones only with a sun sensor.
|
|
uint16_t shadeStateTopics(const shade_snapshot_t &shade);
|
|
#endif
|