From 5ca3cd1fcf9a33d52b449d074e48e3b6804a71f0 Mon Sep 17 00:00:00 2001 From: Dawid Chyrzynski Date: Fri, 4 Dec 2020 19:48:20 +0100 Subject: [PATCH] minor changes --- src/HAMqtt.cpp | 32 ++++++++++---------------------- src/HAMqtt.h | 1 - src/device-types/HASwitch.h | 3 +++ 3 files changed, 13 insertions(+), 23 deletions(-) diff --git a/src/HAMqtt.cpp b/src/HAMqtt.cpp index dcebf27..38718b1 100644 --- a/src/HAMqtt.cpp +++ b/src/HAMqtt.cpp @@ -6,18 +6,6 @@ #include "ArduinoHADefines.h" #include "device-types/BaseDeviceType.h" -#define HAMQTT_INIT \ - _initialized(false), \ - _discoveryPrefix(DefaultDiscoveryPrefix), \ - _mqtt(new PubSubClient(netClient)), \ - _serverIp(new IPAddress()), \ - _serverPort(0), \ - _username(nullptr), \ - _password(nullptr), \ - _lastConnectionAttemptAt(0), \ - _devicesTypesNb(0), \ - _devicesTypes(nullptr) - const char* HAMqtt::DefaultDiscoveryPrefix = "homeassistant"; HAMqtt* instance = nullptr; @@ -30,21 +18,21 @@ void onMessageReceived(char* topic, uint8_t* payload, uint16_t length) instance->processMessage(topic, payload, length); } -HAMqtt::HAMqtt(const char* clientId, Client& netClient) : - _clientId(clientId), - _netClient(netClient), - _hasDevice(false), - HAMQTT_INIT -{ - instance = this; -} - HAMqtt::HAMqtt(const char* clientId, Client& netClient, HADevice& device) : _clientId(clientId), _netClient(netClient), _device(device), _hasDevice(true), - HAMQTT_INIT + _initialized(false), + _discoveryPrefix(DefaultDiscoveryPrefix), + _mqtt(new PubSubClient(netClient)), + _serverIp(new IPAddress()), + _serverPort(0), + _username(nullptr), + _password(nullptr), + _lastConnectionAttemptAt(0), + _devicesTypesNb(0), + _devicesTypes(nullptr) { instance = this; } diff --git a/src/HAMqtt.h b/src/HAMqtt.h index cb7b685..bd6a426 100644 --- a/src/HAMqtt.h +++ b/src/HAMqtt.h @@ -15,7 +15,6 @@ public: static const char* DefaultDiscoveryPrefix; static const uint16_t ReconnectInterval = 3000; // ms - HAMqtt(const char* clientId, Client& netClient); HAMqtt(const char* clientId, Client& netClient, HADevice& device); /** diff --git a/src/device-types/HASwitch.h b/src/device-types/HASwitch.h index c4ac5c8..9ef25e1 100644 --- a/src/device-types/HASwitch.h +++ b/src/device-types/HASwitch.h @@ -23,6 +23,9 @@ public: const uint16_t& length ) override; + inline const char* getName() const + { return _name; } + void setState(bool state); void turnOn(); void turnOff();