浏览代码

mark units unknown on shutdown

NMS Indium 8 月之前
父节点
当前提交
c6d3f86cb7
共有 1 个文件被更改,包括 8 次插入8 次删除
  1. 8 8
      systemctl_mqtt/__init__.py

+ 8 - 8
systemctl_mqtt/__init__.py

@@ -15,7 +15,7 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
 
-print("nathan's version")
+print("nathan's version 3")
 
 import abc
 import argparse
@@ -493,13 +493,6 @@ async def _run(  # pylint: disable=too-many-arguments
         await state.publish_homeassistant_device_config(mqtt_client=mqtt_client)
         await state.publish_preparing_for_shutdown(mqtt_client=mqtt_client)
         try:
-            # Clear unit/system. Prevents retained messages getting "stuck" if command changes
-            await mqtt_client.publish(
-                topic=state.mqtt_topic_prefix + "/unit/system/",
-                payload="",
-                retain=True,
-            )
-            
             await mqtt_client.publish(
                 topic=state.mqtt_availability_topic,
                 payload=_MQTT_PAYLOAD_AVAILABLE,
@@ -518,6 +511,13 @@ async def _run(  # pylint: disable=too-many-arguments
                 payload=_MQTT_PAYLOAD_NOT_AVAILABLE,
                 retain=True,
             )
+            
+            for monitored_system_unit in state.monitored_system_unit_names:
+                await mqtt_client.publish(
+                    topic=state.get_system_unit_active_state_mqtt_topic(unit_name=monitored_system_unit),
+                    payload="unknown",
+                    retain=True,
+                )
 
 
 def _main() -> None: