diff --git a/.semver b/.semver index 21e8796..ee90284 100644 --- a/.semver +++ b/.semver @@ -1 +1 @@ -1.0.3 +1.0.4 diff --git a/config/config-sample.yaml b/config/config-sample.yaml index 7327e74..71b11fd 100644 --- a/config/config-sample.yaml +++ b/config/config-sample.yaml @@ -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 diff --git a/docker-compose.yaml b/docker-compose.yaml index 6067a64..f03cbde 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -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" diff --git a/src/main.py b/src/main.py index ba34342..f379f7e 100644 --- a/src/main.py +++ b/src/main.py @@ -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 diff --git a/src/xiaomihub.py b/src/xiaomihub.py index d723f35..3dfe331 100644 --- a/src/xiaomihub.py +++ b/src/xiaomihub.py @@ -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] diff --git a/src/yamlparser.py b/src/yamlparser.py index a5cbfe2..3f12aea 100644 --- a/src/yamlparser.py +++ b/src/yamlparser.py @@ -13,12 +13,12 @@ def load_yaml(file): _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" - configGateway = config.get("gateway", None) - if (configGateway == None): - raise "Config gateway is null" - password = configGateway.get("password", None) - if (password == None): - raise "Config gateway passowrd is null" - return password + if (config == None): + raise "Config is null" + configGateway = config.get("gateway", None) + if (configGateway == None): + raise "Config gateway is null" + password = configGateway.get("password", None) + if (password == None): + raise "Config gateway passowrd is null" + return password