EnigmaIOT  0.9.8
Secure sensor and gateway platform based on ESP8266 and ESP32
haSwitch.h
Go to the documentation of this file.
1 
9 #ifndef _SWITCH_h
10 #define _SWITCH_h
11 
12 #include "haEntity.h"
13 
14 #if SUPPORT_HA_DISCOVERY
15 
94 class HASwitch : public HAEntity {
95 
96 public:
100  HASwitch () {
101  capacity = JSON_OBJECT_SIZE (10) + 250;
102  entityConfig = new DynamicJsonDocument (capacity);
103  deviceType = SWITCH;
104  (*entityConfig)[ha_device_type] = deviceType;
105  };
106 
112  void setPayloadOn (const char* payload);
113 
119  void setPayloadOff (const char* payload);
120 
126  void setPayloadOn (int payload);
127 
133  void setPayloadOff (int payload);
134 
140  void setStateOn (const char* payload);
141 
147  void setStateOff (const char* payload);
148 
154  void setStateOn (int payload);
155 
161  void setStateOff (int payload);
162 
168  void setValueField (const char* payload);
169 
179  static size_t getDiscoveryJson (char* buffer, size_t buflen, const char* nodeName, const char* networkName, DynamicJsonDocument* inputJSON);
180 
181 };
182 
183 #endif // SUPPORT_HA_DISCOVERY
184 
185 #endif // _SWITCH_h
HAEntity::entityConfig
DynamicJsonDocument * entityConfig
JSON object to be sent to gateway.
Definition: haEntity.h:138
SWITCH
@ SWITCH
Definition: haEntity.h:67
haEntity.h
Defines an entity for Home Assistant autodiscovery.
HAEntity::capacity
size_t capacity
JSON object memory reservation length.
Definition: haEntity.h:134
HASwitch::setStateOn
void setStateOn(const char *payload)
The payload that represents the on state. Used when value that represents on state in the state_topic...
Definition: haSwitch.cpp:34
HASwitch
Definition: haSwitch.h:94
HASwitch::setStateOff
void setStateOff(const char *payload)
The payload that represents the off state. Used when value that represents off state in the state_top...
Definition: haSwitch.cpp:40
HASwitch::setPayloadOff
void setPayloadOff(const char *payload)
The payload that represents off state. If specified, will be used for both comparing to the value in ...
Definition: haSwitch.cpp:20
HASwitch::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 Switch template.
Definition: haSwitch.cpp:85
HASwitch::HASwitch
HASwitch()
Switch constructor.
Definition: haSwitch.h:100
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
HASwitch::setPayloadOn
void setPayloadOn(const char *payload)
The payload that represents on state. If specified, will be used for both comparing to the value in t...
Definition: haSwitch.cpp:14
HASwitch::setValueField
void setValueField(const char *payload)
Defines a json key to extract device’s state from the state_topic. To determine the switches’s state ...
Definition: haSwitch.cpp:54
HAEntity
Definition: haEntity.h:132