Skip to content

Commit

Permalink
Added user/password auth to mqtt connection
Browse files Browse the repository at this point in the history
  • Loading branch information
brownjl authored and trickeydan committed Sep 18, 2021
1 parent 3fc7bda commit 24310e9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ port = 1883
enable_tls = false
force_protocol_version_3_1 = true

enable_auth = false
username = ""
password = ""

topic_prefix = "hue2mqtt"

[hue]
Expand Down
3 changes: 3 additions & 0 deletions hue2mqtt/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class MQTTBrokerInfo(BaseModel):

host: str
port: int
enable_auth: bool = False
username: str = ""
password: str = ""
enable_tls: bool = False
topic_prefix: str = "hue2mqtt"
force_protocol_version_3_1: bool = False
Expand Down
4 changes: 4 additions & 0 deletions hue2mqtt/mqtt/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ async def connect(self) -> None:
if self._broker_info.force_protocol_version_3_1:
mqtt_version = gmqtt.constants.MQTTv311

if self._broker_info.enable_auth:
LOGGER.debug("MQTT Auth enabled")
self._client.set_auth_credentials(self._broker_info.username,self._broker_info.password)

await self._client.connect(
self._broker_info.host,
port=self._broker_info.port,
Expand Down

0 comments on commit 24310e9

Please sign in to comment.