瀏覽代碼

Usage of mqtt app_name for client instance + no switch off on init

master
Dirk Alders 2 年之前
父節點
當前提交
e8334669e8
共有 1 個文件被更改,包括 2 次插入9 次删除
  1. 2
    9
      powerplug.py

+ 2
- 9
powerplug.py 查看文件

@@ -1,6 +1,6 @@
1 1
 import config
2 2
 import logging
3
-import paho.mqtt.client as mqtt
3
+import paho.mqtt.client as paho
4 4
 import report
5 5
 import socket
6 6
 import subprocess
@@ -19,14 +19,7 @@ class sispmctl(object):
19 19
     def __init__(self, mqtt_client):
20 20
         logger.info("Starting sispmctl module...")
21 21
         self.__mqtt_client__ = mqtt_client
22
-        self.__state__ = [False, False, False, False]
23 22
         self.__state_requests__ = [{}, {}, {}, {}]
24
-        try:
25
-            out_txt = subprocess.check_output(["sudo", "sispmctl", "-f", "all"]).decode('UTF-8')
26
-        except subprocess.CalledProcessError as grepexc:                                                                                                   
27
-            logger.error("sispm error code %d", grepexc.returncode)
28
-        else:
29
-            logger.info('sispmctl all channels switched off')
30 23
         self.publish_states()
31 24
 
32 25
     def __filter_output_parameter__(self, output):
@@ -99,7 +92,7 @@ class mqtt_powerplug(object):
99 92
     ]
100 93
 
101 94
     def __init__(self):
102
-        self.__client__ = mqtt.Client("mqtt_powerplug")                         # create client object
95
+        self.__client__ = paho.Client(config.APP_NAME)                          # create client object
103 96
         self.__client__.on_message = self.__receive__                           # attach function to callback
104 97
         self.__client__.username_pw_set(config.MQTT_USER, config.MQTT_PASS)     # login with credentials
105 98
         try:

Loading…
取消
儲存