diff --git a/custom_components/hunterdouglas_powerview_ble/api.py b/custom_components/hunterdouglas_powerview_ble/api.py index 3567b3c..5f7db06 100644 --- a/custom_components/hunterdouglas_powerview_ble/api.py +++ b/custom_components/hunterdouglas_powerview_ble/api.py @@ -95,6 +95,7 @@ class PowerViewBLE: self._info: PVDeviceInfo = PVDeviceInfo() self._cmd_lock: Final = asyncio.Lock() self._cmd_next = None + self._is_encrypted: bool = False self._cipher: Final = ( Cipher(algorithms.AES(home_key), modes.CTR(bytearray(16))) if len(home_key) == 16 @@ -105,6 +106,15 @@ class PowerViewBLE: await self._data_event.wait() self._data_event.clear() + @property + def encrypted(self) -> bool: + """Return whether communication with this shade is encrypted.""" + return self._is_encrypted + + @encrypted.setter + def encrypted(self, value:bool) -> None: + self._is_encrypted = value + @property def info(self) -> PVDeviceInfo: """Return device information, e.g. SW version.""" @@ -135,7 +145,7 @@ class PowerViewBLE: ) + cmd_run[1] ) - if self._cipher is not None: + if self._cipher is not None and self._is_encrypted: enc = self._cipher.encryptor() tx_data = enc.update(tx_data) + enc.finalize() self._data_event.clear() @@ -224,7 +234,7 @@ class PowerViewBLE: def _verify_response(self, din: bytearray, seq_nr: int, cmd: ShadeCmd) -> bool: """Verify shade response data.""" data: bytearray = din - if self._cipher is not None: + if self._cipher is not None and self._is_encrypted: dec = self._cipher.decryptor() data = bytearray(dec.update(din) + dec.finalize()) if len(data) < 4: diff --git a/custom_components/hunterdouglas_powerview_ble/coordinator.py b/custom_components/hunterdouglas_powerview_ble/coordinator.py index 35a526d..f283fe7 100644 --- a/custom_components/hunterdouglas_powerview_ble/coordinator.py +++ b/custom_components/hunterdouglas_powerview_ble/coordinator.py @@ -103,6 +103,7 @@ class PVCoordinator(PassiveBluetoothDataUpdateCoordinator): bytearray(service_info.manufacturer_data.get(2073, b"")) ) ) + self.api.encrypted = bool(self.data.get("home_id")) LOGGER.debug("data sample %s", self.data) super()._async_handle_bluetooth_event(service_info, change) diff --git a/custom_components/hunterdouglas_powerview_ble/manifest.json b/custom_components/hunterdouglas_powerview_ble/manifest.json index 4011766..4bbb5b3 100644 --- a/custom_components/hunterdouglas_powerview_ble/manifest.json +++ b/custom_components/hunterdouglas_powerview_ble/manifest.json @@ -17,5 +17,5 @@ "issue_tracker": "https://github.com/patman15/hdpv_ble/issues", "loggers": ["hunterdouglas_powerview_ble"], "requirements": ["cryptography>=43.0.0"], - "version": "0.21" + "version": "0.22" }