EnigmaIOT  0.9.8
Secure sensor and gateway platform based on ESP8266 and ESP32
haTrigger.h
Go to the documentation of this file.
1 
10 #ifndef _HA_TRIGGER_h
11 #define _HA_TRIGGER_h
12 
13 #include "haEntity.h"
14 
15 #if SUPPORT_HA_DISCOVERY
16 
82 typedef enum {
92 
93 static const char* ha_triggerTypeStr[] = {
94  "button_short_press",
95  "button_short_release",
96  "button_long_press",
97  "button_long_release",
98  "button_double_press",
99  "button_triple_press",
100  "button_quadruple_press",
101  "button_quintuple_press"
102 };
103 
104 typedef enum {
105  turn_on = 0,
106  turn_off = 1,
107  button_1 = 2,
108  button_2 = 3,
109  button_3 = 4,
110  button_4 = 5,
111  button_5 = 6,
112  button_6 = 7
114 
115 static const char* ha_triggerSubtypeStr[] = {
116  "turn_on",
117  "turn_off",
118  "button_1",
119  "button_2",
120  "button_3",
121  "button_4",
122  "button_5",
123  "button_6"
124 };
125 
126 class HATrigger : public HAEntity {
127 
128 public:
133  capacity = JSON_OBJECT_SIZE (10) + 250;
134  entityConfig = new DynamicJsonDocument (capacity);
136  (*entityConfig)[ha_device_type] = deviceType;
137  };
138 
139 
145  static const char* getTriggerTypeStr (int type) {
146  if (type >= button_short_press || type <= button_quintuple_press) {
147  return ha_triggerTypeStr[type];
148  } else {
149  return NULL;
150  }
151  }
152 
158  static const char* getTriggerSubtypeStr (int subtype) {
159  if (subtype >= turn_on || subtype <= button_6) {
160  return ha_triggerSubtypeStr[subtype];
161  } else {
162  return NULL;
163  }
164  }
165 
171  void setPayload (const char* payload);
172 
178  void setType (ha_triggerType_t type) {
179  (*entityConfig)[ha_type] = type;
180  }
181 
187  void setType (const char* type) {
188  (*entityConfig)[ha_type] = type;
189  }
190 
197  (*entityConfig)[ha_subtype] = subtype;
198  }
199 
205  void setSubtype (const char* subtype) {
206  (*entityConfig)[ha_subtype] = subtype;
207  }
208 
218  static size_t getDiscoveryJson (char* buffer, size_t buflen, const char* nodeName, const char* networkName, DynamicJsonDocument* inputJSON);
219 
220 };
221 
222 #endif // SUPPORT_HA_DISCOVERY
223 
224 #endif // _HA_TRIGGER_h
button_long_release
@ button_long_release
Definition: haTrigger.h:86
HATrigger::getTriggerSubtypeStr
static const char * getTriggerSubtypeStr(int subtype)
Returns string that correspond with trigger subtype in ha_triggerSubtype_t format https://www....
Definition: haTrigger.h:158
button_3
@ button_3
Definition: haTrigger.h:109
HATrigger::setPayload
void setPayload(const char *payload)
Optional payload to match the payload being sent over the topic https://www.home-assistant....
Definition: haTrigger.cpp:13
button_6
@ button_6
Definition: haTrigger.h:112
HAEntity::entityConfig
DynamicJsonDocument * entityConfig
JSON object to be sent to gateway.
Definition: haEntity.h:138
turn_off
@ turn_off
Definition: haTrigger.h:106
button_quintuple_press
@ button_quintuple_press
Definition: haTrigger.h:90
haEntity.h
Defines an entity for Home Assistant autodiscovery.
button_5
@ button_5
Definition: haTrigger.h:111
HATrigger::setSubtype
void setSubtype(const char *subtype)
Set trigger subtype as char string https://www.home-assistant.io/integrations/device_trigger....
Definition: haTrigger.h:205
HATrigger::setSubtype
void setSubtype(ha_triggerSubtype_t subtype)
Set trigger subtype as ha_triggerSubtype_t https://www.home-assistant.io/integrations/device_trigger....
Definition: haTrigger.h:196
ha_triggerTypeStr
static const char * ha_triggerTypeStr[]
Definition: haTrigger.h:93
ha_triggerType_t
ha_triggerType_t
Definition: haTrigger.h:82
HAEntity::capacity
size_t capacity
JSON object memory reservation length.
Definition: haEntity.h:134
button_short_release
@ button_short_release
Definition: haTrigger.h:84
button_long_press
@ button_long_press
Definition: haTrigger.h:85
button_4
@ button_4
Definition: haTrigger.h:110
button_1
@ button_1
Definition: haTrigger.h:107
ha_subtype
constexpr auto ha_subtype
Definition: haEntity.h:50
ha_triggerSubtype_t
ha_triggerSubtype_t
Definition: haTrigger.h:104
ha_device_type
constexpr auto ha_device_type
Definition: haEntity.h:23
HAEntity::deviceType
haDeviceType_t deviceType
HomeAssistant entity device type.
Definition: haEntity.h:135
button_2
@ button_2
Definition: haTrigger.h:108
ha_type
constexpr auto ha_type
Definition: haEntity.h:49
turn_on
@ turn_on
Definition: haTrigger.h:105
HATrigger::getDiscoveryJson
static size_t getDiscoveryJson(char *buffer, size_t buflen, const char *nodeName, const char *networkName, DynamicJsonDocument *inputJSON)
Allows Gateway to get Home Assistant discovery message using Trigger template.
Definition: haTrigger.cpp:39
button_short_press
@ button_short_press
Definition: haTrigger.h:83
HATrigger::setType
void setType(const char *type)
Set trigger type as char string https://www.home-assistant.io/integrations/device_trigger....
Definition: haTrigger.h:187
HATrigger
Definition: haTrigger.h:126
HATrigger::HATrigger
HATrigger()
Trigger constructor.
Definition: haTrigger.h:132
DEVICE_TRIGGER
@ DEVICE_TRIGGER
Definition: haEntity.h:60
HATrigger::getTriggerTypeStr
static const char * getTriggerTypeStr(int type)
Returns string that correspond with trigger type in ha_triggerType_t format https://www....
Definition: haTrigger.h:145
button_quadruple_press
@ button_quadruple_press
Definition: haTrigger.h:89
HAEntity
Definition: haEntity.h:132
ha_triggerSubtypeStr
static const char * ha_triggerSubtypeStr[]
Definition: haTrigger.h:115
HATrigger::setType
void setType(ha_triggerType_t type)
Set trigger type as ha_triggerType_t https://www.home-assistant.io/integrations/device_trigger....
Definition: haTrigger.h:178
button_double_press
@ button_double_press
Definition: haTrigger.h:87
button_triple_press
@ button_triple_press
Definition: haTrigger.h:88