Skip to content

Commit

Permalink
SwitchBot Curtain fix (#268)
Browse files Browse the repository at this point in the history
SwitchBot Curtain fix for

https: //github.com/1technophile/OpenMQTTGateway/issues/1412#issuecomment-1399518643
Co-Authored-By: Sebastian <812398+sebbo2002@users.noreply.github.com>

Co-authored-by: Sebastian <812398+sebbo2002@users.noreply.github.com>
  • Loading branch information
DigiH and sebbo2002 committed Jan 22, 2023
1 parent 884e1e7 commit bbe2105
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class TheengsDecoder {
RUUVITAG_RAWV2,
SBCS,
SBCU,
SBCU_NEW,
SBMS,
SBMT,
SBS1,
Expand Down
3 changes: 2 additions & 1 deletion src/devices.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ const char* _devices[][2] = {
{_RuuviTag_RAWv1_json, _RuuviTag_RAWv1_json_props},
{_RuuviTag_RAWv2_json, _RuuviTag_RAWv2_json_props},
{_SBCS_json, _SBCS_json_props},
{_SBCU_json, _SBCU_json_props},
{_SBCU_json_ORIG, _SBCU_json_props},
{_SBCU_json_NEW, _SBCU_json_props},
{_SBMS_json, _SBMS_json_props},
{_SBMT_json, _SBMT_json_props},
{_SBS1_json, _SBS1_json_props},
Expand Down
30 changes: 29 additions & 1 deletion src/devices/SBCU_json.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const char* _SBCU_json = "{\"brand\":\"SwitchBot\",\"model\":\"Curtain\",\"model_id\":\"W070160X\",\"condition\":[\"uuid\",\"index\",0,\"0d00\",\"&\",\"servicedata\",\"=\",10,\"index\",0,\"63\"],\"properties\":{\"motion\":{\"decoder\":[\"bit_static_value\",\"servicedata\",6,3,false,true]},\"position\":{\"decoder\":[\"value_from_hex_data\",\"servicedata\",6,2,false,false],\"post_proc\":[\"&\",127]},\"calibrated\":{\"decoder\":[\"bit_static_value\",\"servicedata\",2,2,false,true]},\"lightlevel\":{\"decoder\":[\"value_from_hex_data\",\"servicedata\",8,1,false,false]},\"batt\":{\"decoder\":[\"value_from_hex_data\",\"servicedata\",4,2,false,false],\"post_proc\":[\"&\",127]}}}";
const char* _SBCU_json_ORIG = "{\"brand\":\"SwitchBot\",\"model\":\"Curtain\",\"model_id\":\"W070160X\",\"condition\":[\"uuid\",\"index\",0,\"0d00\",\"&\",\"servicedata\",\"=\",10,\"index\",0,\"63\"],\"properties\":{\"motion\":{\"decoder\":[\"bit_static_value\",\"servicedata\",6,3,false,true]},\"position\":{\"decoder\":[\"value_from_hex_data\",\"servicedata\",6,2,false,false],\"post_proc\":[\"&\",127]},\"calibrated\":{\"decoder\":[\"bit_static_value\",\"servicedata\",2,2,false,true]},\"lightlevel\":{\"decoder\":[\"value_from_hex_data\",\"servicedata\",8,1,false,false]},\"batt\":{\"decoder\":[\"value_from_hex_data\",\"servicedata\",4,2,false,false],\"post_proc\":[\"&\",127]}}}";
/*R""""(
{
"brand":"SwitchBot",
Expand Down Expand Up @@ -26,6 +26,34 @@ const char* _SBCU_json = "{\"brand\":\"SwitchBot\",\"model\":\"Curtain\",\"model
}
})"""";*/

const char* _SBCU_json_NEW = "{\"brand\":\"SwitchBot\",\"model\":\"Curtain\",\"model_id\":\"W070160X\",\"condition\":[\"uuid\",\"index\",0,\"fd3d\",\"&\",\"servicedata\",\"=\",12,\"index\",0,\"63\"],\"properties\":{\"motion\":{\"decoder\":[\"bit_static_value\",\"servicedata\",6,3,false,true]},\"position\":{\"decoder\":[\"value_from_hex_data\",\"servicedata\",6,2,false,false],\"post_proc\":[\"&\",127]},\"calibrated\":{\"decoder\":[\"bit_static_value\",\"servicedata\",2,2,false,true]},\"lightlevel\":{\"decoder\":[\"value_from_hex_data\",\"servicedata\",8,1,false,false]},\"batt\":{\"decoder\":[\"value_from_hex_data\",\"servicedata\",4,2,false,false],\"post_proc\":[\"&\",127]}}}";
/*R""""(
{
"brand":"SwitchBot",
"model":"Curtain",
"model_id":"W070160X",
"condition":["uuid", "index", 0, "fd3d", "&", "servicedata", "=", 12, "index", 0, "63"],
"properties":{
"motion":{
"decoder":["bit_static_value", "servicedata", 6, 3, false, true]
},
"position":{
"decoder":["value_from_hex_data", "servicedata", 6, 2, false, false],
"post_proc":["&", 127]
},
"calibrated":{
"decoder":["bit_static_value", "servicedata", 2, 2, false, true]
},
"lightlevel":{
"decoder":["value_from_hex_data", "servicedata", 8, 1, false, false]
},
"batt":{
"decoder":["value_from_hex_data", "servicedata", 4, 2, false, false],
"post_proc":["&", 127]
}
}
})"""";*/

const char* _SBCU_json_props = "{\"properties\":{\"motion\":{\"unit\":\"status\",\"name\":\"motion\"},\"position\":{\"unit\":\"%\",\"name\":\"position\"},\"calibrated\":{\"unit\":\"status\",\"name\":\"calibrated\"},\"lightlevel\":{\"unit\":\"int\",\"name\":\"light level\"},\"batt\":{\"unit\":\"%\",\"name\":\"battery\"}}}";
/*R""""(
{
Expand Down
3 changes: 3 additions & 0 deletions tests/BLE/test_ble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ const char* expected_uuid[] = {
"{\"brand\":\"ClearGrass/Qingping\",\"model\":\"Round TH\",\"model_id\":\"CGG1\",\"tempc\":23.5,\"tempf\":74.3,\"hum\":28.3,\"batt\":100}",
"{\"brand\":\"ClearGrass/Qingping\",\"model\":\"Round TH\",\"model_id\":\"CGG1\",\"tempc\":24.4,\"tempf\":75.92,\"hum\":31.5,\"batt\":100}",
"{\"brand\":\"ClearGrass/Qingping\",\"model\":\"Alarm Clock\",\"model_id\":\"CGC1/CGD1\",\"tempc\":21,\"tempf\":69.8,\"hum\":51,\"batt\":100}",
"{\"brand\":\"SwitchBot\",\"model\":\"Curtain\",\"model_id\":\"W070160X\",\"motion\":false,\"position\":100,\"calibrated\":true,\"lightlevel\":1,\"batt\":17}",
};

const char* expected_mac_mfg[] = {
Expand Down Expand Up @@ -587,6 +588,7 @@ const char* test_uuid[][4] = {
{"Qingping round sensor", "0xfdcd", "servicedata", "8816YYYYYYYYYYYY0104eb001b01020164"},
{"Qingping round sensor", "0xfdcd", "servicedata", "8816xxxxxxxxxxxx0104f4003b01020164"},
{"Qingping alarm clock", "0xfdcd", "servicedata", "081eaabbccddeeff0104d200fe01020164"},
{"Switchbot_Curtain NEW", "fd3d", "servicedata", "63c011641104"},
};

TheengsDecoder::BLE_ID_NUM test_uuid_id_num[]{
Expand Down Expand Up @@ -671,6 +673,7 @@ TheengsDecoder::BLE_ID_NUM test_uuid_id_num[]{
TheengsDecoder::BLE_ID_NUM::CGG1_STOCK,
TheengsDecoder::BLE_ID_NUM::CGG1_STOCK,
TheengsDecoder::BLE_ID_NUM::CGD1,
TheengsDecoder::BLE_ID_NUM::SBCU_NEW,
};

// MAC manufacturer data test input [test name] [mac] [data]
Expand Down

0 comments on commit bbe2105

Please sign in to comment.