From a6482ba92d9ebb8e217ae29226bcc5bd14240853 Mon Sep 17 00:00:00 2001 From: Ivan Belokobylskiy Date: Wed, 3 May 2023 10:38:29 +0200 Subject: [PATCH] Make `ssl` module optional --- README.md | 7 +++++++ lumimqtt/lumimqtt.py | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6106c09..cddccea 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,13 @@ changes `light_transition_period` value in seconds to set default transition for light switching or light change. Use `0` to remove the transition. + +### SSL connection + +To use SSL connection, you need to set `mqtt_cert` and `mqtt_key`, and optional `mqtt_ca` with corresponding paths to files. + +### Custom sensors + You can also use GPIO(s) as binary sensor(s). Add this to configuration: ```json diff --git a/lumimqtt/lumimqtt.py b/lumimqtt/lumimqtt.py index b42f485..d7ce81b 100644 --- a/lumimqtt/lumimqtt.py +++ b/lumimqtt/lumimqtt.py @@ -9,7 +9,6 @@ from dataclasses import dataclass from datetime import datetime -import ssl import aio_mqtt from .__version__ import version @@ -474,6 +473,8 @@ async def _connect_forever(self) -> None: client_id = f'lumimqtt_{self.dev_id}' context = None if self._mqtt_cert is not None and self._mqtt_key is not None: + import ssl + context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2) if self._mqtt_ca is not None: context.load_verify_locations(self._mqtt_ca)