Skip to content

Commit

Permalink
fix: move to more static Home Assistant topic names
Browse files Browse the repository at this point in the history
  • Loading branch information
dchesterton committed Dec 31, 2021
1 parent f10c04b commit cfa7b00
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/amcrest2mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def signal_handler(sig, frame):
"storage_used": f"amcrest2mqtt/{serial_number}/storage/used",
"storage_used_percent": f"amcrest2mqtt/{serial_number}/storage/used_percent",
"storage_total": f"amcrest2mqtt/{serial_number}/storage/total",
"home_assistant": {
"home_assistant_legacy": {
"doorbell": f"{home_assistant_prefix}/binary_sensor/amcrest2mqtt-{serial_number}/{device_slug}_doorbell/config",
"human": f"{home_assistant_prefix}/binary_sensor/amcrest2mqtt-{serial_number}/{device_slug}_human/config",
"motion": f"{home_assistant_prefix}/binary_sensor/amcrest2mqtt-{serial_number}/{device_slug}_motion/config",
Expand All @@ -197,6 +197,17 @@ def signal_handler(sig, frame):
"host": f"{home_assistant_prefix}/sensor/amcrest2mqtt-{serial_number}/{device_slug}_host/config",
"serial_number": f"{home_assistant_prefix}/sensor/amcrest2mqtt-{serial_number}/{device_slug}_serial_number/config",
},
"home_assistant": {
"doorbell": f"{home_assistant_prefix}/binary_sensor/amcrest2mqtt-{serial_number}/doorbell/config",
"human": f"{home_assistant_prefix}/binary_sensor/amcrest2mqtt-{serial_number}/human/config",
"motion": f"{home_assistant_prefix}/binary_sensor/amcrest2mqtt-{serial_number}/motion/config",
"storage_used": f"{home_assistant_prefix}/sensor/amcrest2mqtt-{serial_number}/storage_used/config",
"storage_used_percent": f"{home_assistant_prefix}/sensor/amcrest2mqtt-{serial_number}/storage_used_percent/config",
"storage_total": f"{home_assistant_prefix}/sensor/amcrest2mqtt-{serial_number}/storage_total/config",
"version": f"{home_assistant_prefix}/sensor/amcrest2mqtt-{serial_number}/version/config",
"host": f"{home_assistant_prefix}/sensor/amcrest2mqtt-{serial_number}/host/config",
"serial_number": f"{home_assistant_prefix}/sensor/amcrest2mqtt-{serial_number}/serial_number/config",
},
}

# Connect to MQTT
Expand Down Expand Up @@ -251,6 +262,7 @@ def signal_handler(sig, frame):
}

if is_doorbell:
mqtt_publish(topics["home_assistant_legacy"]["doorbell"], "")
mqtt_publish(
topics["home_assistant"]["doorbell"],
base_config
Expand All @@ -266,6 +278,7 @@ def signal_handler(sig, frame):
)

if is_ad410:
mqtt_publish(topics["home_assistant_legacy"]["human"], "")
mqtt_publish(
topics["home_assistant"]["human"],
base_config
Expand All @@ -280,6 +293,7 @@ def signal_handler(sig, frame):
json=True,
)

mqtt_publish(topics["home_assistant_legacy"]["motion"], "")
mqtt_publish(
topics["home_assistant"]["motion"],
base_config
Expand All @@ -294,6 +308,7 @@ def signal_handler(sig, frame):
json=True,
)

mqtt_publish(topics["home_assistant_legacy"]["version"], "")
mqtt_publish(
topics["home_assistant"]["version"],
base_config
Expand All @@ -309,6 +324,7 @@ def signal_handler(sig, frame):
json=True,
)

mqtt_publish(topics["home_assistant_legacy"]["serial_number"], "")
mqtt_publish(
topics["home_assistant"]["serial_number"],
base_config
Expand All @@ -324,6 +340,7 @@ def signal_handler(sig, frame):
json=True,
)

mqtt_publish(topics["home_assistant_legacy"]["host"], "")
mqtt_publish(
topics["home_assistant"]["host"],
base_config
Expand All @@ -340,6 +357,7 @@ def signal_handler(sig, frame):
)

if storage_poll_interval > 0:
mqtt_publish(topics["home_assistant_legacy"]["storage_used_percent"], "")
mqtt_publish(
topics["home_assistant"]["storage_used_percent"],
base_config
Expand All @@ -355,6 +373,7 @@ def signal_handler(sig, frame):
json=True,
)

mqtt_publish(topics["home_assistant_legacy"]["storage_used"], "")
mqtt_publish(
topics["home_assistant"]["storage_used"],
base_config
Expand All @@ -369,6 +388,7 @@ def signal_handler(sig, frame):
json=True,
)

mqtt_publish(topics["home_assistant_legacy"]["storage_total"], "")
mqtt_publish(
topics["home_assistant"]["storage_total"],
base_config
Expand Down

0 comments on commit cfa7b00

Please sign in to comment.