Compare commits

..
53 Commits
Author SHA1 Message Date
G. Roggemans 74b7cee069 Remove unreachable code for logging model errors 2018-03-05 18:32:51 +01:00
G. Roggemans 38bb43086b Fix whitespace errors to make pylint happy 2018-03-05 18:31:17 +01:00
monster 9b4f784532 Merge pull request #15 from eburtsev/master
Fixed 'int' object has no attribute 'isdigit' exception
2018-02-27 16:13:55 +03:00
Eugene Burtsev e6bce68641 Fixed 'int' object has no attribute 'isdigit' exception 2018-02-27 15:21:11 +03:00
raspberry b9e940e9de Fix linter errors 2018-02-22 11:03:57 +03:00
raspberry 0f9a759839 Compile before 2018-02-22 10:10:08 +03:00
raspberry 3e5e71035d _read_unwanted_data_fix is now controlled via settings 2018-02-22 09:39:54 +03:00
raspberry fadd23e8cd Readme change 2018-02-22 09:03:19 +03:00
raspberry 04169ffe4e Fix for new aqara motion sensor 2018-02-22 06:39:55 +03:00
raspberry b390d044cc Fix for new aqara motion sensor 2018-02-21 21:05:24 +03:00
raspberry da10280a34 SORRY! Fix for broken motion/door state! 2018-02-21 20:01:12 +03:00
raspberry 7a2d601481 SORRY! Fix for broken motion/door state! 2018-02-21 19:56:31 +03:00
raspberry ed116b431b SORRY! Fix for broken motion/door state! 2018-02-21 19:55:47 +03:00
raspberry 6f8bbe1599 1.0.2 2018-02-18 19:18:25 +03:00
monster 86967d7599 Merge pull request #14 from eburtsev/master
Added ability to set gateway discovery IP in config
2018-02-18 19:17:33 +03:00
Eugene Burtsev d638b89fc2 Added ability to set gateway discovery IP in config 2018-02-17 15:58:15 +03:00
Eugene Burtsev 3561d4e595 Merge pull request #1 from monster1025/master
Changes from upstream
2018-02-17 15:48:15 +03:00
Your Name f0eda582e1 travis docker layers cache - cant get it working ( 2018-02-16 13:34:36 +03:00
Your Name 219df48228 travis docker layers cache 2018-02-16 13:26:48 +03:00
Your Name 693f3a21de travis docker layers cache 2018-02-16 12:52:56 +03:00
Your Name a0979f4e39 travis docker layers cache 2018-02-16 12:15:45 +03:00
Your Name d47548ce24 README change. 2018-02-16 11:12:45 +03:00
Your Name 3754c8d08d Added support for JSON report instead of properties. 2018-02-16 11:08:36 +03:00
Your Name 8b4ea2a089 Added support for JSON report instead of properties. 2018-02-16 11:08:17 +03:00
Your Name 076e70de6b travis 2018-02-16 10:49:59 +03:00
Your Name a1fbbd0922 travis 2018-02-16 10:40:11 +03:00
Your Name b48c2abfd3 travis 2018-02-16 10:39:05 +03:00
Your Name 67b465fac4 travis 2018-02-16 10:18:29 +03:00
Your Name 147fe4dc78 travis 2018-02-16 10:11:55 +03:00
Your Name 810fe2b4b1 travis 2018-02-16 10:01:39 +03:00
Your Name 85a53d031e travis 2018-02-16 09:40:11 +03:00
Your Name 74f3d3bce6 travis 2018-02-16 09:25:55 +03:00
Your Name 848a36f9cd travis 2018-02-16 09:16:16 +03:00
Your Name 3b3effc67d travis 2018-02-16 09:12:35 +03:00
Your Name e129152f79 travis 2018-02-16 08:55:53 +03:00
Your Name a845c49bcd travis 2018-02-16 08:50:04 +03:00
Your Name 1e6c131f81 travis 2018-02-16 01:07:46 +03:00
Your Name b0082fe61b travis 2018-02-16 01:02:36 +03:00
Your Name 7ee0cfadc7 travis 2018-02-16 00:58:36 +03:00
Your Name 6bd16ded60 travis 2018-02-16 00:53:39 +03:00
Your Name 32c8aefb76 travis 2018-02-16 00:50:58 +03:00
Your Name f647e97b7f travis 2018-02-16 00:42:39 +03:00
Your Name 10900725a1 travis 2018-02-16 00:37:39 +03:00
Your Name 080de01b37 travis 2018-02-16 00:37:24 +03:00
Your Name 5fd253a7f5 travis 2018-02-16 00:32:49 +03:00
Your Name 3b4e735cf2 travis 2018-02-16 00:28:28 +03:00
Your Name e83ce64a47 travis 2018-02-16 00:22:57 +03:00
Your Name f4d8b0e529 travis 2018-02-16 00:19:10 +03:00
Your Name c25dadfeb2 travis 2018-02-16 00:08:44 +03:00
Your Name 5182c22f1a travis 2018-02-15 23:54:00 +03:00
Your Name a32cc13bc3 travis 2018-02-15 23:43:06 +03:00
Your Name 9cabb1adb2 travis 2018-02-15 23:38:04 +03:00
Your Name cf703caad8 travis 2018-02-15 23:29:17 +03:00
12 changed files with 221 additions and 56 deletions

No files matched your search

+1
View File
@@ -0,0 +1 @@
1.0.4
+117
View File
@@ -0,0 +1,117 @@
sudo: true
language: python
services:
- docker
env:
global:
- PROJECT=aqara-mqtt
- IMAGE_NAME=$DOCKER_USERNAME/$PROJECT
- VERSION=$(cat .semver)
- MAJOR=$(cut -d. -f1 .semver)
- MINOR=$(cut -d. -f2 .semver)
- PATCH=$(cut -d. -f3 .semver)
jobs:
include:
- stage: build x64 image
before_script:
- ARCH=x64
script:
# build
- docker build -t $PROJECT -f Dockerfile-$ARCH .
# push image
- >
if [ "$TRAVIS_BRANCH" == "master" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"
#1.0.0-arch
docker tag $PROJECT $IMAGE_NAME:$VERSION-$ARCH
docker push $IMAGE_NAME:$VERSION-$ARCH
#1.0-arch
docker tag $PROJECT $IMAGE_NAME:$MAJOR.$MINOR-$ARCH
docker push $IMAGE_NAME:$MAJOR.$MINOR-$ARCH
#1-arch
docker tag $PROJECT $IMAGE_NAME:$MAJOR-$ARCH
docker push $IMAGE_NAME:$MAJOR-$ARCH
#latest by arch
docker tag $PROJECT $IMAGE_NAME:$ARCH
docker push $IMAGE_NAME:$ARCH
fi
- stage: build i386 image
before_script:
- ARCH=i386
script:
# build
- docker build -t $PROJECT -f Dockerfile-$ARCH .
# push image
- >
if [ "$TRAVIS_BRANCH" == "master" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"
#1.0.0-arch
docker tag $PROJECT $IMAGE_NAME:$VERSION-$ARCH
docker push $IMAGE_NAME:$VERSION-$ARCH
#1.0-arch
docker tag $PROJECT $IMAGE_NAME:$MAJOR.$MINOR-$ARCH
docker push $IMAGE_NAME:$MAJOR.$MINOR-$ARCH
#1-arch
docker tag $PROJECT $IMAGE_NAME:$MAJOR-$ARCH
docker push $IMAGE_NAME:$MAJOR-$ARCH
#latest by arch
docker tag $PROJECT $IMAGE_NAME:$ARCH
docker push $IMAGE_NAME:$ARCH
fi
- stage: build armhf image
before_script:
- ARCH=armhf
script:
# prepare qemu
- docker run --rm --privileged multiarch/qemu-user-static:register --reset
# get qemu-arm-static binary
- >
mkdir tmp &&
pushd tmp &&
curl -L -o qemu-arm-static.tar.gz https://github.com/multiarch/qemu-user-static/releases/download/v2.6.0/qemu-arm-static.tar.gz &&
tar xzf qemu-arm-static.tar.gz &&
popd
#copy it to container
- sed -i -e '2iCOPY tmp/qemu-arm-static /usr/bin/qemu-arm-static\' Dockerfile-$ARCH
# build
- docker build -t $PROJECT -f Dockerfile-$ARCH .
# push image
- >
if [ "$TRAVIS_BRANCH" == "master" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"
#1.0.0-arch
docker tag $PROJECT $IMAGE_NAME:$VERSION-$ARCH
docker push $IMAGE_NAME:$VERSION-$ARCH
#1.0-arch
docker tag $PROJECT $IMAGE_NAME:$MAJOR.$MINOR-$ARCH
docker push $IMAGE_NAME:$MAJOR.$MINOR-$ARCH
#1-arch
docker tag $PROJECT $IMAGE_NAME:$MAJOR-$ARCH
docker push $IMAGE_NAME:$MAJOR-$ARCH
#latest by arch
docker tag $PROJECT $IMAGE_NAME:$ARCH
docker push $IMAGE_NAME:$ARCH
fi
+15
View File
@@ -0,0 +1,15 @@
FROM arm32v7/python:slim
ENV LIBRARY_PATH=/lib:/usr/lib
ADD src/requirements.txt /
RUN apt-get update && apt-get install -y build-essential autoconf \
&& pip install --upgrade pip && pip install -r /requirements.txt \
&& apt-get remove -y build-essential autoconf \
&& apt-get autoremove -y \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY src /app
CMD ["python3", "-u", "/app/main.py"]
-11
View File
@@ -1,11 +0,0 @@
FROM alpine-python:latest
ENV LIBRARY_PATH=/lib:/usr/lib
ADD src/requirements.txt /
RUN pip install --upgrade pip && pip install -r /requirements.txt
WORKDIR /app
COPY src /app
CMD ["python3", "-u", "/app/main.py"]
+14
View File
@@ -0,0 +1,14 @@
ARGS = `arg="$(filter-out $@,$(MAKECMDGOALS))" && echo $${arg:-${1}}`
lint:
rm -rf "src/__pycache__"
python3 -m compileall src
rm -rf "src/__pycache__"
commit: lint
git add .
git commit -m "$(call ARGS,\"updating to lastest local code\")"
git push
%:
@:
+10 -2
View File
@@ -1,5 +1,7 @@
# Aqara-MQTT # Aqara-MQTT
Aqara (Xiaomi) Gateway to MQTT brodge. [![Build Status](https://travis-ci.org/monster1025/aqara-mqtt.svg?branch=master)](https://travis-ci.org/monster1025/aqara-mqtt)
Aqara (Xiaomi) Gateway to MQTT bridge.
I use it for home assistant integration and it works well now. I use it for home assistant integration and it works well now.
You need to activate developer mode (described here: http://bbs.xiaomi.cn/t-13198850) You need to activate developer mode (described here: http://bbs.xiaomi.cn/t-13198850)
@@ -14,6 +16,12 @@ will turn on plug/heater and translate devices state from gateway:
"home/plug/heater/status" on "home/plug/heater/status" on
``` ```
## Architecture
Docker image support following architectures (you must choose your architecture in docker-compose):
- armhf (raspberry pi 3, arm32v7)
- i386 (x86 pc)
- x64 (x64 pc)
## Config ## Config
Edit file config/config-sample.yaml and rename it to config/config.yaml Edit file config/config-sample.yaml and rename it to config/config.yaml
@@ -21,7 +29,7 @@ Edit file config/config-sample.yaml and rename it to config/config.yaml
Sample docker-compose.yaml file for user: Sample docker-compose.yaml file for user:
``` ```
aqara: aqara:
image: monster1025/aqara-mqtt image: monster1025/aqara-mqtt:1-armhf
container_name: aqara container_name: aqara
volumes: volumes:
- "./config:/app/config" - "./config:/app/config"
+4
View File
@@ -4,9 +4,13 @@ mqtt:
username: username username: username
password: passw0rd password: passw0rd
prefix: home prefix: home
#send report as json
json: False
gateway: gateway:
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
+2 -1
View File
@@ -1,6 +1,7 @@
aqara: aqara:
#image: monster1025/aqara-mqtt:1-armhf
build: . build: .
dockerfile: Dockerfile-rpi dockerfile: Dockerfile-armhf
container_name: aqara container_name: aqara
volumes: volumes:
- "./config:/app/config" - "./config:/app/config"
+13 -11
View File
@@ -1,7 +1,6 @@
import logging import logging
import time import time
import threading import threading
import os
import json import json
import signal import signal
@@ -13,6 +12,7 @@ from xiaomihub import XiaomiHub
logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.INFO)
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
def process_gateway_messages(gateway, client, stop_event): def process_gateway_messages(gateway, client, stop_event):
while not stop_event.is_set(): while not stop_event.is_set():
try: try:
@@ -33,6 +33,7 @@ def process_gateway_messages(gateway, client, stop_event):
_LOGGER.error('Error while sending from gateway to mqtt: ', str(e)) _LOGGER.error('Error while sending from gateway to mqtt: ', str(e))
_LOGGER.info("Stopping Gateway Thread ...") _LOGGER.info("Stopping Gateway Thread ...")
def read_motion_data(gateway, client, polling_interval, polling_models, stop_event): def read_motion_data(gateway, client, polling_interval, polling_models, stop_event):
first = True first = True
while not stop_event.is_set(): while not stop_event.is_set():
@@ -41,21 +42,19 @@ def read_motion_data(gateway, client, polling_interval, polling_models, stop_eve
devices = gateway.XIAOMI_DEVICES[device_type] devices = gateway.XIAOMI_DEVICES[device_type]
for device in devices: for device in devices:
model = device.get("model", "") model = device.get("model", "")
if (model not in polling_models): if model not in polling_models:
continue continue
sid = device['sid'] sid = device['sid']
sensor_resp = gateway.get_from_hub(sid) sensor_resp = gateway.get_from_hub(sid)
if (sensor_resp == None): if sensor_resp is None:
continue; continue
if (sensor_resp['sid'] != sid): if sensor_resp['sid'] != sid:
_LOGGER.error("Error: Response sid(" + sensor_resp['sid'] + ") differs from requested(" + sid + "). Skipping.") _LOGGER.error("Error: Response sid(" + sensor_resp['sid'] + ") differs from requested(" + sid + "). Skipping.")
continue; continue
data = json.loads(sensor_resp['data']) data = json.loads(sensor_resp['data'])
state = data.get("status", None) if device['data'] != data or first:
short_id = sensor_resp['short_id']
if ( device['data'] != data or first):
device['data'] = data device['data'] = data
_LOGGER.debug("Polling result differs for " + str(model) + " with sid(First: " + str(first) + "): " + str(sid) + "; " + str(data)) _LOGGER.debug("Polling result differs for " + str(model) + " with sid(First: " + str(first) + "): " + str(sid) + "; " + str(data))
client.publish(model, sid, data) client.publish(model, sid, data)
@@ -65,6 +64,7 @@ def read_motion_data(gateway, client, polling_interval, polling_models, stop_eve
time.sleep(polling_interval) time.sleep(polling_interval)
_LOGGER.info("Stopping Polling Thread ...") _LOGGER.info("Stopping Polling Thread ...")
def process_mqtt_messages(gateway, client, stop_event): def process_mqtt_messages(gateway, client, stop_event):
while not stop_event.is_set(): while not stop_event.is_set():
try: try:
@@ -76,12 +76,13 @@ def process_mqtt_messages(gateway, client, stop_event):
sid = data.get("sid", None) sid = data.get("sid", None)
values = data.get("values", dict()) values = data.get("values", dict())
resp = gateway.write_to_hub(sid, **values) gateway.write_to_hub(sid, **values)
client._queue.task_done() client._queue.task_done()
except Exception as e: except Exception as e:
_LOGGER.error('Error while sending from mqtt to gateway: ', str(e)) _LOGGER.error('Error while sending from mqtt to gateway: ', str(e))
_LOGGER.info("Stopping MQTT Thread ...") _LOGGER.info("Stopping MQTT Thread ...")
def exit_handler(signal, frame): def exit_handler(signal, frame):
print('Exiting') print('Exiting')
stop_event.set() stop_event.set()
@@ -97,6 +98,7 @@ if __name__ == "__main__":
gateway_pass = yamlparser.get_gateway_password(config) gateway_pass = yamlparser.get_gateway_password(config)
polling_interval = config['gateway'].get("polling_interval", 2) polling_interval = config['gateway'].get("polling_interval", 2)
polling_models = config['gateway'].get("polling_models", ['motion']) polling_models = config['gateway'].get("polling_models", ['motion'])
gateway_ip = config['gateway'].get("ip", None)
signal.signal(signal.SIGINT, exit_handler) signal.signal(signal.SIGINT, exit_handler)
signal.signal(signal.SIGTERM, exit_handler) signal.signal(signal.SIGTERM, exit_handler)
@@ -109,7 +111,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 = 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
+28 -20
View File
@@ -1,5 +1,4 @@
import paho.mqtt.client as mqtt import paho.mqtt.client as mqtt
import os
import logging import logging
from queue import Queue from queue import Queue
from threading import Thread from threading import Thread
@@ -7,7 +6,11 @@ import json
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
class Mqtt: class Mqtt:
event_based_sensors = ["switch", "cube"]
motion_sensors = ["motion", "sensor_motion.aq2"]
magnet_sensors = ["magnet"]
username = "" username = ""
password = "" password = ""
server = "localhost" server = "localhost"
@@ -38,6 +41,7 @@ class Mqtt:
self.server = mqttConfig.get("server", "localhost") self.server = mqttConfig.get("server", "localhost")
self.port = mqttConfig.get("port", 1883) self.port = mqttConfig.get("port", 1883)
self.prefix = mqttConfig.get("prefix", "home") self.prefix = mqttConfig.get("prefix", "home")
self.json = mqttConfig.get("json", False)
self._queue = Queue() self._queue = Queue()
self._threads = [] self._threads = []
@@ -72,28 +76,39 @@ class Mqtt:
model = sidprops.get("model", model) model = sidprops.get("model", model)
sid = sidprops.get("name", sid) sid = sidprops.get("name", sid)
# _LOGGER.info("data is " + format(data)) items = {}
PATH_FMT = self.prefix + "/{model}/{sid}/{prop}"
for key, value in data.items(): for key, value in data.items():
# fix for latest motion value # fix for latest motion value
if (model == "motion" and key == "no_motion"): if (model in self.motion_sensors and key == "no_motion"):
key = "status" key = "status"
value = "no_motion" value = "no_motion"
if (model == "magnet" and key == "no_close"): if (model in self.magnet_sensors and key == "no_close"):
key = "status" key = "status"
value = "open" value = "open"
# do not retain event-based sensors (like switches and cubes). # do not retain event-based sensors (like switches and cubes).
if (model in ["switch", "cube"]): if (model in self.event_based_sensors):
retain = False retain = False
# fix for rgb format # fix for rgb format
if (key == "rgb" and self._is_int(value)): if (key == "rgb" and str(value).isdigit()):
value = self._color_xiaomi_to_rgb(value) value = self._color_xiaomi_to_rgb(str(value))
items[key] = value
if self.json == True:
PATH_FMT = self.prefix + "/{model}/{sid}/json"
topic = PATH_FMT.format(model=model, sid=sid)
values = {}
values['sid'] = sid
for key in items:
values[key] = items[key]
jsondata = json.dumps(values)
_LOGGER.info("Publishing message to topic " + topic + ": " + str(jsondata) + ".")
self._client.publish(topic, payload=jsondata, qos=0, retain=retain)
else:
for key in items:
PATH_FMT = self.prefix + "/{model}/{sid}/{prop}"
topic = PATH_FMT.format(model=model, sid=sid, prop=key) topic = PATH_FMT.format(model=model, sid=sid, prop=key)
_LOGGER.info("Publishing message to topic " + topic + ": " + str(value) + ".") _LOGGER.info("Publishing message to topic " + topic + ": " + str(items[key]) + ".")
self._client.publish(topic, payload=value, qos=0, retain=retain) self._client.publish(topic, payload=items[key], qos=0, retain=retain)
def _mqtt_on_connect(self, client, userdata, rc, unk): def _mqtt_on_connect(self, client, userdata, rc, unk):
_LOGGER.info("Connected to mqtt server.") _LOGGER.info("Connected to mqtt server.")
@@ -142,7 +157,7 @@ class Mqtt:
# use single value set method # use single value set method
value = (msg.payload).decode('utf-8') value = (msg.payload).decode('utf-8')
if self._is_int(value): if value.isdigit():
value = int(value) value = int(value)
# fix for rgb format # fix for rgb format
@@ -187,10 +202,3 @@ class Mqtt:
bright = 255 bright = 255
value = int('%02x%02x%02x%02x' % (bright, r, g, b), 16) value = int('%02x%02x%02x%02x' % (bright, r, g, b), 16)
return value return value
def _is_int(self, x):
try:
tmp = int(x)
return True
except Exception as e:
return False
+15 -11
View File
@@ -10,7 +10,8 @@ from threading import Thread
_LOGGER = logging.getLogger(__name__) _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: class XiaomiHub:
GATEWAY_KEY = None GATEWAY_KEY = None
@@ -28,7 +29,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 +37,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))
@@ -88,9 +94,6 @@ class XiaomiHub:
resp = self._send_cmd(cmd, "read_ack") resp = self._send_cmd(cmd, "read_ack")
model = resp["model"] model = resp["model"]
if model == '':
model = 'cube'
xiaomi_device = { xiaomi_device = {
"model": model, "model": model,
"sid": resp["sid"], "sid": resp["sid"],
@@ -107,15 +110,15 @@ class XiaomiHub:
else: else:
device_type = 'sensor' # not really matters device_type = 'sensor' # not really matters
if device_type == None:
_LOGGER.error('Unsupported devices : {0}'.format(model))
else:
self.XIAOMI_DEVICES[device_type].append(xiaomi_device) self.XIAOMI_DEVICES[device_type].append(xiaomi_device)
def _send_cmd(self, cmd, rtnCmd): def _send_cmd(self, cmd, rtnCmd):
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]
@@ -232,7 +235,7 @@ class XiaomiHub:
if isinstance(packet, dict): if isinstance(packet, dict):
try: try:
sid = packet['sid'] sid = packet['sid']
model = packet['model'] # model = packet['model']
data = json.loads(packet['data']) data = json.loads(packet['data'])
for device in self.XIAOMI_HA_DEVICES[sid]: for device in self.XIAOMI_HA_DEVICES[sid]:
@@ -243,6 +246,7 @@ class XiaomiHub:
self._queue.task_done() self._queue.task_done()
class XiaomiDevice(): class XiaomiDevice():
"""Representation a base Xiaomi device.""" """Representation a base Xiaomi device."""
+2
View File
@@ -3,6 +3,7 @@ import logging
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
def load_yaml(file): def load_yaml(file):
try: try:
stram = open(file, "r") stram = open(file, "r")
@@ -12,6 +13,7 @@ def load_yaml(file):
raise raise
_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"