Fix whitespace errors to make pylint happy
This commit is contained in:
+6
-2
@@ -4,7 +4,7 @@ import threading
|
||||
import json
|
||||
import signal
|
||||
|
||||
#mine
|
||||
# mine
|
||||
import mqtt
|
||||
import yamlparser
|
||||
from xiaomihub import XiaomiHub
|
||||
@@ -12,6 +12,7 @@ from xiaomihub import XiaomiHub
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def process_gateway_messages(gateway, client, stop_event):
|
||||
while not stop_event.is_set():
|
||||
try:
|
||||
@@ -32,6 +33,7 @@ def process_gateway_messages(gateway, client, stop_event):
|
||||
_LOGGER.error('Error while sending from gateway to mqtt: ', str(e))
|
||||
_LOGGER.info("Stopping Gateway Thread ...")
|
||||
|
||||
|
||||
def read_motion_data(gateway, client, polling_interval, polling_models, stop_event):
|
||||
first = True
|
||||
while not stop_event.is_set():
|
||||
@@ -62,6 +64,7 @@ def read_motion_data(gateway, client, polling_interval, polling_models, stop_eve
|
||||
time.sleep(polling_interval)
|
||||
_LOGGER.info("Stopping Polling Thread ...")
|
||||
|
||||
|
||||
def process_mqtt_messages(gateway, client, stop_event):
|
||||
while not stop_event.is_set():
|
||||
try:
|
||||
@@ -79,6 +82,7 @@ def process_mqtt_messages(gateway, client, stop_event):
|
||||
_LOGGER.error('Error while sending from mqtt to gateway: ', str(e))
|
||||
_LOGGER.info("Stopping MQTT Thread ...")
|
||||
|
||||
|
||||
def exit_handler(signal, frame):
|
||||
print('Exiting')
|
||||
stop_event.set()
|
||||
@@ -102,7 +106,7 @@ if __name__ == "__main__":
|
||||
_LOGGER.info("Init mqtt client.")
|
||||
client = mqtt.Mqtt(config)
|
||||
client.connect()
|
||||
#only this devices can be controlled from MQTT
|
||||
# only this devices can be controlled from MQTT
|
||||
client.subscribe("gateway", "+", "+", "set")
|
||||
client.subscribe("gateway", "+", "write", None)
|
||||
client.subscribe("plug", "+", "status", "set")
|
||||
|
||||
+13
-12
@@ -6,6 +6,7 @@ import json
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Mqtt:
|
||||
event_based_sensors = ["switch", "cube"]
|
||||
motion_sensors = ["motion", "sensor_motion.aq2"]
|
||||
@@ -25,12 +26,12 @@ class Mqtt:
|
||||
if (config == None):
|
||||
raise "Config is null"
|
||||
|
||||
#load sids dictionary
|
||||
# load sids dictionary
|
||||
self._sids = config.get("sids", None)
|
||||
if (self._sids == None):
|
||||
self._sids = dict({})
|
||||
|
||||
#load mqtt settings
|
||||
# load mqtt settings
|
||||
mqttConfig = config.get("mqtt", None)
|
||||
if (mqttConfig == None):
|
||||
raise "Config mqtt section is null"
|
||||
@@ -53,7 +54,7 @@ class Mqtt:
|
||||
self._client.on_connect = self._mqtt_on_connect
|
||||
self._client.connect(self.server, self.port, 60)
|
||||
|
||||
#run message processing loop
|
||||
# run message processing loop
|
||||
t1 = Thread(target=self._mqtt_loop)
|
||||
t1.start()
|
||||
self._threads.append(t1)
|
||||
@@ -72,18 +73,18 @@ class Mqtt:
|
||||
def publish(self, model, sid, data, retain=True):
|
||||
sidprops = self._sids.get(sid, None)
|
||||
if (sidprops != None):
|
||||
model = sidprops.get("model",model)
|
||||
sid = sidprops.get("name",sid)
|
||||
model = sidprops.get("model", model)
|
||||
sid = sidprops.get("name", sid)
|
||||
|
||||
items = {}
|
||||
for key, value in data.items():
|
||||
# fix for latest motion value
|
||||
if (model in self.motion_sensors and key == "no_motion"):
|
||||
key="status"
|
||||
value="no_motion"
|
||||
key = "status"
|
||||
value = "no_motion"
|
||||
if (model in self.magnet_sensors and key == "no_close"):
|
||||
key="status"
|
||||
value="open"
|
||||
key = "status"
|
||||
value = "open"
|
||||
# do not retain event-based sensors (like switches and cubes).
|
||||
if (model in self.event_based_sensors):
|
||||
retain = False
|
||||
@@ -120,8 +121,8 @@ class Mqtt:
|
||||
return
|
||||
|
||||
model = parts[1]
|
||||
query_sid = parts[2] #sid or name part
|
||||
param = parts[3] #param part
|
||||
query_sid = parts[2] # sid or name part
|
||||
param = parts[3] # param part
|
||||
method = None
|
||||
if len(parts) > 4:
|
||||
method = parts[4]
|
||||
@@ -195,7 +196,7 @@ class Mqtt:
|
||||
r = int(arr[0])
|
||||
g = int(arr[1])
|
||||
b = int(arr[2])
|
||||
if len(arr)>3:
|
||||
if len(arr) > 3:
|
||||
bright = int(arr[3])
|
||||
else:
|
||||
bright = 255
|
||||
|
||||
+10
-8
@@ -10,7 +10,8 @@ from threading import Thread
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
# MANDATORY!!!! NEED TO TURN OFF "_process_report" THREAD IF CODE IS UPDATED!!!!
|
||||
# MANDATORY!!!! NEED TO TURN OFF "_process_report" THREAD IF CODE IS UPDATED!!!
|
||||
|
||||
|
||||
class XiaomiHub:
|
||||
GATEWAY_KEY = None
|
||||
@@ -94,10 +95,10 @@ class XiaomiHub:
|
||||
model = resp["model"]
|
||||
|
||||
xiaomi_device = {
|
||||
"model":model,
|
||||
"sid":resp["sid"],
|
||||
"short_id":resp["short_id"],
|
||||
"data":json.loads(resp["data"])}
|
||||
"model": model,
|
||||
"sid": resp["sid"],
|
||||
"short_id": resp["short_id"],
|
||||
"data": json.loads(resp["data"])}
|
||||
|
||||
device_type = None
|
||||
if model in sensors:
|
||||
@@ -107,7 +108,7 @@ class XiaomiHub:
|
||||
elif model in switches:
|
||||
device_type = 'switch'
|
||||
else:
|
||||
device_type = 'sensor' #not really matters
|
||||
device_type = 'sensor' # not really matters
|
||||
|
||||
if device_type == None:
|
||||
_LOGGER.error('Unsupported devices : {0}'.format(model))
|
||||
@@ -124,7 +125,7 @@ class XiaomiHub:
|
||||
try:
|
||||
socket = self._socket
|
||||
socket_list = [sys.stdin, socket]
|
||||
read_sockets, write_sockets, error_sockets = select.select(socket_list , [], [])
|
||||
read_sockets, write_sockets, error_sockets = select.select(socket_list, [], [])
|
||||
for sock in read_sockets:
|
||||
if sock == socket:
|
||||
data = sock.recv(4096)
|
||||
@@ -237,7 +238,7 @@ class XiaomiHub:
|
||||
if isinstance(packet, dict):
|
||||
try:
|
||||
sid = packet['sid']
|
||||
#model = packet['model']
|
||||
# model = packet['model']
|
||||
data = json.loads(packet['data'])
|
||||
|
||||
for device in self.XIAOMI_HA_DEVICES[sid]:
|
||||
@@ -248,6 +249,7 @@ class XiaomiHub:
|
||||
|
||||
self._queue.task_done()
|
||||
|
||||
|
||||
class XiaomiDevice():
|
||||
"""Representation a base Xiaomi device."""
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import logging
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def load_yaml(file):
|
||||
try:
|
||||
stram = open(file, "r")
|
||||
@@ -12,6 +13,7 @@ def load_yaml(file):
|
||||
raise
|
||||
_LOGGER.error("Can't load yaml with sids %r (%r)" % (file, e))
|
||||
|
||||
|
||||
def get_gateway_password(config, ip=""):
|
||||
if (config == None):
|
||||
raise "Config is null"
|
||||
|
||||
Reference in New Issue
Block a user