Skip to content

Commit

Permalink
Add support for ShellyBLU Wall Switch4 and RC Button4 devices (#564)
Browse files Browse the repository at this point in the history
* Add support for ShellyBLU Wall Switch4 and RC Button4 devices

- Added documentation for ShellyBLU Wall Switch4 (SBBT-004CEU) and RC Button4 (SBBT-004CUS).
- Included JSON definitions and properties for SBBT-004CEU and SBBT-004CUS devices.
- Updated `devices.h` and `decoder.h` to include new device models and their encrypted versions.
- Added test cases for ShellyBLU RC Button4 in `test_ble.cpp`.

* Fix unit tests for SBBT_002C functionality in test_ble.cpp

* Fix unit tests in test_ble.cpp

* Fix unit tests in test_ble.cpp

* Fix unit tests for SBBT_002C functionality in test_ble.cpp

* Fix unit tests for SBBT_002C functionality in test_ble.cpp

* Update device JSON configurations and properties

- Modify `SBBT_004CEU_json.h` to update the model name from "SBBT-004CEU" to "SBBT-EU".
- Modify `SBBT_004CUS_json.h` to update the model name from "SBBT-US76d2" to "SBBT-US".
- Modify `SBBT_004CEU_ENCR_json.h` to update the model name from "SBBT-004CEU" to "SBBT-EU".
- Modify `SBBT_004CUS_ENCR_json.h` to update the model name from "SBBT-US76d2" to "SBBT-US".
- Ensure consistency in JSON property definitions across all device headers.

* Add unit tests for BLE functionality in test_ble.cpp

* Fix copy paste error in test_ble.cpp

* Refactor JSON definitions for SBBT-004CEU and SBBT-004CUS devices to improve readability and maintainability.

* Refactor JSON definitions for SBBT-004CEU and SBBT-004CUS devices to improve readability and maintainability.

* Refactor JSON definitions for SBBT-004CEU and SBBT-004CUS devices to improve readability and maintainability.

* Refactor JSON definitions for SBBT-004CEU and SBBT-004CUS devices to improve readability and maintainability.

* Add support for ShellyBLU Switch4 (SBBT-004CEU/US) and update documentation

- Added new device definition for ShellyBLU Switch4 (SBBT-004CEU/US) in `src/devices/SBBT_004CEU_US_json.h`.
- Updated `docs/devices/SBBT-004CEU.md` and `docs/devices/SBBT-004CUS.md` to indicate support for unencrypted devices only.
- Removed obsolete device definitions: `SBBT_004CEU_ENCR_json.h`, `SBBT_004CUS_ENCR_json.h`, `SBBT_004CEU_json.h`, and `SBBT_004CUS_json.h`.
- Updated `src/devices.h` and `src/decoder.h` to reflect the new device support and clean up unused includes.

* add json string to device

* fix tests

* fix tests

* fix tests

* fix tests

* fix tests

---------

Co-authored-by: Lars <[email protected]>
  • Loading branch information
larswnd and Lars authored Oct 15, 2024
1 parent fbc16b8 commit 6087438
Show file tree
Hide file tree
Showing 6 changed files with 305 additions and 2 deletions.
23 changes: 23 additions & 0 deletions docs/devices/SBBT-004CEU.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# ShellyBLU Wall Switcht4

|Model Id|[SBBT-004CEU](https://github.com/theengs/decoder/blob/development/src/devices/SBBT_004CEU_json.h)|
|-|-|
|Brand|Shelly|
|Model|ShellyBLU Wall Switch4|
|Short Description|Button|
|Communication|BLE broadcast|
|Frequency|2.4Ghz|
|Power Source|CR2032|
|Exchanged Data|button press type of each button, battery, packet ID|
|Encrypted|Yes/No - Optional|

Currently only unencrypted devices are supported.

The button press type for each button is encoded as:

* 0 - None (other Button was pressed or sent every 8 seconds if beacon mode is enabled)
* 1 - Single short click
* 2 - Double click
* 3 - Triple click
* 9 - Long press
* 11 - Button hold
23 changes: 23 additions & 0 deletions docs/devices/SBBT-004CUS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# ShellyBLU RC Button4

|Model Id|[SBBT-004CUS](https://github.com/theengs/decoder/blob/development/src/devices/SBBT_004CUS_json.h)|
|-|-|
|Brand|Shelly|
|Model|ShellyBLU RC Button4|
|Short Description|Button|
|Communication|BLE broadcast|
|Frequency|2.4Ghz|
|Power Source|CR2032|
|Exchanged Data|button press type of each button, battery, packet ID|
|Encrypted|Yes/No - Optional|

Currently only unencrypted devices are supported.

The button press type for each button is encoded as:

* 0 - None (other Button was pressed or sent every 8 seconds if beacon mode is enabled)
* 1 - Single short click
* 2 - Double click
* 3 - Triple click
* 9 - Long press
* 11 - Button hold
1 change: 1 addition & 0 deletions src/decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ class TheengsDecoder {
SE_MAG,
SBBT_002C,
SBBT_002C_ENCR,
SBBT_004CEU_US,
SBDW_002C,
SBDW_002C_ENCR,
SBMO_003Z,
Expand Down
2 changes: 2 additions & 0 deletions src/devices.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
#include "devices/SE_MAG_json.h"
#include "devices/SBBT_002C_json.h"
#include "devices/SBBT_002C_ENCR_json.h"
#include "devices/SBBT_004CEU_US_json.h"
#include "devices/SBDW_002C_json.h"
#include "devices/SBDW_002C_ENCR_json.h"
#include "devices/SBMO_003Z_json.h"
Expand Down Expand Up @@ -238,6 +239,7 @@ const char* _devices[][2] = {
{_SE_MAG_json, _SE_MAG_json_props},
{_SBBT_002C_json, _SBBT_002C_json_props},
{_SBBT_002C_ENCR_json, _SBBT_002C_ENCR_json_props},
{_SBBT_004CEU_US_json, _SBBT_004CEU_US_json_props},
{_SBDW_002C_json, _SBDW_002C_json_props},
{_SBDW_002C_ENCR_json, _SBDW_002C_ENCR_json_props},
{_SBMO_003Z_json, _SBMO_003Z_json_props},
Expand Down
98 changes: 98 additions & 0 deletions src/devices/SBBT_004CEU_US_json.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
const char* _SBBT_004CEU_US_json = "{\"brand\":\"Shelly\",\"model\":\"ShellyBLU Switch4\",\"model_id\":\"SBBT-004CEU/US\",\"tag\":\"1106\",\"condition\":[\"servicedata\",\"=\",26,\"index\",0,\"40\",\"|\",\"servicedata\",\"=\",26,\"index\",0,\"44\",\"&\",\"uuid\",\"index\",0,\"fcd2\",\"&\",\"name\",\"index\",0,\"SBBT-\"],\"properties\":{\"packet\":{\"condition\":[\"servicedata\",2,\"00\"],\"decoder\":[\"value_from_hex_data\",\"servicedata\",4,2,false,false]},\"batt\":{\"condition\":[\"servicedata\",6,\"01\"],\"decoder\":[\"value_from_hex_data\",\"servicedata\",8,2,false,false]},\"button1\":{\"condition\":[\"servicedata\",10,\"3a\"],\"decoder\":[\"string_from_hex_data\",\"servicedata\",12,2],\"lookup\":[\"00\",0,\"01\",1,\"02\",2,\"03\",3,\"04\",9,\"fe\",11]},\"button2\":{\"condition\":[\"servicedata\",14,\"3a\"],\"decoder\":[\"string_from_hex_data\",\"servicedata\",16,2],\"lookup\":[\"00\",0,\"01\",1,\"02\",2,\"03\",3,\"04\",9,\"fe\",11]},\"button3\":{\"condition\":[\"servicedata\",18,\"3a\"],\"decoder\":[\"string_from_hex_data\",\"servicedata\",20,2],\"lookup\":[\"00\",0,\"01\",1,\"02\",2,\"03\",3,\"04\",9,\"fe\",11]},\"button4\":{\"condition\":[\"servicedata\",22,\"3a\"],\"decoder\":[\"string_from_hex_data\",\"servicedata\",24,2],\"lookup\":[\"00\",0,\"01\",1,\"02\",2,\"03\",3,\"04\",9,\"fe\",11]},\"mac\":{\"condition\":[\"manufacturerdata\",\"=\",30],\"decoder\":[\"revmac_from_hex_data\",\"manufacturerdata\",18]}}}";
/*R""""(
{
"brand":"Shelly",
"model":"ShellyBLU Switch4",
"model_id":"SBBT-004CEU/US",
"tag":"1106",
"condition":["servicedata", "=", 26, "index", 0, "40", "|", "servicedata", "=", 26, "index", 0, "44", "&", "uuid", "index", 0, "fcd2", "&", "name", "index", 0, "SBBT-"],
"properties":{
"packet":{
"condition":["servicedata", 2, "00"],
"decoder":["value_from_hex_data", "servicedata", 4, 2, false, false]
},
"batt":{
"condition":["servicedata", 6, "01"],
"decoder":["value_from_hex_data", "servicedata", 8, 2, false, false]
},
"button1":{
"condition":["servicedata", 10, "3a"],
"decoder":["string_from_hex_data", "servicedata", 12, 2],
"lookup":["00", 0,
"01", 1,
"02", 2,
"03", 3,
"04", 9,
"fe", 11]
},
"button2":{
"condition":["servicedata", 14, "3a"],
"decoder":["string_from_hex_data", "servicedata", 16, 2],
"lookup":["00", 0,
"01", 1,
"02", 2,
"03", 3,
"04", 9,
"fe", 11]
},
"button3":{
"condition":["servicedata", 18, "3a"],
"decoder":["string_from_hex_data", "servicedata", 20, 2],
"lookup":["00", 0,
"01", 1,
"02", 2,
"03", 3,
"04", 9,
"fe", 11]
},
"button4":{
"condition":["servicedata", 22, "3a"],
"decoder":["string_from_hex_data", "servicedata", 24, 2],
"lookup":["00", 0,
"01", 1,
"02", 2,
"03", 3,
"04", 9,
"fe", 11]
},
"mac":{
"condition":["manufacturerdata", "=", 30],
"decoder":["revmac_from_hex_data", "manufacturerdata", 18]
}
}
})"""";*/

const char* _SBBT_004CEU_US_json_props = "{\"properties\":{\"packet\":{\"unit\":\"int\",\"name\":\"packet id\"},\"batt\":{\"unit\":\"%\",\"name\":\"battery\"},\"button1\":{\"unit\":\"int\",\"name\":\"button1 press type\"},\"button2\":{\"unit\":\"int\",\"name\":\"button2 press type\"},\"button3\":{\"unit\":\"int\",\"name\":\"button3 press type\"},\"button4\":{\"unit\":\"int\",\"name\":\"button4 press type\"},\"mac\":{\"unit\":\"string\",\"name\":\"MAC address\"}}}";
/*R""""(
{
"properties":{
"packet":{
"unit":"int",
"name":"packet id"
},
"batt":{
"unit":"%",
"name":"battery"
},
"button1":{
"unit":"int",
"name":"button1 press type"
},
"button2":{
"unit":"int",
"name":"button2 press type"
},
"button3":{
"unit":"int",
"name":"button3 press type"
},
"button4":{
"unit":"int",
"name":"button4 press type"
},
"mac":{
"unit":"string",
"name":"MAC address"
}
}
})"""";*/
Loading

0 comments on commit 6087438

Please sign in to comment.