Skip to content

Commit

Permalink
Make MQTT port configurable
Browse files Browse the repository at this point in the history
Start work on #91

Signed-off-by: Joe Block <jpb@unixorn.net>
  • Loading branch information
unixorn committed May 21, 2023
1 parent 70127b1 commit 2f2d5c9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions ha_mqtt_discoverable/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@ class MQTT(BaseModel):
tls_certfile: Optional[str] = None
tls_ca_cert: Optional[str] = None

mqtt_port: int = 1883
discovery_prefix: str = "homeassistant"
"""The root of the topic tree where HA is listening for messages"""
state_prefix: str = "hmd"
Expand Down
1 change: 1 addition & 0 deletions ha_mqtt_discoverable/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def create_base_parser(description: str = "Base parser"):
)
parser.add_argument("--mqtt-user", type=str, help="MQTT user.")
parser.add_argument("--mqtt-password", type=str, help="MQTT password.")
parser.add_argument("--mqtt-port", type=str, help="MQTT port.", default=1883)
parser.add_argument("--mqtt-server", type=str, help="MQTT server.")
parser.add_argument("--settings-file", type=str, help="Settings file.")

Expand Down
5 changes: 5 additions & 0 deletions ha_mqtt_discoverable/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def load_mqtt_settings(path: str = None, cli=None) -> dict:
settings["device_id"] = cli.device_id
settings["device_name"] = cli.device_name
settings["mqtt_password"] = cli.mqtt_password
settings["mqtt_port"] = cli.mqtt_port
settings["mqtt_prefix"] = cli.mqtt_prefix
settings["mqtt_server"] = cli.mqtt_server
settings["mqtt_user"] = cli.mqtt_user
Expand Down Expand Up @@ -71,6 +72,8 @@ def load_mqtt_settings(path: str = None, cli=None) -> dict:
raise RuntimeError("No device_id was specified")
if "device_name" not in settings:
raise RuntimeError("No device_name was specified")
if "mqtt_port" not in settings:
raise RuntimeError("You need to specify an mqtt port")
if "mqtt_prefix" not in settings:
raise RuntimeError("You need to specify an mqtt prefix")
if "mqtt_user" not in settings:
Expand Down Expand Up @@ -115,6 +118,8 @@ def sensor_delete_settings(path: str = None, cli=None) -> dict:
raise RuntimeError("No device_id was specified")
if "device_name" not in settings:
raise RuntimeError("No device_name was specified")
if "mqtt_port" not in settings:
raise RuntimeError("You need to specify an mqtt port")
if "mqtt_prefix" not in settings:
raise RuntimeError("You need to specify an mqtt prefix")
if "mqtt_user" not in settings:
Expand Down

0 comments on commit 2f2d5c9

Please sign in to comment.