_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:
ip: 192.168.0.47
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_models:
- motion
+3 -3
View File
@@ -1,7 +1,7 @@
aqara:
image: monster1025/aqara-mqtt:1-armhf
#build: .
#dockerfile: Dockerfile-armhf
#image: monster1025/aqara-mqtt:1-armhf
build: .
dockerfile: Dockerfile-armhf
container_name: aqara
volumes:
- "./config:/app/config"
+1 -1
View File
@@ -110,7 +110,7 @@ if __name__ == "__main__":
client.subscribe("gateway", "+", "write", None)
client.subscribe("plug", "+", "status", "set")
gateway = XiaomiHub(gateway_pass, gateway_ip)
gateway = XiaomiHub(gateway_pass, gateway_ip, config)
stop_event= threading.Event()
t1 = threading.Thread(target=process_gateway_messages, args=[gateway, client, stop_event])
t1.daemon = True
+11 -3
View File
@@ -28,7 +28,7 @@ class XiaomiHub:
GATEWAY_DISCOVERY_PORT = 4321
SOCKET_BUFSIZE = 1024
def __init__(self, key, gateway=None):
def __init__(self, key, gateway_ip=None, config=None):
self.GATEWAY_KEY = key
self._listening = False
self._queue = None
@@ -36,9 +36,14 @@ class XiaomiHub:
self._mcastsocket = None
self._deviceCallbacks = defaultdict(list)
self._threads = []
self._read_unwanted_data_enabled = True
if gateway is not None:
self.GATEWAY_DISCOVERY_ADDRESS = gateway
if gateway_ip is not None:
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:
_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)
def _read_unwanted_data(self):
if not self._read_unwanted_data_enabled:
return
try:
socket = self._socket
socket_list = [sys.stdin, socket]