Skip to content

Commit

Permalink
Add support for decrypting ShellyBLU Door/Window advertisements (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
koenvervloesem committed Jul 26, 2023
1 parent b8c9e4c commit 7b82367
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
9 changes: 5 additions & 4 deletions TheengsGateway/decryption.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ def replace_encrypted_data(
data_json["servicedata"] = decrypted_data.hex()


class ShellyBLUButton1Decryptor(AdvertisementDecryptor):
"""Class for decryption of ShellyBLU Button1 encrypted advertisements."""
class BTHomeV2Decryptor(AdvertisementDecryptor):
"""Class for decryption of BTHome v2 encrypted advertisements."""

def compute_nonce(self, address: str, decoded_json: Dict) -> bytes:
"""Compute the nonce for a specific address and JSON input."""
Expand Down Expand Up @@ -122,7 +122,8 @@ def replace_encrypted_data(

_DECRYPTOR_MODELS = {
"LYWSD03MMC/MJWSD05MMC_PVVX_ENCR": LYWSD03MMC_PVVXDecryptor,
"SBBT_002C_ENCR": ShellyBLUButton1Decryptor,
"SBBT_002C_ENCR": BTHomeV2Decryptor,
"SBDW_002C_ENCR": BTHomeV2Decryptor,
}


Expand All @@ -134,7 +135,7 @@ def create_decryptor(model_id: str) -> AdvertisementDecryptor:
"""Return the decryptor class for the given model ID."""
if model_id not in _DECRYPTOR_MODELS:
raise UnsupportedEncryptionError()
return _DECRYPTOR_MODELS[model_id]()
return _DECRYPTOR_MODELS[model_id]() # type: ignore[abstract]


def reverse_address(address: str) -> str:
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ include = 'TheengsGateway\/.*\.pyi?$'
[[tool.mypy.overrides]]
module = [
"Cryptodome.Cipher",
"Cryptodome.Cipher.AES",
"paho.mqtt",
"setuptools",
"TheengsDecoder",
Expand Down

0 comments on commit 7b82367

Please sign in to comment.