up
This commit is contained in:
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
FROM jfloff/alpine-python:3.4
|
FROM python:3.7.1-stretch
|
||||||
|
|
||||||
ENV LIBRARY_PATH=/lib:/usr/lib
|
ENV LIBRARY_PATH=/lib:/usr/lib
|
||||||
|
|
||||||
|
|||||||
+30
-21
@@ -13,10 +13,12 @@ QUERY_TIME = os.getenv('QUERY_TIME', 5)
|
|||||||
PREFIX = os.getenv('PREFIX', 'home')
|
PREFIX = os.getenv('PREFIX', 'home')
|
||||||
|
|
||||||
ips = dict({
|
ips = dict({
|
||||||
'192.168.1.103':{'name':'kitchen-right', 'mac':bytearray(b'vr\xcb\rC\xb4'), 'type':'plug'},
|
'192.168.1.49':{'name':'rm2', 'mac':'B4430DCC2255', 'type':'remote'},
|
||||||
'192.168.1.183':{'name':'balcony-heater', 'mac':bytearray(b'\xc1j\xcb\rC\xb4'), 'type':'plug'},
|
# '192.168.1.62':{'name':'main-humidifier', 'mac':'B4430DCB6AC1', 'type':'plug'},
|
||||||
'192.168.1.188':{'name':'kitchen-kettle', 'mac':bytearray(b'9V\xcb\rC\xb4'), 'type':'plug'},
|
'192.168.1.63':{'name':'kitchen-mini-light', 'mac':'B4430DCB6C07', 'type':'plug'},
|
||||||
'192.168.1.49':{'name':'rm2', 'mac':bytearray(b'U"\xcc\rC\xb4'), 'type':'remote'}
|
# '192.168.1.64':{'name':'balcony-heater', 'mac':'B4430DCB7276', 'type':'plug'},
|
||||||
|
# '192.168.1.65':{'name':'kitchen-kettle', 'mac':'B4430DCB5639', 'type':'plug'},
|
||||||
|
# '192.168.1.66':{'name':'balcony-lights', 'mac':'B4430DCB6F18', 'type':'plug'},
|
||||||
})
|
})
|
||||||
|
|
||||||
plugs=[]
|
plugs=[]
|
||||||
@@ -40,24 +42,30 @@ def push_data(client, model, sid, data):
|
|||||||
prop=key)
|
prop=key)
|
||||||
client.publish(path, payload=value, qos=0, retain=True)
|
client.publish(path, payload=value, qos=0, retain=True)
|
||||||
|
|
||||||
|
def reverse_hex(s):
|
||||||
|
return "".join(map(str.__add__, s[-2::-2] ,s[-1::-2]))
|
||||||
|
|
||||||
def init_plugs():
|
def init_plugs():
|
||||||
plugs=[]
|
plugs=[]
|
||||||
for ip in ips:
|
for ip in ips:
|
||||||
try:
|
for i in range(1,3):
|
||||||
props = ips[ip]
|
try:
|
||||||
name = props['name']
|
props = ips[ip]
|
||||||
mac = props['mac']
|
name = props['name']
|
||||||
typeName = props['type']
|
mac = props['mac']
|
||||||
typeId = 0x2720 #SP2 by default
|
typeName = props['type']
|
||||||
if (typeName == "remote"):
|
typeId = 0x2720 #SP2 by default
|
||||||
typeId = 0x2712
|
if (typeName == "remote"):
|
||||||
broadObj = broadlink.gendevice(typeId, (ip, 80) , mac)
|
typeId = 0x2712
|
||||||
broadObj.auth()
|
macBytes = bytes.fromhex(reverse_hex(mac))
|
||||||
plug = PlugState(ip, typeName, name, broadObj)
|
broadObj = broadlink.gendevice(typeId, (ip, 80) , macBytes)
|
||||||
plug.update_properties()
|
broadObj.auth()
|
||||||
plugs.append(plug)
|
plug = PlugState(ip, typeName, name, broadObj)
|
||||||
except Exception as e:
|
plug.update_properties()
|
||||||
print('Connection to ', str(ip) , ' error:', str(e))
|
plugs.append(plug)
|
||||||
|
break
|
||||||
|
except Exception as e:
|
||||||
|
print('['+str(i) + '] Connection to ', str(ip) , ' error:', str(e))
|
||||||
return plugs
|
return plugs
|
||||||
|
|
||||||
def refresh_plug_states(data_callback):
|
def refresh_plug_states(data_callback):
|
||||||
@@ -98,7 +106,7 @@ def on_mqtt_message(client, userdata, msg):
|
|||||||
plug.process_command(param, value)
|
plug.process_command(param, value)
|
||||||
processNow=True
|
processNow=True
|
||||||
|
|
||||||
def on_connect(client, userdata, rc):
|
def on_connect(client, userdata, rc, kwargs):
|
||||||
client.subscribe(PREFIX + "/plug/+/+/set")
|
client.subscribe(PREFIX + "/plug/+/+/set")
|
||||||
client.subscribe(PREFIX + "/remote/+/+/learn")
|
client.subscribe(PREFIX + "/remote/+/+/learn")
|
||||||
client.subscribe(PREFIX + "/remote/+/+/set")
|
client.subscribe(PREFIX + "/remote/+/+/set")
|
||||||
@@ -129,4 +137,5 @@ if __name__ == "__main__":
|
|||||||
t1.start()
|
t1.start()
|
||||||
|
|
||||||
# and process mqtt messages in this thread
|
# and process mqtt messages in this thread
|
||||||
client.loop_forever()
|
client.loop_forever()
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -63,7 +63,7 @@ class PlugState:
|
|||||||
print("No ir packets recieved")
|
print("No ir packets recieved")
|
||||||
return
|
return
|
||||||
self.learn_temp = binascii.hexlify(ir_packet)
|
self.learn_temp = binascii.hexlify(ir_packet)
|
||||||
print("Learned code:", self.learn_temp)
|
print("Learned code:", ir_packet)
|
||||||
if (param == 'code' and self.type == 'remote'):
|
if (param == 'code' and self.type == 'remote'):
|
||||||
if (value == None or value == ""):
|
if (value == None or value == ""):
|
||||||
print("No ir packets in value")
|
print("No ir packets in value")
|
||||||
@@ -75,4 +75,4 @@ class PlugState:
|
|||||||
self.broadlink.send_data(ir_packet)
|
self.broadlink.send_data(ir_packet)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print ('Error while set value of plug', self.name , ' error:', e)
|
print ('Error while set value of plug', self.name , ' error:', e)
|
||||||
|
|||||||
Reference in New Issue
Block a user