Browse Source

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

master
Dirk Alders 2 years ago
parent
commit
e8334669e8
1 changed files with 2 additions and 9 deletions
  1. 2
    9
      powerplug.py

+ 2
- 9
powerplug.py View File

1
 import config
1
 import config
2
 import logging
2
 import logging
3
-import paho.mqtt.client as mqtt
3
+import paho.mqtt.client as paho
4
 import report
4
 import report
5
 import socket
5
 import socket
6
 import subprocess
6
 import subprocess
19
     def __init__(self, mqtt_client):
19
     def __init__(self, mqtt_client):
20
         logger.info("Starting sispmctl module...")
20
         logger.info("Starting sispmctl module...")
21
         self.__mqtt_client__ = mqtt_client
21
         self.__mqtt_client__ = mqtt_client
22
-        self.__state__ = [False, False, False, False]
23
         self.__state_requests__ = [{}, {}, {}, {}]
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
         self.publish_states()
23
         self.publish_states()
31
 
24
 
32
     def __filter_output_parameter__(self, output):
25
     def __filter_output_parameter__(self, output):
99
     ]
92
     ]
100
 
93
 
101
     def __init__(self):
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
         self.__client__.on_message = self.__receive__                           # attach function to callback
96
         self.__client__.on_message = self.__receive__                           # attach function to callback
104
         self.__client__.username_pw_set(config.MQTT_USER, config.MQTT_PASS)     # login with credentials
97
         self.__client__.username_pw_set(config.MQTT_USER, config.MQTT_PASS)     # login with credentials
105
         try:
98
         try:

Loading…
Cancel
Save