70 void onInit()
override;
71 bool onLoadConfig()
override;
72 bool verifyConfig()
override;
73 bool isEnabled()
override;
76 bool isNetworkRestartRequested()
override;
77 uint32_t getConnectionFailTime()
override;
78 bool isConnectionError()
override;
79 bool isConnecting()
override;
80 bool isMqtt()
const override;
81 void publish(
const char *topic,
85 bool ignorePrefix =
false);
86 void publishInt(
const char *topic,
90 void publishBool(
const char *topic,
94 void publishOnOff(
const char *topic,
bool payload,
int qos,
int retain);
95 void publishOpenClosed(
const char *topic,
bool payload,
int qos,
int retain);
96 void publishDouble(
const char *topic,
101 void publishColor(
const char *topic,
107 void publishChannelState(
int channel);
108 void publishExtendedChannelState(
int channel);
109 void subscribeChannel(
int channel);
110 void unsubscribeChannel(
int channel);
111 const char *getPrefix()
const;
112 const char *getHostname()
const;
113 void subscribe(
const char *topic,
int qos = -1);
114 void unsubscribe(
const char *topic);
115 bool isUpdatePending()
override;
116 bool isRegisteredAndReady()
override;
117 void notifyConfigChange(
int channelNumber)
override;
119 void sendActionTrigger(uint8_t channelNumber, uint32_t actionId)
override;
120 void sendChannelValueChanged(uint8_t channelNumber, int8_t *value,
121 unsigned char offline, uint32_t validityTimeSec)
override;
122 void sendExtendedChannelValueChanged(uint8_t channelNumber,
125 bool processData(
const char *topic,
const char *payload);
126 void processRelayRequest(
const char *topic,
130 void processRGBWRequest(
const char *topic,
134 void processRGBRequest(
const char *topic,
138 void processDimmerRequest(
const char *topic,
142 void processRollerShutterRequest(
const char *topic,
148 void generateClientId(
char result[MQTT_CLIENTID_MAX_SIZE]);
149 void generateObjectId(
char result[30],
int channelNumber,
int subId);
150 MqttTopic getHADiscoveryTopic(
const char *sensor,
char *objectId);
151 void publishDeviceStatus(
bool onRegistration =
false);
152 void publishChannelSetup(
int channelNumber);
153 bool isChannelAvailableForHa(
const Supla::Channel *channel)
const;
154 void publishChannelAvailability(
int channelNumber,
bool force =
false);
155 void resetChannelAvailabilityCache();
159 size_t resultSize)
const;
160 void processConfigChanges();
161 void publishHADiscovery(
int channel);
166 void clearHADiscoveryRelayAlternativeTypes(
Supla::Channel *channel,
167 const char *currentType);
170 bool currentIsRoller);
185 void publishHADiscoveryEMParameter(
186 Supla::Element *element,
int parameterId,
const char *parameterName,
187 const char *units, Supla::Protocol::HAStateClass stateClass,
188 Supla::Protocol::HADeviceClass deviceClass);
189 const char *getActionTriggerType(uint8_t actionIdx);
190 bool isActionTriggerEnabled(
Supla::Channel *ch, uint8_t actionIdx);
191 virtual void publishImp(
const char *topic,
195 virtual void subscribeImp(
const char *topic,
int qos) = 0;
196 virtual void unsubscribeImp(
const char *topic) = 0;
197 const char *getStateClassStr(Supla::Protocol::HAStateClass stateClass);
198 const char *getDeviceClassStr(Supla::Protocol::HADeviceClass deviceClass);
200 const char *getRelayChannelName(
int channelFunction)
const;
201 const char *getBinarySensorChannelName(
int channelFunction)
const;
203 bool isPayloadOn(
const char *);
204 bool isOpenClosedBinarySensorFunction(
int channelFunction)
const;
210 char server[SUPLA_SERVER_NAME_MAXSIZE] = {};
212 char user[MQTT_USERNAME_MAX_SIZE] = {};
213 char password[MQTT_PASSWORD_MAX_SIZE] = {};
214 char hostname[32] = {};
218 bool retainCfg =
false;
220 bool connecting =
false;
221 bool connected =
false;
223 uint16_t prefixLen = 0;
224 uint16_t channelsCount = 0;
225 uint16_t buttonNumber = 0;
226 char *prefix =
nullptr;
233 static constexpr size_t CONFIG_CHANGED_BIT_SIZE =
234 (SUPLA_CHANNELMAXCOUNT + 7) / 8;
235 static_assert(CONFIG_CHANGED_BIT_SIZE * 8 >= SUPLA_CHANNELMAXCOUNT,
236 "MQTT config change bitset is too small");
237 uint8_t configChangedBit[CONFIG_CHANGED_BIT_SIZE] = {};
238 static constexpr size_t CHANNEL_AVAILABILITY_BIT_SIZE =
239 (SUPLA_CHANNELMAXCOUNT + 7) / 8;
240 static_assert(CHANNEL_AVAILABILITY_BIT_SIZE * 8 >= SUPLA_CHANNELMAXCOUNT,
241 "MQTT channel availability bitset is too small");
242 uint8_t channelAvailabilityKnownBit[CHANNEL_AVAILABILITY_BIT_SIZE] = {};
243 uint8_t channelAvailabilityValueBit[CHANNEL_AVAILABILITY_BIT_SIZE] = {};
244 uint8_t channelOnlineButNotAvailableBit[CHANNEL_AVAILABILITY_BIT_SIZE] = {};
245 static constexpr size_t HA_AVAILABILITY_BUFFER_SIZE = 400;
246 char haAvailability[HA_AVAILABILITY_BUFFER_SIZE] = {};