Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SwitchBot Outdoor Meter Manufacturerdata & Servicedata only decoders #562

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ class TheengsDecoder {
SBMT,
SBMT_M,
SBOT,
SBOT_M,
SBOT_S,
SBS1,
SHT4X,
SCD4X,
Expand Down
2 changes: 2 additions & 0 deletions src/devices.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ const char* _devices[][2] = {
{_SBMT_json, _SBMT_json_props},
{_SBMT_json_M, _SBMT_json_props},
{_SBOT_json, _SBOT_json_props},
{_SBOT_json_M, _SBOT_json_props},
{_SBOT_json_S, _SBOT_json_props},
{_SBS1_json, _SBS1_json_props},
{_SHT4X_json, _SHT4X_json_props},
{_SCD4X_json, _SCD4X_json_props},
Expand Down
49 changes: 49 additions & 0 deletions src/devices/SBOT_json.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,53 @@ const char* _SBOT_json = "{\"brand\":\"SwitchBot\",\"model\":\"Outdoor Meter\",\
}
})"""";*/

const char* _SBOT_json_M = "{\"brand\":\"SwitchBot\",\"model\":\"Outdoor Meter\",\"model_id\":\"W340001X\",\"tag\":\"0100\",\"condition\":[\"manufacturerdata\",\"=\",28,\"&\",\"name\",\"index\",0,\"WoIOSensorTH\"],\"properties\":{\".cal\":{\"decoder\":[\"value_from_hex_data\",\"manufacturerdata\",21,1,false,false],\"post_proc\":[\"/\",10]},\"tempc\":{\"condition\":[\"manufacturerdata\",22,\"bit\",3,0],\"decoder\":[\"value_from_hex_data\",\"manufacturerdata\",22,2,true,false],\"post_proc\":[\"+\",\".cal\",\"*\",-1]},\"_tempc\":{\"condition\":[\"manufacturerdata\",22,\"bit\",3,1],\"decoder\":[\"value_from_hex_data\",\"manufacturerdata\",22,2,true,false],\"post_proc\":[\"+\",\".cal\",\"-\",128]},\"hum\":{\"decoder\":[\"value_from_hex_data\",\"manufacturerdata\",24,2,false,false],\"post_proc\":[\"&\",127]},\"mac\":{\"decoder\":[\"mac_from_hex_data\",\"manufacturerdata\",4]}}}";
/*R""""(
{
"brand":"SwitchBot",
"model":"Outdoor Meter",
"model_id":"W340001X",
"tag":"0100",
"condition":["manufacturerdata", "=", 28, "&", "name", "index", 0, "WoIOSensorTH"],
"properties":{
".cal":{
"decoder":["value_from_hex_data", "manufacturerdata", 21, 1, false, false],
"post_proc":["/", 10]
},
"tempc":{
"condition":["manufacturerdata", 22, "bit", 3, 0],
"decoder":["value_from_hex_data", "manufacturerdata", 22, 2, true, false],
"post_proc":["+", ".cal", "*", -1]
},
"_tempc":{
"condition":["manufacturerdata", 22, "bit", 3, 1],
"decoder":["value_from_hex_data", "manufacturerdata", 22, 2, true, false],
"post_proc":["+", ".cal", "-", 128]
},
"hum":{
"decoder":["value_from_hex_data", "manufacturerdata", 24, 2, false, false],
"post_proc":["&", 127]
},
"mac":{
"decoder":["mac_from_hex_data", "manufacturerdata", 4]
}
}
})"""";*/

const char* _SBOT_json_S = "{\"brand\":\"SwitchBot\",\"model\":\"Outdoor Meter\",\"model_id\":\"W340001X\",\"tag\":\"0100\",\"condition\":[\"servicedata\",\"=\",6,\"index\",0,\"77\",\"&\",\"name\",\"index\",0,\"WoIOSensorTH\"],\"properties\":{\"batt\":{\"decoder\":[\"value_from_hex_data\",\"servicedata\",4,2,false,false],\"post_proc\":[\"&\",127]}}}";
/*R""""(
{
"brand":"SwitchBot",
"model":"Outdoor Meter",
"model_id":"W340001X",
"tag":"0100",
"condition":["servicedata", "=", 6, "index", 0, "77", "&", "name", "index", 0, "WoIOSensorTH"],
"properties":{
"batt":{
"decoder":["value_from_hex_data", "servicedata", 4, 2, false, false],
"post_proc":["&", 127]
}
}
})"""";*/

const char* _SBOT_json_props = _common_BTHM_props;
6 changes: 6 additions & 0 deletions tests/BLE/test_ble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ const char* expected_mfg[] = {
"{\"brand\":\"Onset\",\"model\":\"Hobo Water Level Sensor\",\"model_id\":\"HOBOMX2001\",\"type\":\"UNIQ\",\"lvl_cm\":6.646526605,\"lvl_in\":2.616742758}",
"{\"brand\":\"Onset\",\"model\":\"Hobo Water Level Sensor\",\"model_id\":\"HOBOMX2001\",\"type\":\"UNIQ\",\"lvl_cm\":8.46760273,\"lvl_in\":3.333701862}",
"{\"brand\":\"Onset\",\"model\":\"Hobo Water Level Sensor\",\"model_id\":\"HOBOMX2001\",\"type\":\"UNIQ\",\"lvl_cm\":9.514185786,\"lvl_in\":3.745742436}",
"{\"brand\":\"SwitchBot\",\"model\":\"Outdoor Meter\",\"model_id\":\"W340001X\",\"type\":\"THB\",\"tempc\":25.5,\"tempf\":77.9,\"hum\":50,\"mac\":\"AA:BB:CC:DD:EE:FF\"}",
};

const char* expected_name_uuid_mfgsvcdata[] = {
Expand Down Expand Up @@ -256,6 +257,7 @@ const char* expected_uuid_name_svcdata[] = {
"{\"brand\":\"Sensor Easy\",\"model\":\"SE TEMP PROBE\",\"model_id\":\"SE_TPROBE\",\"type\":\"THB\",\"tempc\":20.7,\"tempf\":69.26}",
"{\"brand\":\"Sensor Easy\",\"model\":\"SE MAG\",\"model_id\":\"SE_MAG\",\"type\":\"CTMO\",\"open\":true,\"cont\":true}",
"{\"brand\":\"Sensor Easy\",\"model\":\"SE MAG\",\"model_id\":\"SE_MAG\",\"type\":\"CTMO\",\"open\":false,\"cont\":true}",
"{\"brand\":\"SwitchBot\",\"model\":\"Outdoor Meter\",\"model_id\":\"W340001X\",\"type\":\"THB\",\"batt\":65}",
};

const char* expected_uuid[] = {
Expand Down Expand Up @@ -611,6 +613,7 @@ const char* test_mfgdata[][3] = {
{"Hobo Water Level", "", "c500073fd54f01062402000008005235019ff11e883d"},
{"Hobo Water Level", "", "c500073fd54f0106240000000800529501a0a06aad3d"},
{"Hobo Water Level", "", "c500073fd54f010624000000080092a901a0bcd9c23d"},
{"SwitchBot Outdoor Meter Manufacturerdata", "WoIOSensorTH", "6909aabbccddeeff8b0305993200"},
};

TheengsDecoder::BLE_ID_NUM test_mfgdata_id_num[]{
Expand Down Expand Up @@ -761,6 +764,7 @@ TheengsDecoder::BLE_ID_NUM test_mfgdata_id_num[]{
TheengsDecoder::BLE_ID_NUM::HOBOMX2001,
TheengsDecoder::BLE_ID_NUM::HOBOMX2001,
TheengsDecoder::BLE_ID_NUM::HOBOMX2001,
TheengsDecoder::BLE_ID_NUM::SBOT_M,
};

// uuid test input [test name] [device name] [uuid] [manufacturer data] [service data]
Expand Down Expand Up @@ -900,6 +904,7 @@ const char* test_uuid_name_svcdata[][4] = {
{"SE TEMP PROBE temp","0x2a6e","P TPROBE 111999","1608"},
{"SE MAG Open","0x2a06","P MAG CCCCCC","2400"},
{"SE MAG Closed","0x2a06","P MAG CCCCCC","2900"},
{"SwitchBot Outdoor Meter Servicdata", "0xfd3d", "WoIOSensorTH", "770041"},
};

TheengsDecoder::BLE_ID_NUM test_uuid_name_svcdata_id_num[]{
Expand Down Expand Up @@ -942,6 +947,7 @@ TheengsDecoder::BLE_ID_NUM test_uuid_name_svcdata_id_num[]{
TheengsDecoder::BLE_ID_NUM::SE_TPROBE,
TheengsDecoder::BLE_ID_NUM::SE_MAG,
TheengsDecoder::BLE_ID_NUM::SE_MAG,
TheengsDecoder::BLE_ID_NUM::SBOT_S,
};

// uuid test input [test name] [uuid] [data source] [data]
Expand Down
Loading