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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 3 additions & 4 deletions
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 2 additions & 3 deletions
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

Lines changed: 2 additions & 3 deletions
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 2 additions & 3 deletions
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") {

0 commit comments

Comments
 (0)