Skip to content

Commit e5eb033

Browse files
committed
Code optimization
- removed unnecessary includes - simplified call for standard request handler - simplified SinricProSwitch to a typedef since SinricProDevice handles powerState
1 parent 47ac1f5 commit e5eb033

15 files changed

+18
-37
lines changed

SinricPro.h

+2
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@
55
* This file is part of the Sinric Pro (https://github.com/sinricpro/)
66
*/
77

8+
#include <ArduonoJson.h>
9+
#include <WebSockets.h>
810
#include "src/SinricPro.h"

src/SinricProContactsensor.h

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#define _SINRICCONTACTSENSOR_H_
1010

1111
#include "SinricProDevice.h"
12-
#include <ArduinoJson.h>
1312

1413
class SinricProContactsensor : public SinricProDevice {
1514
public:

src/SinricProDimSwitch.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#define _SINRICDIMSWITCH_H_
1010

1111
#include "SinricProDevice.h"
12-
#include <ArduinoJson.h>
1312

1413
class SinricProDimSwitch : public SinricProDevice {
1514
public:
@@ -37,10 +36,10 @@ SinricProDimSwitch::SinricProDimSwitch(const char* deviceId, unsigned long event
3736

3837
bool SinricProDimSwitch::handleRequest(const char* deviceId, const char* action, JsonObject &request_value, JsonObject &response_value) {
3938
if (strcmp(deviceId, this->deviceId) != 0) return false;
39+
40+
if (SinricProDevice::handleRequest(deviceId, action, request_value, response_value)) return true;
4041

41-
bool success = SinricProDevice::handleRequest(deviceId, action, request_value, response_value);
42-
if (success) return success;
43-
42+
bool success = false;
4443
String actionString = String(action);
4544

4645
if (powerLevelCallback && actionString == "setPowerLevel") {

src/SinricProDoorbell.h

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#define _SINRICDOORBELL_H_
1010

1111
#include "SinricProDevice.h"
12-
#include <ArduinoJson.h>
1312

1413
class SinricProDoorbell : public SinricProDevice {
1514
public:

src/SinricProFan.h

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#define _SINRICFAN_H_
1010

1111
#include "SinricProDevice.h"
12-
#include <ArduinoJson.h>
1312

1413
/*
1514
* SinricFan is the same deviceType like SinricDimSwitch

src/SinricProFanUS.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#define _SINRICFANUS_H_
1010

1111
#include "SinricProDevice.h"
12-
#include <ArduinoJson.h>
1312

1413
class SinricProFanUS : public SinricProDevice {
1514
public:
@@ -34,9 +33,9 @@ SinricProFanUS::SinricProFanUS(const char* deviceId, unsigned long eventWaitTime
3433

3534
bool SinricProFanUS::handleRequest(const char* deviceId, const char* action, JsonObject &request_value, JsonObject &response_value) {
3635
if (strcmp(deviceId, this->deviceId) != 0) return false;
37-
bool success = SinricProDevice::handleRequest(deviceId, action, request_value, response_value); // call default handler
38-
if (success) return success; // default handler handled request? return...
36+
if (SinricProDevice::handleRequest(deviceId, action, request_value, response_value)) return true;
3937

38+
bool success = false;
4039
String actionString = String(action);
4140

4241
if (actionString == "setRangeValue" && rangeValueCallback) {

src/SinricProLight.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#define _SINRICLIGHT_H_
1010

1111
#include "SinricProDevice.h"
12-
#include <ArduinoJson.h>
1312

1413
class SinricProLight : public SinricProDevice {
1514
public:
@@ -52,9 +51,9 @@ SinricProLight::SinricProLight(const char* deviceId, unsigned long eventWaitTime
5251

5352
bool SinricProLight::handleRequest(const char* deviceId, const char* action, JsonObject &request_value, JsonObject &response_value) {
5453
if (strcmp(deviceId, this->deviceId) != 0) return false;
55-
bool success = SinricProDevice::handleRequest(deviceId, action, request_value, response_value); // call default handler
56-
if (success) return success; // default handler handled request? return...
54+
if (SinricProDevice::handleRequest(deviceId, action, request_value, response_value)) return true;
5755

56+
bool success = false;
5857
String actionString = String(action);
5958

6059
if (brightnessCallback && actionString == "setBrightness") {

src/SinricProLock.h

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#define _SINRICLOCK_H_
1010

1111
#include "SinricProDevice.h"
12-
#include <ArduinoJson.h>
1312

1413
class SinricProLock : public SinricProDevice {
1514
public:

src/SinricProMotionsensor.h

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#define _SINRICMOTIONSENSOR_H_
1010

1111
#include "SinricProDevice.h"
12-
#include <ArduinoJson.h>
1312

1413
class SinricProMotionsensor : public SinricProDevice {
1514
public:

src/SinricProSpeaker.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#define _SINRICSPEAKER_H_
1010

1111
#include "SinricProDevice.h"
12-
#include <ArduinoJson.h>
1312

1413
class SinricProSpeaker : public SinricProDevice {
1514
public:
@@ -63,9 +62,9 @@ SinricProSpeaker::SinricProSpeaker(const char* deviceId, unsigned long eventWait
6362

6463
bool SinricProSpeaker::handleRequest(const char* deviceId, const char* action, JsonObject &request_value, JsonObject &response_value) {
6564
if (strcmp(deviceId, this->deviceId) != 0) return false;
66-
bool success = SinricProDevice::handleRequest(deviceId, action, request_value, response_value); // call default handler
67-
if (success) return success; // default handler handled request? return...
65+
if (SinricProDevice::handleRequest(deviceId, action, request_value, response_value)) return true;
6866

67+
bool success = false;
6968
String actionString = String(action);
7069

7170
if (volumeCallback && actionString == "setVolume") {

src/SinricProSwitch.h

+1-9
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,7 @@
99
#define _SINRICSWITCH_H_
1010

1111
#include "SinricProDevice.h"
12-
#include <ArduinoJson.h>
13-
14-
class SinricProSwitch : public SinricProDevice {
15-
public:
16-
SinricProSwitch(const char* deviceId, unsigned long eventWaitTime=100);
17-
private:
18-
};
19-
20-
SinricProSwitch::SinricProSwitch(const char* deviceId, unsigned long eventWaitTime) : SinricProDevice(deviceId, eventWaitTime) {}
12+
typedef SinricProDevice SinricProSwitch;
2113

2214
#endif
2315

src/SinricProTV.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#define _SINRICTV_H_
1010

1111
#include "SinricProDevice.h"
12-
#include <ArduinoJson.h>
1312

1413
class SinricProTV : public SinricProDevice {
1514
public:
@@ -61,9 +60,9 @@ SinricProTV::SinricProTV(const char* deviceId, unsigned long eventWaitTime) : Si
6160

6261
bool SinricProTV::handleRequest(const char* deviceId, const char* action, JsonObject &request_value, JsonObject &response_value) {
6362
if (strcmp(deviceId, this->deviceId) != 0) return false;
64-
bool success = SinricProDevice::handleRequest(deviceId, action, request_value, response_value); // call default handler
65-
if (success) return success; // default handler handled request? return...
63+
if (SinricProDevice::handleRequest(deviceId, action, request_value, response_value)) return true;
6664

65+
bool success = false;
6766
String actionString = String(action);
6867

6968
if (volumeCallback && actionString == "setVolume") {

src/SinricProTemperaturesensor.h

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#define _SINRICTEMPERATURESENSOR_H_
1010

1111
#include "SinricProDevice.h"
12-
#include <ArduinoJson.h>
1312

1413
class SinricProTemperaturesensor : public SinricProDevice {
1514
public:

src/SinricProThermostat.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#define _SINRICTHERMOSTAT_H_
1010

1111
#include "SinricProDevice.h"
12-
#include <ArduinoJson.h>
1312

1413
class SinricProThermostat : public SinricProDevice {
1514
public:
@@ -42,9 +41,9 @@ SinricProThermostat::SinricProThermostat(const char* deviceId, unsigned long eve
4241

4342
bool SinricProThermostat::handleRequest(const char* deviceId, const char* action, JsonObject &request_value, JsonObject &response_value) {
4443
if (strcmp(deviceId, this->deviceId) != 0) return false;
45-
bool success = SinricProDevice::handleRequest(deviceId, action, request_value, response_value); // call default handler
46-
if (success) return success; // default handler handled request? return...
44+
if (SinricProDevice::handleRequest(deviceId, action, request_value, response_value)) return true;
4745

46+
bool success = false;
4847
String actionString = String(action);
4948

5049
if (actionString == "targetTemperature" && targetTemperatureCallback) {

src/SinricProWindowAC.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#define _SINRICWINDOWAC_H_
1010

1111
#include "SinricProDevice.h"
12-
#include <ArduinoJson.h>
1312

1413
class SinricProWindowAC : public SinricProDevice {
1514
public:
@@ -51,9 +50,9 @@ SinricProWindowAC::SinricProWindowAC(const char* deviceId, unsigned long eventWa
5150

5251
bool SinricProWindowAC::handleRequest(const char* deviceId, const char* action, JsonObject &request_value, JsonObject &response_value) {
5352
if (strcmp(deviceId, this->deviceId) != 0) return false;
54-
bool success = SinricProDevice::handleRequest(deviceId, action, request_value, response_value); // call default handler
55-
if (success) return success; // default handler handled request? return...
53+
if (SinricProDevice::handleRequest(deviceId, action, request_value, response_value)) return true;
5654

55+
bool success = false;
5756
String actionString = String(action);
5857

5958
if (actionString == "setRangeValue" && rangeValueCallback) {

0 commit comments

Comments
 (0)