|
@@ -40,7 +40,7 @@ class sispmctl(object):
|
40
|
40
|
try:
|
41
|
41
|
out_txt = subprocess.check_output(["sudo", "sispmctl", "-o" if state == True else "-f", output]).decode('UTF-8')
|
42
|
42
|
except subprocess.CalledProcessError as grepexc:
|
43
|
|
- logger.error("sispm error code %d", grepexc.returncode)
|
|
43
|
+ logger.error("sispm error code %d while changing state of channel %s", grepexc.returncode, output)
|
44
|
44
|
else:
|
45
|
45
|
logger.info('sispmctl channel %s changed to %s', output, state)
|
46
|
46
|
self.publish_states()
|
|
@@ -53,15 +53,19 @@ class sispmctl(object):
|
53
|
53
|
self.set_out_state(output, not self.__state__[int(output) - 1])
|
54
|
54
|
|
55
|
55
|
def get_out_states(self):
|
56
|
|
- try:
|
57
|
|
- out_txt = subprocess.check_output(["sudo", "sispmctl", "-g", "all"])
|
58
|
|
- except subprocess.CalledProcessError as grepexc:
|
59
|
|
- logger.error("sispm error code %d", grepexc.returncode)
|
60
|
|
- else:
|
61
|
|
- rv = []
|
62
|
|
- for i in range(1, 5):
|
63
|
|
- rv.append(out_txt.decode("UTF-8").split("\n")[i].split("\t")[1] == "on")
|
64
|
|
- return rv
|
|
56
|
+ i = 0
|
|
57
|
+ while i < 10: # number of tries
|
|
58
|
+ try:
|
|
59
|
+ out_txt = subprocess.check_output(["sudo", "sispmctl", "-g", "all"])
|
|
60
|
+ except subprocess.CalledProcessError as grepexc:
|
|
61
|
+ logger.error("sispm error code %d while getting states", grepexc.returncode)
|
|
62
|
+ else:
|
|
63
|
+ rv = []
|
|
64
|
+ for i in range(1, 5):
|
|
65
|
+ rv.append(out_txt.decode("UTF-8").split("\n")[i].split("\t")[1] == "on")
|
|
66
|
+ return rv
|
|
67
|
+ logger.warning("Could not get state of powerplugs")
|
|
68
|
+ return self.__state__
|
65
|
69
|
|
66
|
70
|
def publish_states(self):
|
67
|
71
|
self.__state__ = self.get_out_states()
|
|
@@ -70,11 +74,11 @@ class sispmctl(object):
|
70
|
74
|
|
71
|
75
|
def send_state(self, output):
|
72
|
76
|
topic = config.MQTT_TOPIC + "/status/" + str(output)
|
73
|
|
- logger.info("Sending Powerplug status information of plug %s to mqtt %s = %s", str(output), topic, str(self.__state__[output - 1]))
|
|
77
|
+ logger.debug("Sending Powerplug status information of plug %s to mqtt %s = %s", str(output), topic, str(self.__state__[output - 1]))
|
74
|
78
|
try:
|
75
|
79
|
self.__mqtt_client__.send(topic, "true" if self.__state__[output - 1] else "false")
|
76
|
80
|
except (socket.timeout, OSError) as e:
|
77
|
|
- logger.warning("Erro while sending state information information")
|
|
81
|
+ logger.warning("Error while sending state information via mqtt")
|
78
|
82
|
|
79
|
83
|
|
80
|
84
|
class mqtt_powerplug(mqtt.mqtt_client):
|