_read_unwanted_data_fix is now controlled via settings

This commit is contained in:
raspberry
2018-02-22 09:39:54 +03:00
parent fadd23e8cd
commit 3e5e71035d
6 changed files with 26 additions and 17 deletions
+1 -1
View File
@@ -1 +1 @@
1.0.3 1.0.4
+1
View File
@@ -10,6 +10,7 @@ mqtt:
gateway: gateway:
ip: 192.168.0.47 ip: 192.168.0.47
password: passw0rd password: passw0rd
unwanted_data_fix: True #leave it True if it works for you. Otherwise (if you didn't recieve any data from sensors) - set it to False
polling_interval: 2 polling_interval: 2
polling_models: polling_models:
- motion - motion
+3 -3
View File
@@ -1,7 +1,7 @@
aqara: aqara:
image: monster1025/aqara-mqtt:1-armhf #image: monster1025/aqara-mqtt:1-armhf
#build: . build: .
#dockerfile: Dockerfile-armhf dockerfile: Dockerfile-armhf
container_name: aqara container_name: aqara
volumes: volumes:
- "./config:/app/config" - "./config:/app/config"
+1 -1
View File
@@ -110,7 +110,7 @@ if __name__ == "__main__":
client.subscribe("gateway", "+", "write", None) client.subscribe("gateway", "+", "write", None)
client.subscribe("plug", "+", "status", "set") client.subscribe("plug", "+", "status", "set")
gateway = XiaomiHub(gateway_pass, gateway_ip) gateway = XiaomiHub(gateway_pass, gateway_ip, config)
stop_event= threading.Event() stop_event= threading.Event()
t1 = threading.Thread(target=process_gateway_messages, args=[gateway, client, stop_event]) t1 = threading.Thread(target=process_gateway_messages, args=[gateway, client, stop_event])
t1.daemon = True t1.daemon = True
+11 -3
View File
@@ -28,7 +28,7 @@ class XiaomiHub:
GATEWAY_DISCOVERY_PORT = 4321 GATEWAY_DISCOVERY_PORT = 4321
SOCKET_BUFSIZE = 1024 SOCKET_BUFSIZE = 1024
def __init__(self, key, gateway=None): def __init__(self, key, gateway_ip=None, config=None):
self.GATEWAY_KEY = key self.GATEWAY_KEY = key
self._listening = False self._listening = False
self._queue = None self._queue = None
@@ -36,9 +36,14 @@ class XiaomiHub:
self._mcastsocket = None self._mcastsocket = None
self._deviceCallbacks = defaultdict(list) self._deviceCallbacks = defaultdict(list)
self._threads = [] self._threads = []
self._read_unwanted_data_enabled = True
if gateway is not None: if gateway_ip is not None:
self.GATEWAY_DISCOVERY_ADDRESS = gateway self.GATEWAY_DISCOVERY_ADDRESS = gateway_ip
if config is not None and 'gateway' in config and 'unwanted_data_fix' in config['gateway']:
self._read_unwanted_data_enabled = (config['gateway']['unwanted_data_fix'] == True)
_LOGGER.info('"Read unwanted data" fix is {0}'.format(self._read_unwanted_data_enabled))
try: try:
_LOGGER.info('Discovering Xiaomi Gateways using address {0}'.format(self.GATEWAY_DISCOVERY_ADDRESS)) _LOGGER.info('Discovering Xiaomi Gateways using address {0}'.format(self.GATEWAY_DISCOVERY_ADDRESS))
@@ -113,6 +118,9 @@ class XiaomiHub:
return self._send_socket(cmd, rtnCmd, self.GATEWAY_IP, self.GATEWAY_PORT) return self._send_socket(cmd, rtnCmd, self.GATEWAY_IP, self.GATEWAY_PORT)
def _read_unwanted_data(self): def _read_unwanted_data(self):
if not self._read_unwanted_data_enabled:
return
try: try:
socket = self._socket socket = self._socket
socket_list = [sys.stdin, socket] socket_list = [sys.stdin, socket]
+9 -9
View File
@@ -13,12 +13,12 @@ def load_yaml(file):
_LOGGER.error("Can't load yaml with sids %r (%r)" % (file, e)) _LOGGER.error("Can't load yaml with sids %r (%r)" % (file, e))
def get_gateway_password(config, ip=""): def get_gateway_password(config, ip=""):
if (config == None): if (config == None):
raise "Config is null" raise "Config is null"
configGateway = config.get("gateway", None) configGateway = config.get("gateway", None)
if (configGateway == None): if (configGateway == None):
raise "Config gateway is null" raise "Config gateway is null"
password = configGateway.get("password", None) password = configGateway.get("password", None)
if (password == None): if (password == None):
raise "Config gateway passowrd is null" raise "Config gateway passowrd is null"
return password return password