mirror of
https://github.com/alexhopeoconnor/arduino-home-assistant.git
synced 2026-10-04 02:48:13 +10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a7039fad81 | ||
|
|
77321da999 | ||
|
|
9c9d074711 | ||
|
|
a1f286a80d | ||
|
|
21fd745a7a | ||
|
|
471b9c6fb0 | ||
|
|
f081272fcf | ||
|
|
470ec878d6 | ||
|
|
586bf3fe1d | ||
|
|
4755081296 | ||
|
|
1f41c47f64 | ||
|
|
105d9bd078 | ||
|
|
67ff1c84b8 | ||
|
|
51e28f2c93 |
+19
-1
@@ -1,3 +1,21 @@
|
||||
# General
|
||||
docsrc/xml
|
||||
docsrc/build
|
||||
.DS_Store
|
||||
|
||||
# MacOS
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# C++ objects and libs
|
||||
*.slo
|
||||
*.lo
|
||||
*.o
|
||||
*.a
|
||||
*.la
|
||||
*.lai
|
||||
*.so
|
||||
*.so.*
|
||||
*.dll
|
||||
*.dylib
|
||||
*.out
|
||||
@@ -1,5 +1,10 @@
|
||||
# Changelog
|
||||
|
||||
## 2.2.0
|
||||
|
||||
* Added support for std::function in all callbacks [#281](https://github.com/dawidchyrzynski/arduino-home-assistant/pull/281)
|
||||
* Fixed a crash caused by a missing device ID [#284](https://github.com/dawidchyrzynski/arduino-home-assistant/issues/284)
|
||||
|
||||
## 2.1.0
|
||||
|
||||
**New features:**
|
||||
|
||||
@@ -79,6 +79,7 @@ void setup() {
|
||||
device.setSoftwareVersion("1.0.0");
|
||||
|
||||
// assign callbacks (optional)
|
||||
// alternatively you can use std::bind or lambda functions
|
||||
hvac.onTargetTemperatureCommand(onTargetTemperatureCommand);
|
||||
hvac.onPowerCommand(onPowerCommand);
|
||||
hvac.onModeCommand(onModeCommand);
|
||||
|
||||
@@ -54,7 +54,7 @@ void setup() {
|
||||
device.setSoftwareVersion("1.0.0");
|
||||
|
||||
// handle switch state
|
||||
led.onCommand(onSwitchCommand);
|
||||
led.onCommand(onSwitchCommand); // alternatively you can use std::bind or lambda functions
|
||||
led.setName("My LED"); // optional
|
||||
|
||||
mqtt.begin(BROKER_ADDR);
|
||||
|
||||
@@ -42,6 +42,7 @@ void setup() {
|
||||
Serial.begin(9600);
|
||||
Ethernet.begin(mac);
|
||||
|
||||
// alternativelly you can use std::bind or lambda functions (only on platforms with std::function support)
|
||||
mqtt.onMessage(onMqttMessage);
|
||||
mqtt.onConnected(onMqttConnected);
|
||||
mqtt.onDisconnected(onMqttDisconnected);
|
||||
|
||||
@@ -45,7 +45,7 @@ void setup() {
|
||||
device.setSoftwareVersion("1.0.0");
|
||||
|
||||
// handle switch state
|
||||
led.onCommand(onSwitchCommand);
|
||||
led.onCommand(onSwitchCommand); // alternatively you can use std::bind or lambda function
|
||||
led.setName("My LED"); // optional
|
||||
|
||||
mqtt.begin(BROKER_ADDR);
|
||||
|
||||
@@ -34,7 +34,7 @@ void loop() {
|
||||
mqtt.loop();
|
||||
|
||||
if ((millis() - lastUpdateAt) > 2000) { // update in 2s interval
|
||||
unsigned long uptimeValue = millis() / 1000;
|
||||
uint32_t uptimeValue = millis() / 1000;
|
||||
uptimeSensor.setValue(uptimeValue);
|
||||
lastUpdateAt = millis();
|
||||
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
name=home-assistant-integration
|
||||
version=2.1.0
|
||||
version=2.2.0
|
||||
author=Dawid Chyrzynski <dev@chyrzynski.pl>
|
||||
maintainer=Dawid Chyrzynski <dev@chyrzynski.pl>
|
||||
sentence=Home Assistant MQTT integration for Arduino
|
||||
|
||||
@@ -33,10 +33,17 @@
|
||||
#define ARDUINOHA_DEBUG_PRINT(x)
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(__SAMD21G18A__) or defined(__SAM3X8E__)
|
||||
#define ARDUINOHA_INT_OVERLOAD
|
||||
#endif
|
||||
|
||||
#if __cplusplus >= 201103L and !defined(__AVR__)
|
||||
#define ARDUINOHA_USE_STD_FUNCTION
|
||||
#endif
|
||||
|
||||
#if defined(ARDUINOHA_USE_STD_FUNCTION)
|
||||
#include <functional>
|
||||
#endif
|
||||
|
||||
#define AHATOFSTR(x) reinterpret_cast<const __FlashStringHelper*>(x)
|
||||
#define AHAFROMFSTR(x) reinterpret_cast<const char*>(x)
|
||||
|
||||
+9
-1
@@ -22,6 +22,7 @@ public:
|
||||
/**
|
||||
* Constructs HADevice with the given unique ID (string).
|
||||
* Keep the unique ID short to save the memory.
|
||||
* The given string must be static or const and cannot live on the stack.
|
||||
*
|
||||
* @param uniqueId String with the null terminator.
|
||||
*/
|
||||
@@ -30,6 +31,7 @@ public:
|
||||
/**
|
||||
* Constructs HADevice using the given byte array as the unique ID.
|
||||
* It works in the same way as HADevice::setUniqueId method.
|
||||
* The given string is copied internally and can be freed after the constructor returns.
|
||||
*
|
||||
* @param uniqueId Bytes array that's going to be converted into the string.
|
||||
* @param length Number of bytes in the array.
|
||||
@@ -88,7 +90,8 @@ public:
|
||||
|
||||
/**
|
||||
* Sets unique ID of the device based on the given byte array.
|
||||
* Each byte is converted into a hex string representation, so the final length of the unique ID will be twice as given.
|
||||
* Each byte is converted to its hexadecimal string representation, so the final length of the unique ID will be twice the original number of bytes.
|
||||
* The given string is copied internally and can be freed after the method returns.
|
||||
*
|
||||
* @param uniqueId Bytes array that's going to be converted into the string.
|
||||
* @param length Number of bytes in the array.
|
||||
@@ -98,6 +101,7 @@ public:
|
||||
|
||||
/**
|
||||
* Sets the "manufacturer" property that's going to be displayed in the Home Assistant.
|
||||
* The given string must be static or const and cannot live on the stack.
|
||||
*
|
||||
* @param manufacturer Any string. Keep it short to save the memory.
|
||||
*/
|
||||
@@ -105,6 +109,7 @@ public:
|
||||
|
||||
/**
|
||||
* Sets the "model" property that's going to be displayed in the Home Assistant.
|
||||
* The given string must be static or const and cannot live on the stack.
|
||||
*
|
||||
* @param model Any string. Keep it short to save the memory.
|
||||
*/
|
||||
@@ -112,6 +117,7 @@ public:
|
||||
|
||||
/**
|
||||
* Sets the "name" property that's going to be displayed in the Home Assistant.
|
||||
* The given string must be static or const and cannot live on the stack.
|
||||
*
|
||||
* @param name Any string. Keep it short to save the memory.
|
||||
*/
|
||||
@@ -119,6 +125,7 @@ public:
|
||||
|
||||
/**
|
||||
* Sets the "software version" property that's going to be displayed in the Home Assistant.
|
||||
* The given string must be static or const and cannot live on the stack.
|
||||
*
|
||||
* @param softwareVersion Any string. Keep it short to save the memory.
|
||||
*/
|
||||
@@ -126,6 +133,7 @@ public:
|
||||
|
||||
/**
|
||||
* Sets the "configuration URL" property that's going to be used by the Home Assistant.
|
||||
* The given string must be static or const and cannot live on the stack.
|
||||
*
|
||||
* @param url Configuration URL to publish.
|
||||
*/
|
||||
|
||||
+19
-12
@@ -6,28 +6,35 @@
|
||||
#include <IPAddress.h>
|
||||
#include "ArduinoHADefines.h"
|
||||
|
||||
#define HAMQTT_CALLBACK(name) void (*name)()
|
||||
#define HAMQTT_STATE_CALLBACK(name) void (*name)(ConnectionState state)
|
||||
#define HAMQTT_MESSAGE_CALLBACK(name) void (*name)(const char* topic, const uint8_t* payload, uint16_t length)
|
||||
#if defined(ARDUINOHA_USE_STD_FUNCTION)
|
||||
#define HAMQTT_CALLBACK(name) std::function<void()> name
|
||||
#define HAMQTT_STATE_CALLBACK(name) std::function<void(ConnectionState state)> name
|
||||
#define HAMQTT_MESSAGE_CALLBACK(name) std::function<void(const char* topic, const uint8_t* payload, uint16_t length)> name
|
||||
#else
|
||||
#define HAMQTT_CALLBACK(name) void (*name)()
|
||||
#define HAMQTT_STATE_CALLBACK(name) void (*name)(ConnectionState state)
|
||||
#define HAMQTT_MESSAGE_CALLBACK(name) void (*name)(const char* topic, const uint8_t* payload, uint16_t length)
|
||||
#endif
|
||||
|
||||
#define HAMQTT_DEFAULT_PORT 1883
|
||||
|
||||
#ifdef ARDUINOHA_TEST
|
||||
class PubSubClientMock;
|
||||
class PubSubClientMock;
|
||||
#else
|
||||
class PubSubClient;
|
||||
class PubSubClient;
|
||||
#endif
|
||||
|
||||
#if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__)
|
||||
#define HAMQTT_DEFAULT_DEVICES_LIMIT 6
|
||||
#define HAMQTT_DEFAULT_DEVICES_LIMIT 6
|
||||
#else
|
||||
#define HAMQTT_DEFAULT_DEVICES_LIMIT 24
|
||||
#define HAMQTT_DEFAULT_DEVICES_LIMIT 24
|
||||
#endif
|
||||
|
||||
class HADevice;
|
||||
class HABaseDeviceType;
|
||||
|
||||
#if defined(ARDUINO_API_VERSION)
|
||||
using namespace arduino;
|
||||
using namespace arduino;
|
||||
#endif
|
||||
|
||||
/**
|
||||
@@ -129,7 +136,7 @@ public:
|
||||
* Please note that the callback is also fired by internal MQTT messages used by the library.
|
||||
* You should always verify the topic of the received message.
|
||||
*
|
||||
* @param callback Callback method.
|
||||
* @param callback Pointer to a function or std::bind or lambda function.
|
||||
*/
|
||||
inline void onMessage(HAMQTT_MESSAGE_CALLBACK(callback))
|
||||
{ _messageCallback = callback; }
|
||||
@@ -139,7 +146,7 @@ public:
|
||||
* The callback is also fired after reconnecting to the broker.
|
||||
* You can use this method to register topics' subscriptions.
|
||||
*
|
||||
* @param callback Callback method.
|
||||
* @param callback Pointer to a function or std::bind or lambda function.
|
||||
*/
|
||||
inline void onConnected(HAMQTT_CALLBACK(callback))
|
||||
{ _connectedCallback = callback; }
|
||||
@@ -147,7 +154,7 @@ public:
|
||||
/**
|
||||
* Registers a new callback method that will be called each time the connection to the MQTT broker is lost.
|
||||
*
|
||||
* @param callback Callback method.
|
||||
* @param callback Pointer to a function or std::bind or lambda function.
|
||||
*/
|
||||
inline void onDisconnected(HAMQTT_CALLBACK(callback))
|
||||
{ _disconnectedCallback = callback; }
|
||||
@@ -155,7 +162,7 @@ public:
|
||||
/**
|
||||
* Registers a new callback method that will be called each time the connection state changes.
|
||||
*
|
||||
* @param callback Callback method.
|
||||
* @param callback Pointer to a function or std::bind or lambda function.
|
||||
*/
|
||||
inline void onStateChanged(HAMQTT_STATE_CALLBACK(callback))
|
||||
{ _stateChangedCallback = callback; }
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
|
||||
HABinarySensor::HABinarySensor(const char* uniqueId) :
|
||||
HABaseDeviceType(AHATOFSTR(HAComponentBinarySensor), uniqueId),
|
||||
_class(nullptr),
|
||||
_deviceClass(nullptr),
|
||||
_stateClass(nullptr),
|
||||
_icon(nullptr),
|
||||
_currentState(false)
|
||||
{
|
||||
@@ -42,11 +43,12 @@ void HABinarySensor::buildSerializer()
|
||||
return;
|
||||
}
|
||||
|
||||
_serializer = new HASerializer(this, 9); // 9 - max properties nb
|
||||
_serializer = new HASerializer(this, 10); // 10 - max properties nb
|
||||
_serializer->set(AHATOFSTR(HANameProperty), _name);
|
||||
_serializer->set(AHATOFSTR(HAObjectIdProperty), _objectId);
|
||||
_serializer->set(HASerializer::WithUniqueId);
|
||||
_serializer->set(AHATOFSTR(HADeviceClassProperty), _class);
|
||||
_serializer->set(AHATOFSTR(HADeviceClassProperty), _deviceClass);
|
||||
_serializer->set(AHATOFSTR(HAStateClassProperty), _stateClass);
|
||||
_serializer->set(AHATOFSTR(HAIconProperty), _icon);
|
||||
|
||||
if (_expireAfter.isSet()) {
|
||||
|
||||
@@ -61,7 +61,17 @@ public:
|
||||
* @param deviceClass The class name.
|
||||
*/
|
||||
inline void setDeviceClass(const char* deviceClass)
|
||||
{ _class = deviceClass; }
|
||||
{ _deviceClass = deviceClass; }
|
||||
|
||||
/**
|
||||
* Sets class of the state for the long term stats.
|
||||
* You can find list of available values here: https://developers.home-assistant.io/docs/core/entity/sensor/#available-state-classes
|
||||
* See: https://developers.home-assistant.io/docs/core/entity/sensor/#long-term-statistics
|
||||
*
|
||||
* @param stateClass The state class name.
|
||||
*/
|
||||
inline void setStateClass(const char* stateClass)
|
||||
{ _stateClass = stateClass; }
|
||||
|
||||
/**
|
||||
* Sets icon of the sensor.
|
||||
@@ -86,7 +96,10 @@ private:
|
||||
bool publishState(bool state);
|
||||
|
||||
/// The device class. It can be nullptr.
|
||||
const char* _class;
|
||||
const char* _deviceClass;
|
||||
|
||||
/// The state class. It can be nullptr.
|
||||
const char* _stateClass;
|
||||
|
||||
/// The icon of the sensor. It can be nullptr.
|
||||
const char* _icon;
|
||||
|
||||
@@ -5,7 +5,11 @@
|
||||
|
||||
#ifndef EX_ARDUINOHA_BUTTON
|
||||
|
||||
#define HABUTTON_CALLBACK(name) void (*name)(HAButton* sender)
|
||||
#if defined(ARDUINOHA_USE_STD_FUNCTION)
|
||||
#define HABUTTON_CALLBACK(name) std::function<void(HAButton* sender)> name
|
||||
#else
|
||||
#define HABUTTON_CALLBACK(name) void (*name)(HAButton* sender)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* HAButton represents a button that's displayed in the Home Assistant panel and
|
||||
@@ -51,10 +55,10 @@ public:
|
||||
{ _retain = retain; }
|
||||
|
||||
/**
|
||||
* Registers callback that will be called each time the press command from HA is received.
|
||||
* Registers a callback that will be called each time the press command from HA is received.
|
||||
* Please note that it's not possible to register multiple callbacks for the same button.
|
||||
*
|
||||
* @param callback
|
||||
* @param callback Pointer to a function or std::bind or lambda function.
|
||||
*/
|
||||
inline void onCommand(HABUTTON_CALLBACK(callback))
|
||||
{ _commandCallback = callback; }
|
||||
|
||||
@@ -5,7 +5,11 @@
|
||||
|
||||
#ifndef EX_ARDUINOHA_COVER
|
||||
|
||||
#define HACOVER_CALLBACK(name) void (*name)(CoverCommand cmd, HACover* sender)
|
||||
#if defined(ARDUINOHA_USE_STD_FUNCTION)
|
||||
#define HACOVER_CALLBACK(name) std::function<void(CoverCommand cmd, HACover* sender)> name
|
||||
#else
|
||||
#define HACOVER_CALLBACK(name) void (*name)(CoverCommand cmd, HACover* sender)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* HACover allows to control a cover (such as blinds, a roller shutter or a garage door).
|
||||
@@ -142,7 +146,7 @@ public:
|
||||
* Registers callback that will be called each time the command from HA is received.
|
||||
* Please note that it's not possible to register multiple callbacks for the same cover.
|
||||
*
|
||||
* @param callback
|
||||
* @param callback Pointer to a function or std::bind or lambda function.
|
||||
*/
|
||||
inline void onCommand(HACOVER_CALLBACK(callback))
|
||||
{ _commandCallback = callback; }
|
||||
|
||||
@@ -6,8 +6,13 @@
|
||||
|
||||
#ifndef EX_ARDUINOHA_FAN
|
||||
|
||||
#define HAFAN_STATE_CALLBACK(name) void (*name)(bool state, HAFan* sender)
|
||||
#define HAFAN_SPEED_CALLBACK(name) void (*name)(uint16_t speed, HAFan* sender)
|
||||
#if defined(ARDUINOHA_USE_STD_FUNCTION)
|
||||
#define HAFAN_STATE_CALLBACK(name) std::function<void(bool state, HAFan* sender)> name
|
||||
#define HAFAN_SPEED_CALLBACK(name) std::function<void(uint16_t speed, HAFan* sender)> name
|
||||
#else
|
||||
#define HAFAN_STATE_CALLBACK(name) void (*name)(bool state, HAFan* sender)
|
||||
#define HAFAN_SPEED_CALLBACK(name) void (*name)(uint16_t speed, HAFan* sender)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* HAFan allows adding a controllable fan in the Home Assistant panel.
|
||||
@@ -152,7 +157,7 @@ public:
|
||||
* Registers callback that will be called each time the state command from HA is received.
|
||||
* Please note that it's not possible to register multiple callbacks for the same fan.
|
||||
*
|
||||
* @param callback
|
||||
* @param callback Pointer to a function or std::bind or lambda function.
|
||||
* @note In non-optimistic mode, the state must be reported back to HA using the HAFan::setState method.
|
||||
*/
|
||||
inline void onStateCommand(HAFAN_STATE_CALLBACK(callback))
|
||||
@@ -162,7 +167,7 @@ public:
|
||||
* Registers callback that will be called each time the speed command from HA is received.
|
||||
* Please note that it's not possible to register multiple callbacks for the same fan.
|
||||
*
|
||||
* @param callback
|
||||
* @param callback Pointer to a function or std::bind or lambda function.
|
||||
* @note In non-optimistic mode, the speed must be reported back to HA using the HAFan::setSpeed method.
|
||||
*/
|
||||
inline void onSpeedCommand(HAFAN_SPEED_CALLBACK(callback))
|
||||
|
||||
+19
-11
@@ -26,11 +26,19 @@
|
||||
inline void setCurrentTargetTemperature(const type temperature) \
|
||||
{ setCurrentTargetTemperature(HANumeric(temperature, _precision)); }
|
||||
|
||||
#define HAHVAC_CALLBACK_BOOL(name) void (*name)(bool state, HAHVAC* sender)
|
||||
#define HAHVAC_CALLBACK_TARGET_TEMP(name) void (*name)(HANumeric temperature, HAHVAC* sender)
|
||||
#define HAHVAC_CALLBACK_FAN_MODE(name) void (*name)(FanMode mode, HAHVAC* sender)
|
||||
#define HAHVAC_CALLBACK_SWING_MODE(name) void (*name)(SwingMode mode, HAHVAC* sender)
|
||||
#define HAHVAC_CALLBACK_MODE(name) void (*name)(Mode mode, HAHVAC* sender)
|
||||
#if defined(ARDUINOHA_USE_STD_FUNCTION)
|
||||
#define HAHVAC_CALLBACK_BOOL(name) std::function<void(bool state, HAHVAC* sender)> name
|
||||
#define HAHVAC_CALLBACK_TARGET_TEMP(name) std::function<void(HANumeric temperature, HAHVAC* sender)> name
|
||||
#define HAHVAC_CALLBACK_FAN_MODE(name) std::function<void(FanMode mode, HAHVAC* sender)> name
|
||||
#define HAHVAC_CALLBACK_SWING_MODE(name) std::function<void(SwingMode mode, HAHVAC* sender)> name
|
||||
#define HAHVAC_CALLBACK_MODE(name) std::function<void(Mode mode, HAHVAC* sender)> name
|
||||
#else
|
||||
#define HAHVAC_CALLBACK_BOOL(name) void (*name)(bool state, HAHVAC* sender)
|
||||
#define HAHVAC_CALLBACK_TARGET_TEMP(name) void (*name)(HANumeric temperature, HAHVAC* sender)
|
||||
#define HAHVAC_CALLBACK_FAN_MODE(name) void (*name)(FanMode mode, HAHVAC* sender)
|
||||
#define HAHVAC_CALLBACK_SWING_MODE(name) void (*name)(SwingMode mode, HAHVAC* sender)
|
||||
#define HAHVAC_CALLBACK_MODE(name) void (*name)(Mode mode, HAHVAC* sender)
|
||||
#endif
|
||||
|
||||
class HASerializerArray;
|
||||
|
||||
@@ -443,7 +451,7 @@ public:
|
||||
* Registers callback that will be called each time the aux state command from HA is received.
|
||||
* Please note that it's not possible to register multiple callbacks for the same HVAC.
|
||||
*
|
||||
* @param callback
|
||||
* @param callback Pointer to a function or std::bind or lambda function.
|
||||
* @note The aux state must be reported back to HA using the HAHVAC::setAuxState method.
|
||||
*/
|
||||
inline void onAuxStateCommand(HAHVAC_CALLBACK_BOOL(callback))
|
||||
@@ -453,7 +461,7 @@ public:
|
||||
* Registers callback that will be called each time the power command from HA is received.
|
||||
* Please note that it's not possible to register multiple callbacks for the same HVAC.
|
||||
*
|
||||
* @param callback
|
||||
* @param callback Pointer to a function or std::bind or lambda function.
|
||||
*/
|
||||
inline void onPowerCommand(HAHVAC_CALLBACK_BOOL(callback))
|
||||
{ _powerCallback = callback; }
|
||||
@@ -462,7 +470,7 @@ public:
|
||||
* Registers callback that will be called each time the fan mode command from HA is received.
|
||||
* Please note that it's not possible to register multiple callbacks for the same HVAC.
|
||||
*
|
||||
* @param callback
|
||||
* @param callback Pointer to a function or std::bind or lambda function.
|
||||
* @note The fan mode must be reported back to HA using the HAHVAC::setFanMode method.
|
||||
*/
|
||||
inline void onFanModeCommand(HAHVAC_CALLBACK_FAN_MODE(callback))
|
||||
@@ -472,7 +480,7 @@ public:
|
||||
* Registers callback that will be called each time the swing mode command from HA is received.
|
||||
* Please note that it's not possible to register multiple callbacks for the same HVAC.
|
||||
*
|
||||
* @param callback
|
||||
* @param callback Pointer to a function or std::bind or lambda function.
|
||||
* @note The swing mode must be reported back to HA using the HAHVAC::setSwingMode method.
|
||||
*/
|
||||
inline void onSwingModeCommand(HAHVAC_CALLBACK_SWING_MODE(callback))
|
||||
@@ -482,7 +490,7 @@ public:
|
||||
* Registers callback that will be called each time the HVAC mode command from HA is received.
|
||||
* Please note that it's not possible to register multiple callbacks for the same HVAC.
|
||||
*
|
||||
* @param callback
|
||||
* @param callback Pointer to a function or std::bind or lambda function.
|
||||
* @note The mode must be reported back to HA using the HAHVAC::setMode method.
|
||||
*/
|
||||
inline void onModeCommand(HAHVAC_CALLBACK_MODE(callback))
|
||||
@@ -492,7 +500,7 @@ public:
|
||||
* Registers callback that will be called each time the target temperature is set via HA panel.
|
||||
* Please note that it's not possible to register multiple callbacks for the same HVAC.
|
||||
*
|
||||
* @param callback
|
||||
* @param callback Pointer to a function or std::bind or lambda function.
|
||||
* @note The target temperature must be reported back to HA using the HAHVAC::setTargetTemperature method.
|
||||
*/
|
||||
inline void onTargetTemperatureCommand(HAHVAC_CALLBACK_TARGET_TEMP(callback))
|
||||
|
||||
@@ -6,10 +6,17 @@
|
||||
|
||||
#ifndef EX_ARDUINOHA_LIGHT
|
||||
|
||||
#define HALIGHT_STATE_CALLBACK(name) void (*name)(bool state, HALight* sender)
|
||||
#define HALIGHT_BRIGHTNESS_CALLBACK(name) void (*name)(uint8_t brightness, HALight* sender)
|
||||
#define HALIGHT_COLOR_TEMP_CALLBACK(name) void (*name)(uint16_t temperature, HALight* sender)
|
||||
#define HALIGHT_RGB_COLOR_CALLBACK(name) void (*name)(HALight::RGBColor color, HALight* sender)
|
||||
#if defined(ARDUINOHA_USE_STD_FUNCTION)
|
||||
#define HALIGHT_STATE_CALLBACK(name) std::function<void(bool state, HALight* sender)> name
|
||||
#define HALIGHT_BRIGHTNESS_CALLBACK(name) std::function<void(uint8_t brightness, HALight* sender)> name
|
||||
#define HALIGHT_COLOR_TEMP_CALLBACK(name) std::function<void(uint16_t temperature, HALight* sender)> name
|
||||
#define HALIGHT_RGB_COLOR_CALLBACK(name) std::function<void(HALight::RGBColor color, HALight* sender)> name
|
||||
#else
|
||||
#define HALIGHT_STATE_CALLBACK(name) void (*name)(bool state, HALight* sender)
|
||||
#define HALIGHT_BRIGHTNESS_CALLBACK(name) void (*name)(uint8_t brightness, HALight* sender)
|
||||
#define HALIGHT_COLOR_TEMP_CALLBACK(name) void (*name)(uint16_t temperature, HALight* sender)
|
||||
#define HALIGHT_RGB_COLOR_CALLBACK(name) void (*name)(HALight::RGBColor color, HALight* sender)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* HALight allows adding a controllable light in the Home Assistant panel.
|
||||
@@ -261,7 +268,7 @@ public:
|
||||
* Registers callback that will be called each time the state command from HA is received.
|
||||
* Please note that it's not possible to register multiple callbacks for the same light.
|
||||
*
|
||||
* @param callback
|
||||
* @param callback Pointer to a function or std::bind or lambda function.
|
||||
* @note In non-optimistic mode, the state must be reported back to HA using the HALight::setState method.
|
||||
*/
|
||||
inline void onStateCommand(HALIGHT_STATE_CALLBACK(callback))
|
||||
@@ -271,7 +278,7 @@ public:
|
||||
* Registers callback that will be called each time the brightness command from HA is received.
|
||||
* Please note that it's not possible to register multiple callbacks for the same light.
|
||||
*
|
||||
* @param callback
|
||||
* @param callback Pointer to a function or std::bind or lambda function.
|
||||
* @note In non-optimistic mode, the brightness must be reported back to HA using the HALight::setBrightness method.
|
||||
*/
|
||||
inline void onBrightnessCommand(HALIGHT_BRIGHTNESS_CALLBACK(callback))
|
||||
@@ -281,7 +288,7 @@ public:
|
||||
* Registers callback that will be called each time the color temperature command from HA is received.
|
||||
* Please note that it's not possible to register multiple callbacks for the same light.
|
||||
*
|
||||
* @param callback
|
||||
* @param callback Pointer to a function or std::bind or lambda function.
|
||||
* @note In non-optimistic mode, the color temperature must be reported back to HA using the HALight::setColorTemperature method.
|
||||
*/
|
||||
inline void onColorTemperatureCommand(HALIGHT_COLOR_TEMP_CALLBACK(callback))
|
||||
@@ -291,7 +298,7 @@ public:
|
||||
* Registers callback that will be called each time the RGB color command from HA is received.
|
||||
* Please note that it's not possible to register multiple callbacks for the same light.
|
||||
*
|
||||
* @param callback
|
||||
* @param callback Pointer to a function or std::bind or lambda function.
|
||||
* @note In non-optimistic mode, the color must be reported back to HA using the HALight::setRGBColor method.
|
||||
*/
|
||||
inline void onRGBColorCommand(HALIGHT_RGB_COLOR_CALLBACK(callback))
|
||||
|
||||
@@ -5,7 +5,11 @@
|
||||
|
||||
#ifndef EX_ARDUINOHA_LOCK
|
||||
|
||||
#define HALOCK_CALLBACK(name) void (*name)(LockCommand command, HALock* sender)
|
||||
#if defined(ARDUINOHA_USE_STD_FUNCTION)
|
||||
#define HALOCK_CALLBACK(name) std::function<void(LockCommand command, HALock* sender)> name
|
||||
#else
|
||||
#define HALOCK_CALLBACK(name) void (*name)(LockCommand command, HALock* sender)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* HALock allows to implement a custom lock (for example: door lock)
|
||||
@@ -97,7 +101,7 @@ public:
|
||||
* Registers callback that will be called each time the lock/unlock/open command from the HA is received.
|
||||
* Please note that it's not possible to register multiple callbacks for the same lock.
|
||||
*
|
||||
* @param callback
|
||||
* @param callback Pointer to a function or std::bind or lambda function.
|
||||
*/
|
||||
inline void onCommand(HALOCK_CALLBACK(callback))
|
||||
{ _commandCallback = callback; }
|
||||
|
||||
@@ -16,7 +16,11 @@
|
||||
inline void setCurrentState(const type state) \
|
||||
{ setCurrentState(HANumeric(state, _precision)); }
|
||||
|
||||
#define HANUMBER_CALLBACK(name) void (*name)(HANumeric number, HANumber* sender)
|
||||
#if defined(ARDUINOHA_USE_STD_FUNCTION)
|
||||
#define HANUMBER_CALLBACK(name) std::function<void(HANumeric number, HANumber* sender)> name
|
||||
#else
|
||||
#define HANUMBER_CALLBACK(name) void (*name)(HANumeric number, HANumber* sender)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* HANumber adds a slider or a box in the Home Assistant panel
|
||||
@@ -180,7 +184,7 @@ public:
|
||||
* Registers callback that will be called each time the number is changed in the HA panel.
|
||||
* Please note that it's not possible to register multiple callbacks for the same number.
|
||||
*
|
||||
* @param callback
|
||||
* @param callback Pointer to a function or std::bind or lambda function.
|
||||
* @note In non-optimistic mode, the number must be reported back to HA using the HANumber::setState method.
|
||||
*/
|
||||
inline void onCommand(HANUMBER_CALLBACK(callback))
|
||||
|
||||
@@ -5,7 +5,11 @@
|
||||
|
||||
#ifndef EX_ARDUINOHA_SCENE
|
||||
|
||||
#define HASCENE_CALLBACK(name) void (*name)(HAScene* sender)
|
||||
#if defined(ARDUINOHA_USE_STD_FUNCTION)
|
||||
#define HASCENE_CALLBACK(name) std::function<void(HAScene* sender)> name
|
||||
#else
|
||||
#define HASCENE_CALLBACK(name) void (*name)(HAScene* sender)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* HAScene adds a new scene to the Home Assistant that triggers your callback once activated.
|
||||
@@ -44,7 +48,7 @@ public:
|
||||
* Registers callback that will be called when the scene is activated in the HA panel.
|
||||
* Please note that it's not possible to register multiple callbacks for the same scene.
|
||||
*
|
||||
* @param callback
|
||||
* @param callback Pointer to a function or std::bind or lambda function.
|
||||
*/
|
||||
inline void onCommand(HASCENE_CALLBACK(callback))
|
||||
{ _commandCallback = callback; }
|
||||
|
||||
@@ -7,7 +7,11 @@
|
||||
|
||||
class HASerializerArray;
|
||||
|
||||
#define HASELECT_CALLBACK(name) void (*name)(int8_t index, HASelect* sender)
|
||||
#if defined(ARDUINOHA_USE_STD_FUNCTION)
|
||||
#define HASELECT_CALLBACK(name) std::function<void(int8_t index, HASelect* sender)> name
|
||||
#else
|
||||
#define HASELECT_CALLBACK(name) void (*name)(int8_t index, HASelect* sender)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* HASelect adds a dropdown with options in the Home Assistant panel.
|
||||
@@ -105,7 +109,7 @@ public:
|
||||
* Registers callback that will be called each time the option is changed from the HA panel.
|
||||
* Please note that it's not possible to register multiple callbacks for the same select.
|
||||
*
|
||||
* @param callback
|
||||
* @param callback Pointer to a function or std::bind or lambda function.
|
||||
* @note In non-optimistic mode, the selected option must be reported back to HA using the HASelect::setState method.
|
||||
*/
|
||||
inline void onCommand(HASELECT_CALLBACK(callback))
|
||||
|
||||
@@ -66,9 +66,10 @@ public:
|
||||
|
||||
/**
|
||||
* Sets class of the state for the long term stats.
|
||||
* You can find list of available values here: https://developers.home-assistant.io/docs/core/entity/sensor/#available-state-classes
|
||||
* See: https://developers.home-assistant.io/docs/core/entity/sensor/#long-term-statistics
|
||||
*
|
||||
* @param stateClass The class name.
|
||||
* @param stateClass The state class name.
|
||||
*/
|
||||
inline void setStateClass(const char* stateClass)
|
||||
{ _stateClass = stateClass; }
|
||||
|
||||
@@ -5,7 +5,11 @@
|
||||
|
||||
#ifndef EX_ARDUINOHA_SWITCH
|
||||
|
||||
#define HASWITCH_CALLBACK(name) void (*name)(bool state, HASwitch* sender)
|
||||
#if defined(ARDUINOHA_USE_STD_FUNCTION)
|
||||
#define HASWITCH_CALLBACK(name) std::function<void(bool state, HASwitch* sender)> name
|
||||
#else
|
||||
#define HASWITCH_CALLBACK(name) void (*name)(bool state, HASwitch* sender)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* HASwitch allows to display on/off switch in the HA panel and receive commands on your device.
|
||||
@@ -103,7 +107,7 @@ public:
|
||||
* Registers callback that will be called each time the on/off command from HA is received.
|
||||
* Please note that it's not possible to register multiple callbacks for the same switch.
|
||||
*
|
||||
* @param callback
|
||||
* @param callback Pointer to a function or std::bind or lambda function.
|
||||
* @note In non-optimistic mode, the state must be reported back to HA using the HASwitch::setState method.
|
||||
*/
|
||||
inline void onCommand(HASWITCH_CALLBACK(callback))
|
||||
|
||||
@@ -24,7 +24,8 @@ uint16_t HASerializer::calculateConfigTopicLength(
|
||||
!objectId ||
|
||||
!mqtt ||
|
||||
!mqtt->getDiscoveryPrefix() ||
|
||||
!mqtt->getDevice()
|
||||
!mqtt->getDevice() ||
|
||||
!mqtt->getDevice()->getUniqueId()
|
||||
) {
|
||||
return 0;
|
||||
}
|
||||
@@ -50,7 +51,8 @@ bool HASerializer::generateConfigTopic(
|
||||
!objectId ||
|
||||
!mqtt ||
|
||||
!mqtt->getDiscoveryPrefix() ||
|
||||
!mqtt->getDevice()
|
||||
!mqtt->getDevice() ||
|
||||
!mqtt->getDevice()->getUniqueId()
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
@@ -81,7 +83,8 @@ uint16_t HASerializer::calculateDataTopicLength(
|
||||
!topic ||
|
||||
!mqtt ||
|
||||
!mqtt->getDataPrefix() ||
|
||||
!mqtt->getDevice()
|
||||
!mqtt->getDevice() ||
|
||||
!mqtt->getDevice()->getUniqueId()
|
||||
) {
|
||||
return 0;
|
||||
}
|
||||
@@ -110,7 +113,8 @@ bool HASerializer::generateDataTopic(
|
||||
!topic ||
|
||||
!mqtt ||
|
||||
!mqtt->getDataPrefix() ||
|
||||
!mqtt->getDevice()
|
||||
!mqtt->getDevice() ||
|
||||
!mqtt->getDevice()->getUniqueId()
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -38,6 +38,14 @@ void onCommandReceived(HAButton* caller)
|
||||
lastPressCallbackCall.caller = caller;
|
||||
}
|
||||
|
||||
class CallbacksProcessor {
|
||||
public:
|
||||
void onCommand(HAButton* caller) {
|
||||
lastPressCallbackCall.called = true;
|
||||
lastPressCallbackCall.caller = caller;
|
||||
}
|
||||
};
|
||||
|
||||
AHA_TEST(ButtonTest, invalid_unique_id) {
|
||||
prepareTest
|
||||
|
||||
@@ -241,6 +249,19 @@ AHA_TEST(ButtonTest, different_button_command) {
|
||||
assertPressCallbackNotCalled()
|
||||
}
|
||||
|
||||
#ifdef ARDUINOHA_USE_STD_FUNCTION
|
||||
AHA_TEST(ButtonTest, command_callback_std_function) {
|
||||
prepareTest
|
||||
|
||||
CallbacksProcessor processor;
|
||||
HAButton button(testUniqueId);
|
||||
button.onCommand(std::bind(&CallbacksProcessor::onCommand, &processor, std::placeholders::_1));
|
||||
mock->fakeMessage(AHATOFSTR(CommandTopic), AHATOFSTR(CommandMessage));
|
||||
|
||||
assertPressCallbackCalled(&button)
|
||||
}
|
||||
#endif
|
||||
|
||||
void setup()
|
||||
{
|
||||
delay(1000);
|
||||
|
||||
@@ -43,6 +43,15 @@ void onCommandReceived(HACover::CoverCommand command, HACover* caller)
|
||||
lastCommandCallbackCall.caller = caller;
|
||||
}
|
||||
|
||||
class CallbacksProcessor {
|
||||
public:
|
||||
void onCommand(HACover::CoverCommand command, HACover* caller) {
|
||||
lastCommandCallbackCall.called = true;
|
||||
lastCommandCallbackCall.command = command;
|
||||
lastCommandCallbackCall.caller = caller;
|
||||
}
|
||||
};
|
||||
|
||||
AHA_TEST(CoverTest, invalid_unique_id) {
|
||||
prepareTest
|
||||
|
||||
@@ -490,6 +499,19 @@ AHA_TEST(CoverTest, different_cover_command) {
|
||||
assertCommandCallbackNotCalled()
|
||||
}
|
||||
|
||||
#ifdef ARDUINOHA_USE_STD_FUNCTION
|
||||
AHA_TEST(CoverTest, command_callback_std_function) {
|
||||
prepareTest
|
||||
|
||||
CallbacksProcessor processor;
|
||||
HACover cover(testUniqueId);
|
||||
cover.onCommand(std::bind(&CallbacksProcessor::onCommand, &processor, std::placeholders::_1, std::placeholders::_2));
|
||||
mock->fakeMessage(AHATOFSTR(CommandTopic), F("CLOSE"));
|
||||
|
||||
assertCommandCallbackCalled(HACover::CommandClose, &cover)
|
||||
}
|
||||
#endif
|
||||
|
||||
void setup()
|
||||
{
|
||||
delay(1000);
|
||||
|
||||
@@ -73,6 +73,21 @@ void onSpeedCommandReceived(uint16_t speed, HAFan* caller)
|
||||
lastSpeedCallbackCall.caller = caller;
|
||||
}
|
||||
|
||||
class CallbacksProcessor {
|
||||
public:
|
||||
void onStateCommand(bool state, HAFan* caller) {
|
||||
lastStateCallbackCall.called = true;
|
||||
lastStateCallbackCall.state = state;
|
||||
lastStateCallbackCall.caller = caller;
|
||||
}
|
||||
|
||||
void onSpeedCommand(uint16_t speed, HAFan* caller) {
|
||||
lastSpeedCallbackCall.called = true;
|
||||
lastSpeedCallbackCall.speed = speed;
|
||||
lastSpeedCallbackCall.caller = caller;
|
||||
}
|
||||
};
|
||||
|
||||
AHA_TEST(FanTest, invalid_unique_id) {
|
||||
prepareTest
|
||||
|
||||
@@ -499,6 +514,19 @@ AHA_TEST(FanTest, state_command_different_fan) {
|
||||
assertStateCallbackNotCalled()
|
||||
}
|
||||
|
||||
#ifdef ARDUINOHA_USE_STD_FUNCTION
|
||||
AHA_TEST(FanTest, state_command_callback_std_function) {
|
||||
prepareTest
|
||||
|
||||
CallbacksProcessor processor;
|
||||
HAFan fan(testUniqueId);
|
||||
fan.onStateCommand(std::bind(&CallbacksProcessor::onStateCommand, &processor, std::placeholders::_1, std::placeholders::_2));
|
||||
mock->fakeMessage(AHATOFSTR(StateCommandTopic), F("ON"));
|
||||
|
||||
assertStateCallbackCalled(true, &fan)
|
||||
}
|
||||
#endif
|
||||
|
||||
AHA_TEST(FanTest, speed_command_half) {
|
||||
prepareTest
|
||||
|
||||
@@ -554,6 +582,19 @@ AHA_TEST(FanTest, speed_command_different_fan) {
|
||||
assertSpeedCallbackNotCalled()
|
||||
}
|
||||
|
||||
#ifdef ARDUINOHA_USE_STD_FUNCTION
|
||||
AHA_TEST(FanTest, speed_command_callback_std_function) {
|
||||
prepareTest
|
||||
|
||||
CallbacksProcessor processor;
|
||||
HAFan fan(testUniqueId);
|
||||
fan.onSpeedCommand(std::bind(&CallbacksProcessor::onSpeedCommand, &processor, std::placeholders::_1, std::placeholders::_2));
|
||||
mock->fakeMessage(AHATOFSTR(SpeedPercentageCommandTopic), F("50"));
|
||||
|
||||
assertSpeedCallbackCalled(50, &fan)
|
||||
}
|
||||
#endif
|
||||
|
||||
void setup()
|
||||
{
|
||||
delay(1000);
|
||||
|
||||
@@ -198,6 +198,45 @@ void onTargetTemperatureCommandReceived(HANumeric temperature, HAHVAC* caller)
|
||||
lastTargetTempCallbackCall.caller = caller;
|
||||
}
|
||||
|
||||
class CallbacksProcessor {
|
||||
public:
|
||||
void onAuxStateCommand(bool state, HAHVAC* caller) {
|
||||
lastAuxStateCallbackCall.called = true;
|
||||
lastAuxStateCallbackCall.state = state;
|
||||
lastAuxStateCallbackCall.caller = caller;
|
||||
}
|
||||
|
||||
void onPowerCommand(bool state, HAHVAC* caller) {
|
||||
lastPowerCallbackCall.called = true;
|
||||
lastPowerCallbackCall.state = state;
|
||||
lastPowerCallbackCall.caller = caller;
|
||||
}
|
||||
|
||||
void onFanModeCommand(HAHVAC::FanMode mode, HAHVAC* caller) {
|
||||
lastFanModeCallbackCall.called = true;
|
||||
lastFanModeCallbackCall.mode = mode;
|
||||
lastFanModeCallbackCall.caller = caller;
|
||||
}
|
||||
|
||||
void onSwingModeCommand(HAHVAC::SwingMode mode, HAHVAC* caller) {
|
||||
lastSwingModeCallbackCall.called = true;
|
||||
lastSwingModeCallbackCall.mode = mode;
|
||||
lastSwingModeCallbackCall.caller = caller;
|
||||
}
|
||||
|
||||
void onModeCommand(HAHVAC::Mode mode, HAHVAC* caller) {
|
||||
lastModeCallbackCall.called = true;
|
||||
lastModeCallbackCall.mode = mode;
|
||||
lastModeCallbackCall.caller = caller;
|
||||
}
|
||||
|
||||
void onTargetTemperatureCommand(HANumeric temperature, HAHVAC* caller) {
|
||||
lastTargetTempCallbackCall.called = true;
|
||||
lastTargetTempCallbackCall.temperature = temperature;
|
||||
lastTargetTempCallbackCall.caller = caller;
|
||||
}
|
||||
};
|
||||
|
||||
AHA_TEST(HVACTest, invalid_unique_id) {
|
||||
prepareTest
|
||||
|
||||
@@ -1600,6 +1639,19 @@ AHA_TEST(HVACTest, aux_command_different_fan) {
|
||||
assertAuxStateCallbackNotCalled()
|
||||
}
|
||||
|
||||
#ifdef ARDUINOHA_USE_STD_FUNCTION
|
||||
AHA_TEST(HVACTest, aux_state_command_callback_std_function) {
|
||||
prepareTest
|
||||
|
||||
CallbacksProcessor processor;
|
||||
HAHVAC hvac(testUniqueId, HAHVAC::AuxHeatingFeature);
|
||||
hvac.onAuxStateCommand(std::bind(&CallbacksProcessor::onAuxStateCommand, &processor, std::placeholders::_1, std::placeholders::_2));
|
||||
mock->fakeMessage(AHATOFSTR(AuxCommandTopic), F("ON"));
|
||||
|
||||
assertAuxStateCallbackCalled(true, &hvac)
|
||||
}
|
||||
#endif
|
||||
|
||||
AHA_TEST(HVACTest, power_command_on) {
|
||||
prepareTest
|
||||
|
||||
@@ -1633,6 +1685,19 @@ AHA_TEST(HVACTest, power_command_different) {
|
||||
assertPowerCallbackNotCalled()
|
||||
}
|
||||
|
||||
#ifdef ARDUINOHA_USE_STD_FUNCTION
|
||||
AHA_TEST(HVACTest, power_command_callback_std_function) {
|
||||
prepareTest
|
||||
|
||||
CallbacksProcessor processor;
|
||||
HAHVAC hvac(testUniqueId, HAHVAC::PowerFeature);
|
||||
hvac.onPowerCommand(std::bind(&CallbacksProcessor::onPowerCommand, &processor, std::placeholders::_1, std::placeholders::_2));
|
||||
mock->fakeMessage(AHATOFSTR(PowerCommandTopic), F("ON"));
|
||||
|
||||
assertPowerCallbackCalled(true, &hvac)
|
||||
}
|
||||
#endif
|
||||
|
||||
AHA_TEST(HVACTest, fan_mode_command_auto) {
|
||||
prepareTest
|
||||
|
||||
@@ -1696,6 +1761,20 @@ AHA_TEST(HVACTest, fan_mode_command_different) {
|
||||
assertFanModeCallbackNotCalled()
|
||||
}
|
||||
|
||||
#ifdef ARDUINOHA_USE_STD_FUNCTION
|
||||
AHA_TEST(HVACTest, fan_mode_command_callback_std_function) {
|
||||
prepareTest
|
||||
|
||||
CallbacksProcessor processor;
|
||||
HAHVAC hvac(testUniqueId, HAHVAC::FanFeature);
|
||||
hvac.onFanModeCommand(std::bind(&CallbacksProcessor::onFanModeCommand, &processor, std::placeholders::_1, std::placeholders::_2));
|
||||
mock->fakeMessage(AHATOFSTR(FanModeCommandTopic), F("auto"));
|
||||
|
||||
assertFanModeCallbackCalled(HAHVAC::AutoFanMode, &hvac)
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
AHA_TEST(HVACTest, swing_mode_command_on) {
|
||||
prepareTest
|
||||
|
||||
@@ -1739,6 +1818,19 @@ AHA_TEST(HVACTest, swing_mode_command_different) {
|
||||
assertSwingModeCallbackNotCalled()
|
||||
}
|
||||
|
||||
#ifdef ARDUINOHA_USE_STD_FUNCTION
|
||||
AHA_TEST(HVACTest, swing_mode_command_callback_std_function) {
|
||||
prepareTest
|
||||
|
||||
CallbacksProcessor processor;
|
||||
HAHVAC hvac(testUniqueId, HAHVAC::SwingFeature);
|
||||
hvac.onSwingModeCommand(std::bind(&CallbacksProcessor::onSwingModeCommand, &processor, std::placeholders::_1, std::placeholders::_2));
|
||||
mock->fakeMessage(AHATOFSTR(SwingModeCommandTopic), F("on"));
|
||||
|
||||
assertSwingModeCallbackCalled(HAHVAC::OnSwingMode, &hvac)
|
||||
}
|
||||
#endif
|
||||
|
||||
AHA_TEST(HVACTest, mode_command_auto) {
|
||||
prepareTest
|
||||
|
||||
@@ -1799,6 +1891,32 @@ AHA_TEST(HVACTest, mode_command_fan_only) {
|
||||
assertModeCallbackCalled(HAHVAC::FanOnlyMode, &hvac)
|
||||
}
|
||||
|
||||
AHA_TEST(HVACTest, mode_command_different) {
|
||||
prepareTest
|
||||
|
||||
HAHVAC hvac(testUniqueId, HAHVAC::ModesFeature);
|
||||
hvac.onModeCommand(onModeCommandReceived);
|
||||
mock->fakeMessage(
|
||||
F("testData/testDevice/uniqueHVACDifferent/mode_cmd_t"),
|
||||
F("auto")
|
||||
);
|
||||
|
||||
assertModeCallbackNotCalled()
|
||||
}
|
||||
|
||||
#ifdef ARDUINOHA_USE_STD_FUNCTION
|
||||
AHA_TEST(HVACTest, mode_command_callback_std_function) {
|
||||
prepareTest
|
||||
|
||||
CallbacksProcessor processor;
|
||||
HAHVAC hvac(testUniqueId, HAHVAC::ModesFeature);
|
||||
hvac.onModeCommand(std::bind(&CallbacksProcessor::onModeCommand, &processor, std::placeholders::_1, std::placeholders::_2));
|
||||
mock->fakeMessage(AHATOFSTR(ModeCommandTopic), F("auto"));
|
||||
|
||||
assertModeCallbackCalled(HAHVAC::AutoMode, &hvac)
|
||||
}
|
||||
#endif
|
||||
|
||||
AHA_TEST(HVACTest, target_temperature_command_p1) {
|
||||
prepareTest
|
||||
|
||||
@@ -1860,6 +1978,19 @@ AHA_TEST(HVACTest, target_temperature_command_different) {
|
||||
assertTargetTempCallbackNotCalled()
|
||||
}
|
||||
|
||||
#ifdef ARDUINOHA_USE_STD_FUNCTION
|
||||
AHA_TEST(HVACTest, target_temperature_command_callback_std_function) {
|
||||
prepareTest
|
||||
|
||||
CallbacksProcessor processor;
|
||||
HAHVAC hvac(testUniqueId, HAHVAC::TargetTemperatureFeature);
|
||||
hvac.onTargetTemperatureCommand(std::bind(&CallbacksProcessor::onTargetTemperatureCommand, &processor, std::placeholders::_1, std::placeholders::_2));
|
||||
mock->fakeMessage(AHATOFSTR(TemperatureCommandTopic), F("215"));
|
||||
|
||||
assertTargetTempCallbackCalled(HANumeric(21.5f, 1), &hvac)
|
||||
}
|
||||
#endif
|
||||
|
||||
void setup()
|
||||
{
|
||||
delay(1000);
|
||||
|
||||
@@ -136,6 +136,33 @@ void onRGBColorCommand(HALight::RGBColor color, HALight* caller)
|
||||
lastRGBColorCallbackCall.caller = caller;
|
||||
}
|
||||
|
||||
class CallbacksProcessor {
|
||||
public:
|
||||
void onStateCommand(bool state, HALight* caller) {
|
||||
lastStateCallbackCall.called = true;
|
||||
lastStateCallbackCall.state = state;
|
||||
lastStateCallbackCall.caller = caller;
|
||||
}
|
||||
|
||||
void onBrightnessCommand(uint8_t brightness, HALight* caller) {
|
||||
lastBrightnessCallbackCall.called = true;
|
||||
lastBrightnessCallbackCall.brightness = brightness;
|
||||
lastBrightnessCallbackCall.caller = caller;
|
||||
}
|
||||
|
||||
void onColorTemperatureCommand(uint16_t temperature, HALight* caller) {
|
||||
lastColorTempCallbackCall.called = true;
|
||||
lastColorTempCallbackCall.temperature = temperature;
|
||||
lastColorTempCallbackCall.caller = caller;
|
||||
}
|
||||
|
||||
void onRGBColorCommand(HALight::RGBColor color, HALight* caller) {
|
||||
lastRGBColorCallbackCall.called = true;
|
||||
lastRGBColorCallbackCall.color = color;
|
||||
lastRGBColorCallbackCall.caller = caller;
|
||||
}
|
||||
};
|
||||
|
||||
AHA_TEST(LightTest, invalid_unique_id) {
|
||||
prepareTest
|
||||
|
||||
@@ -821,6 +848,19 @@ AHA_TEST(LightTest, state_command_different_light) {
|
||||
assertStateCallbackNotCalled()
|
||||
}
|
||||
|
||||
#ifdef ARDUINOHA_USE_STD_FUNCTION
|
||||
AHA_TEST(LightTest, state_command_callback_std_function) {
|
||||
prepareTest
|
||||
|
||||
CallbacksProcessor processor;
|
||||
HALight light(testUniqueId);
|
||||
light.onStateCommand(std::bind(&CallbacksProcessor::onStateCommand, &processor, std::placeholders::_1, std::placeholders::_2));
|
||||
mock->fakeMessage(AHATOFSTR(StateCommandTopic), F("ON"));
|
||||
|
||||
assertStateCallbackCalled(true, &light)
|
||||
}
|
||||
#endif
|
||||
|
||||
AHA_TEST(LightTest, brightness_command_min) {
|
||||
prepareTest
|
||||
|
||||
@@ -874,6 +914,19 @@ AHA_TEST(LightTest, brightness_command_different_light) {
|
||||
assertBrightnessCallbackNotCalled()
|
||||
}
|
||||
|
||||
#ifdef ARDUINOHA_USE_STD_FUNCTION
|
||||
AHA_TEST(LightTest, brightness_command_callback_std_function) {
|
||||
prepareTest
|
||||
|
||||
CallbacksProcessor processor;
|
||||
HALight light(testUniqueId);
|
||||
light.onBrightnessCommand(std::bind(&CallbacksProcessor::onBrightnessCommand, &processor, std::placeholders::_1, std::placeholders::_2));
|
||||
mock->fakeMessage(AHATOFSTR(BrightnessCommandTopic), F("50"));
|
||||
|
||||
assertBrightnessCallbackCalled(50, &light)
|
||||
}
|
||||
#endif
|
||||
|
||||
AHA_TEST(LightTest, color_temperature_command) {
|
||||
prepareTest
|
||||
|
||||
@@ -927,6 +980,19 @@ AHA_TEST(LightTest, color_temperature_command_different_light) {
|
||||
assertColorTempCallbackNotCalled()
|
||||
}
|
||||
|
||||
#ifdef ARDUINOHA_USE_STD_FUNCTION
|
||||
AHA_TEST(LightTest, color_temperature_command_callback_std_function) {
|
||||
prepareTest
|
||||
|
||||
CallbacksProcessor processor;
|
||||
HALight light(testUniqueId, HALight::ColorTemperatureFeature);
|
||||
light.onColorTemperatureCommand(std::bind(&CallbacksProcessor::onColorTemperatureCommand, &processor, std::placeholders::_1, std::placeholders::_2));
|
||||
mock->fakeMessage(AHATOFSTR(ColorTemperatureCommandTopic), F("200"));
|
||||
|
||||
assertColorTempCallbackCalled(200, &light)
|
||||
}
|
||||
#endif
|
||||
|
||||
AHA_TEST(LightTest, rgb_color_min_command) {
|
||||
prepareTest
|
||||
|
||||
@@ -1040,6 +1106,19 @@ AHA_TEST(LightTest, rgb_color_command_different_light) {
|
||||
assertRGBColorCallbackNotCalled()
|
||||
}
|
||||
|
||||
#ifdef ARDUINOHA_USE_STD_FUNCTION
|
||||
AHA_TEST(LightTest, rgb_color_command_callback_std_function) {
|
||||
prepareTest
|
||||
|
||||
CallbacksProcessor processor;
|
||||
HALight light(testUniqueId, HALight::RGBFeature);
|
||||
light.onRGBColorCommand(std::bind(&CallbacksProcessor::onRGBColorCommand, &processor, std::placeholders::_1, std::placeholders::_2));
|
||||
mock->fakeMessage(AHATOFSTR(RGBCommandTopic), F("255,12,1"));
|
||||
|
||||
assertRGBColorCallbackCalled(HALight::RGBColor(255,12,1), &light)
|
||||
}
|
||||
#endif
|
||||
|
||||
void setup()
|
||||
{
|
||||
delay(1000);
|
||||
|
||||
@@ -42,6 +42,15 @@ void onCommandReceived(HALock::LockCommand command, HALock* caller)
|
||||
lastCommandCallbackCall.caller = caller;
|
||||
}
|
||||
|
||||
class CallbacksProcessor {
|
||||
public:
|
||||
void onCommand(HALock::LockCommand command, HALock* caller) {
|
||||
lastCommandCallbackCall.called = true;
|
||||
lastCommandCallbackCall.command = command;
|
||||
lastCommandCallbackCall.caller = caller;
|
||||
}
|
||||
};
|
||||
|
||||
AHA_TEST(LockTest, invalid_unique_id) {
|
||||
prepareTest
|
||||
|
||||
@@ -327,6 +336,19 @@ AHA_TEST(LockTest, different_lock_command) {
|
||||
assertCommandCallbackNotCalled()
|
||||
}
|
||||
|
||||
#ifdef ARDUINOHA_USE_STD_FUNCTION
|
||||
AHA_TEST(LockTest, command_callback_std_function) {
|
||||
prepareTest
|
||||
|
||||
CallbacksProcessor processor;
|
||||
HALock lock(testUniqueId);
|
||||
lock.onCommand(std::bind(&CallbacksProcessor::onCommand, &processor, std::placeholders::_1, std::placeholders::_2));
|
||||
mock->fakeMessage(AHATOFSTR(CommandTopic), F("LOCK"));
|
||||
|
||||
assertCommandCallbackCalled(HALock::CommandLock, &lock)
|
||||
}
|
||||
#endif
|
||||
|
||||
void setup()
|
||||
{
|
||||
delay(1000);
|
||||
|
||||
@@ -42,6 +42,15 @@ void onCommandReceived(HANumeric number, HANumber* caller)
|
||||
lastCommandCallbackCall.caller = caller;
|
||||
}
|
||||
|
||||
class CallbacksProcessor {
|
||||
public:
|
||||
void onCommand(HANumeric number, HANumber* caller) {
|
||||
lastCommandCallbackCall.called = true;
|
||||
lastCommandCallbackCall.number = number;
|
||||
lastCommandCallbackCall.caller = caller;
|
||||
}
|
||||
};
|
||||
|
||||
AHA_TEST(NumberTest, invalid_unique_id) {
|
||||
prepareTest
|
||||
|
||||
@@ -858,6 +867,19 @@ AHA_TEST(NumberTest, different_number_command) {
|
||||
assertCommandCallbackNotCalled()
|
||||
}
|
||||
|
||||
#ifdef ARDUINOHA_USE_STD_FUNCTION
|
||||
AHA_TEST(NumberTest, command_callback_std_function) {
|
||||
prepareTest
|
||||
|
||||
CallbacksProcessor processor;
|
||||
HANumber number(testUniqueId, HANumber::PrecisionP1);
|
||||
number.onCommand(std::bind(&CallbacksProcessor::onCommand, &processor, std::placeholders::_1, std::placeholders::_2));
|
||||
mock->fakeMessage(AHATOFSTR(CommandTopic), F("1234"));
|
||||
|
||||
assertCommandCallbackCalled(HANumeric(123.4f, 1), &number)
|
||||
}
|
||||
#endif
|
||||
|
||||
void setup()
|
||||
{
|
||||
delay(1000);
|
||||
|
||||
@@ -38,6 +38,14 @@ void onCommandReceived(HAScene* caller)
|
||||
lastActivateCallbackCall.caller = caller;
|
||||
}
|
||||
|
||||
class CallbacksProcessor {
|
||||
public:
|
||||
void onCommand(HAScene* caller) {
|
||||
lastActivateCallbackCall.called = true;
|
||||
lastActivateCallbackCall.caller = caller;
|
||||
}
|
||||
};
|
||||
|
||||
AHA_TEST(SceneTest, invalid_unique_id) {
|
||||
prepareTest
|
||||
|
||||
@@ -221,6 +229,20 @@ AHA_TEST(SceneTest, different_scene_command) {
|
||||
assertActivateCallbackNotCalled()
|
||||
}
|
||||
|
||||
#ifdef ARDUINOHA_USE_STD_FUNCTION
|
||||
|
||||
AHA_TEST(SceneTest, command_callback_std_function) {
|
||||
prepareTest
|
||||
|
||||
CallbacksProcessor processor;
|
||||
HAScene scene(testUniqueId);
|
||||
scene.onCommand(std::bind(&CallbacksProcessor::onCommand, &processor, std::placeholders::_1));
|
||||
mock->fakeMessage(AHATOFSTR(CommandTopic), AHATOFSTR(CommandMessage));
|
||||
|
||||
assertActivateCallbackCalled(&scene)
|
||||
}
|
||||
#endif
|
||||
|
||||
void setup()
|
||||
{
|
||||
delay(1000);
|
||||
|
||||
@@ -42,6 +42,15 @@ void onCommandReceived(int8_t index, HASelect* caller)
|
||||
lastCommandCallbackCall.caller = caller;
|
||||
}
|
||||
|
||||
class CallbacksProcessor {
|
||||
public:
|
||||
void onCommand(int8_t index, HASelect* caller) {
|
||||
lastCommandCallbackCall.called = true;
|
||||
lastCommandCallbackCall.index = index;
|
||||
lastCommandCallbackCall.caller = caller;
|
||||
}
|
||||
};
|
||||
|
||||
AHA_TEST(SelectTest, invalid_unique_id) {
|
||||
prepareTest
|
||||
|
||||
@@ -472,7 +481,19 @@ AHA_TEST(SelectTest, different_select_command) {
|
||||
assertCommandCallbackNotCalled()
|
||||
}
|
||||
|
||||
#ifdef ARDUINOHA_USE_STD_FUNCTION
|
||||
AHA_TEST(SelectTest, command_callback_std_function) {
|
||||
prepareTest
|
||||
|
||||
CallbacksProcessor processor;
|
||||
HASelect select(testUniqueId);
|
||||
select.setOptions("Option A;B;C");
|
||||
select.onCommand(std::bind(&CallbacksProcessor::onCommand, &processor, std::placeholders::_1, std::placeholders::_2));
|
||||
mock->fakeMessage(AHATOFSTR(CommandTopic), F("Option A"));
|
||||
|
||||
assertCommandCallbackCalled(0, &select)
|
||||
}
|
||||
#endif
|
||||
void setup()
|
||||
{
|
||||
delay(1000);
|
||||
|
||||
@@ -42,6 +42,15 @@ void onCommandReceived(bool state, HASwitch* caller)
|
||||
lastCommandCallbackCall.caller = caller;
|
||||
}
|
||||
|
||||
class CallbacksProcessor {
|
||||
public:
|
||||
void onCommand(bool state, HASwitch* caller) {
|
||||
lastCommandCallbackCall.called = true;
|
||||
lastCommandCallbackCall.state = state;
|
||||
lastCommandCallbackCall.caller = caller;
|
||||
}
|
||||
};
|
||||
|
||||
AHA_TEST(SwitchTest, invalid_unique_id) {
|
||||
prepareTest
|
||||
|
||||
@@ -329,6 +338,19 @@ AHA_TEST(SwitchTest, different_switch_command) {
|
||||
assertCommandCallbackNotCalled()
|
||||
}
|
||||
|
||||
#ifdef ARDUINOHA_USE_STD_FUNCTION
|
||||
AHA_TEST(SwitchTest, command_callback_std_function) {
|
||||
prepareTest
|
||||
|
||||
CallbacksProcessor processor;
|
||||
HASwitch testSwitch(testUniqueId);
|
||||
testSwitch.onCommand(std::bind(&CallbacksProcessor::onCommand, &processor, std::placeholders::_1, std::placeholders::_2));
|
||||
mock->fakeMessage(AHATOFSTR(CommandTopic), F("ON"));
|
||||
|
||||
assertCommandCallbackCalled(true, &testSwitch)
|
||||
}
|
||||
#endif
|
||||
|
||||
void setup()
|
||||
{
|
||||
delay(1000);
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
[auniter]
|
||||
monitor = picocom -b $baud --omap crlf --imap lfcrlf --echo $port
|
||||
|
||||
[boards]
|
||||
uno = arduino:avr:uno
|
||||
mega = arduino:avr:mega:cpu=atmega2560
|
||||
|
||||
Reference in New Issue
Block a user