Exemplo n.º 1
0
	def read(self,mac):
		result={}
		try:
			conn = Connector(mac)
			conn.connect(type='random')
			if not conn.isconnected:
				conn.connect(type='random')
				if not conn.isconnected:
					return
			battery = struct.unpack('2B',conn.readCharacteristic('0x2e'))
			temperature = struct.unpack('2B',conn.readCharacteristic('0x34'))
			humidity = struct.unpack('2B',conn.readCharacteristic('0x3c'))
			pression = struct.unpack('4B',conn.readCharacteristic('0x44'))
			temperature = int(str(hex(temperature[0])[2:].zfill(2) + hex(temperature[1])[2:].zfill(2)),16)
			humidity = int(str(hex(humidity[0])[2:].zfill(2) + hex(humidity[1])[2:].zfill(2)),16)
			logging.debug(str(pression))
			pression = int(str(hex(pression[0])[2:].zfill(2) + hex(pression[1])[2:].zfill(2)+ hex(pression[2])[2:].zfill(2)+ hex(pression[3])[2:].zfill(2)),16)
			battery = int(str(hex(battery[0])[2:].zfill(2) + hex(battery[1])[2:].zfill(2)),16)
			result['temperature'] = float(temperature)/10
			result['humidity'] = float(humidity)/10
			result['pressure'] = float(pression)/100
			result['batteryvoltage'] = round(float(battery)*0.00051029,2)
			if round(float(battery)*0.00051029,2) > 3:
				battery = 100
			elif round(float(battery)*0.00051029,2) < 2:
				battery = 0
			else:
				battery = round((float(battery)*0.00051029 - 2) *100,0)
			result['battery'] = battery
		except Exception,e:
			logging.error('HECTOR------'+str(e))
			conn.disconnect()
Exemplo n.º 2
0
 def read(self, mac):
     global result
     result = {}
     try:
         if mac in globals.KEEPED_CONNECTION:
             logging.debug('Already a connection for ' + mac + ' use it')
             conn = globals.KEEPED_CONNECTION[mac]
         else:
             logging.debug('Creating a new connection for ' + mac)
             conn = Connector(mac)
             globals.KEEPED_CONNECTION[mac] = conn
             conn.connect()
         if not conn.isconnected:
             conn.connect()
             if not conn.isconnected:
                 return
         notification = Notification(conn, Smartplug)
         conn.writeCharacteristic('0x2b', '0f050400000005ffff')
         notification.subscribe(2)
         return
     except Exception as e:
         try:
             conn.disconnect()
         except Exception as e:
             pass
         logging.error(str(e))
     return
Exemplo n.º 3
0
 def action(self, message):
     logging.debug('ACTION BLPNR')
     mac = message['device']['id']
     logging.debug('MAC BLPNR ' + mac)
     action = message['command']['action']
     if mac not in globals.LAST_STORAGE:
         globals.LAST_STORAGE[mac] = {}
     logging.debug('action BLPNR ' + action)
     handle = '0X0011'
     conn = Connector(mac)
     conn.connect(type='random')
     if not conn.isconnected:
         conn.connect(type='random')
         if not conn.isconnected:
             return
     logging.debug('connected BLPNR')
     if action == 'refresh':
         logging.debug('refresh BLPNR')
         self.getStatus(mac)
         return
     if action == 'off':
         message = '050400900000009900'
     if action == 'on':
         value = message['command']['value']
         logging.debug('value BLPNR ' + str(value))
         liste = [5, 4, 0, 10, 0, int(value), 0]
         checksum1 = sum(liste) % 256
         checksum2 = sum(liste) / 256
         liste.append(checksum1)
         liste.append(checksum2)
         message = utils.tuple_to_hex(liste)
     conn.writeCharacteristic(handle, message)
     conn.disconnect()
     self.getStatus(mac)
Exemplo n.º 4
0
    def read(self, mac):
        result = {}
        try:
            conn = Connector(mac)
            conn.connect()
            if not conn.isconnected:
                conn.connect()
                if not conn.isconnected:
                    return

            logging.debug('read batteryFirm')
            batteryFirm = bytearray(conn.readCharacteristic('0x18'))
            battery = batteryFirm[0]
            firmware = "".join(map(chr, batteryFirm[2:]))
            notification = Notification(conn, Mithermaff)
            logging.debug('write 0x10 0100 to get sensor values')
            conn.writeCharacteristic('0x10', '0100', response=True)
            notification.subscribe(2)
            result['battery'] = battery
            result['firmware'] = firmware
            result['id'] = mac
            logging.debug(str(result))
            return result
        except Exception, e:
            logging.error(str(e))
Exemplo n.º 5
0
 def read(self, mac):
     result = {}
     #account verify : 0x29
     #realtimedata : 0x30
     #settings : 0x34
     #settingsresult : 0x25
     #historydata : 0x2c
     #
     #credentials :  0x21, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0xb8, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00
     #
     #enablerealtime : 0x0B, 0x01, 0x00, 0x00, 0x00, 0x00
     #
     #units celcisu : 0x02, 0x00, 0x00, 0x00, 0x00, 0x00
     # defini seuil : dans 0x34 ecrire 010X48f4YYYY  avec x numero de sonde (commencant a 0) et y temperature x10 inverse
     #
     #0x31 0100 activer notif temp
     #batterie 0x34 082400000000
     try:
         conn = Connector(mac)
         conn.connect()
         if not conn.isconnected:
             conn.connect()
             if not conn.isconnected:
                 return
         conn.writeCharacteristic('0x29',
                                  '2107060504030201b8220000000000',
                                  response=True)
         notification = Notification(conn, Ibbq6)
         conn.writeCharacteristic('0x26', '0100', response=True)
         conn.writeCharacteristic('0x34', '082400000000', response=True)
         notification.subscribe(10)
         return result
     except Exception as e:
         logging.error(str(e))
     return result
Exemplo n.º 6
0
 def findCharacteristics(self, mac, conn=''):
     logging.debug("Searching characteristics")
     if conn == '':
         conn = Connector(mac)
         conn.connect(type='random')
     if not conn.isconnected:
         return
     value = ''
     characteristics = []
     try:
         characteristics = conn.conn.getCharacteristics(0x0001)
     except Exception as e:
         logging.debug(str(e))
         try:
             characteristics = conn.conn.getCharacteristics(0x0001)
         except Exception as e:
             logging.debug(str(e))
             try:
                 characteristics = conn.conn.getCharacteristics(0x0001)
             except Exception as e:
                 logging.debug(str(e))
                 conn.disconnect()
     battery_characteristic = next(
         iter(
             filter(lambda el: el.uuid == BATTERY_CHARACTERISTIC_UUID,
                    characteristics)))
     logging.debug('Found ' + hex(battery_characteristic.getHandle()))
     return [hex(battery_characteristic.getHandle())]
Exemplo n.º 7
0
 def read(self, mac):
     result = {}
     try:
         conn = Connector(mac)
         conn.connect()
         if not conn.isconnected:
             conn.connect()
             if not conn.isconnected:
                 return
         if (mac in globals.KNOWN_DEVICES
                 and globals.KNOWN_DEVICES[mac]['model']
                 == 'xiaomiht/xiaomiht_cleargrass'):
             Firm = bytearray(conn.readCharacteristic('0x2a'))
         else:
             Firm = bytearray(conn.readCharacteristic('0x24'))
             batt = bytearray(conn.readCharacteristic('0x18'))
             battery = batt[0]
             result['battery'] = battery
         firmware = "".join(map(chr, Firm))
         result['firmware'] = firmware
         notification = Notification(conn, XiaomiHT)
         conn.writeCharacteristic('0x10', '0100', response=True)
         notification.subscribe(2)
         result['id'] = mac
         logging.debug('XIAOMIHT------' + str(result))
         return result
     except Exception as e:
         logging.error(str(e))
     return result
Exemplo n.º 8
0
    def parse(self, data, mac, name):
        action = {}
        action['present'] = 1

        action['version'] = 'awox'
        if mac.upper() not in globals.KNOWN_DEVICES and globals.LEARN_MODE:
            if name.lower() == P_DEFAULTNAME and self.auto_pairing:
                self.setMeshPairing(mac, name, self.mesh_name,
                                    self.mesh_password, self.mesh_longtermkey)

            if mac in globals.KEEPED_CONNECTION:
                conn = globals.KEEPED_CONNECTION[mac]
            else:
                conn = Connector(mac)
            conn.connect()
            char = conn.readCharacteristic(MODEL_UUID)
            conn.disconnect()
            logging.debug('Version is ' + char)
            if char.lower().startswith('EF'):
                action['version'] = 'awox'
            if char.lower().startswith('ERCUm'):
                action['version'] = 'awoxremote'
            if char.lower().startswith('ESMLm'):  # ESMLm_c9 and ESMLm_c13
                action['version'] = 'awox'

        return action
Exemplo n.º 9
0
 def action(self, message):
     if 'type' in message['command']:
         type = message['command']['type']
     mac = message['device']['id']
     data = {}
     data['source'] = globals.daemonname
     data['id'] = mac
     data['sendstatus'] = '-'
     globals.JEEDOM_COM.add_changes('devices::' + mac, data)
     handle = message['command']['handle']
     value = message['command']['value']
     conn = Connector(mac)
     conn.connect()
     if not conn.isconnected:
         data['sendstatus'] = 'KO'
         globals.JEEDOM_COM.add_changes('devices::' + mac, data)
         return
     conn.writeCharacteristic('0x29',
                              '2107060504030201b8220000000000',
                              response=True)
     if type == 'setTarget':
         logging.debug('IBBQ set Target for probe ' +
                       message['command']['probe'] + ' value ' + value)
         valuetohex = hex(int(value) * 10)[2:].zfill(4)
         towrite = '010' + message['command'][
             'probe'] + '48f4' + valuetohex[2:4] + valuetohex[0:2]
         logging.debug('IBBQ writing ' + towrite + ' on handle ' + handle)
         conn.writeCharacteristic(handle, towrite, response=True)
         data['sendstatus'] = 'OK'
         globals.JEEDOM_COM.add_changes('devices::' + mac, data)
     conn.disconnect()
     return
Exemplo n.º 10
0
 def getStatus(self, mac):
     logging.debug('STATUS BLPNR')
     try:
         conn = Connector(mac)
         if not conn.isconnected:
             conn.connect(type='random')
             if not conn.isconnected:
                 return
         conn.writeCharacteristic('0x000f', '2902')
         conn.disconnect()
     except Exception as e:
         logging.error(str(e))
     try:
         conn = Connector(mac)
         if not conn.isconnected:
             conn.connect(type='random')
             if not conn.isconnected:
                 return
         logging.debug('READ notif BLPNR')
         notification = Notification(conn, Blpnr)
         #notification.subscribe(10,disconnect=True)
         notification.subscribe()
         conn.writeCharacteristic('0x0011', '0d00000d00')
     except Exception as e:
         logging.error(str(e))
Exemplo n.º 11
0
 def action(self, message):
     mac = message['device']['id']
     handle = message['command']['handle']
     value = message['command']['value']
     repeat = 0
     if 'repeat' in message['command']:
         repeat = int(message['command']['repeat'])
     if mac in globals.KEEPED_CONNECTION:
         logging.debug('Already a connection for ' + mac + ' use it')
         conn = globals.KEEPED_CONNECTION[mac]
     else:
         logging.debug('Creating a new connection for ' + mac)
         conn = Connector(mac)
         globals.KEEPED_CONNECTION[mac] = conn
         conn.connect()
     if not conn.isconnected:
         conn.connect()
         if not conn.isconnected:
             return
     if repeat != 0:
         conn.writeCharacteristic('0x25', '010000000000000000000d0a')
         time.sleep(2)
         for x in range(repeat):
             conn.writeCharacteristic(handle, value)
             time.sleep(0.4)
     else:
         conn.writeCharacteristic(handle, value)
     conn.disconnect()
     return
Exemplo n.º 12
0
 def action(self, message):
     mac = message['device']['id']
     handle = message['command']['handle']
     value = message['command']['value']
     type = message['command']['type']
     conn = Connector(mac)
     conn.connect()
     if not conn.isconnected:
         conn.connect()
         if not conn.isconnected:
             return
     try:
         if type == 'color':
             if value == '000000':
                 conn.writeCharacteristic(handle, '234277305C72')
             else:
                 value = self.intToStr(int(value[0:2], 16)) + self.intToStr(
                     int(value[2:4], 16)) + self.intToStr(
                         int(value[4:6], 16))
                 conn.writeCharacteristic(handle, '234577' + value + '5C72')
         elif type == 'ambient':
             conn.writeCharacteristic(handle, '234D77' + value + '5C72')
         elif type == 'brightness':
             conn.writeCharacteristic(
                 handle, '234377' + self.intToStr(int(value)) + '5C72')
         else:
             conn.writeCharacteristic(handle, value)
         conn.disconnect()
     except Exception, e:
         logging.error('Oups ' + str(e))
         conn.disconnect()
Exemplo n.º 13
0
 def read(self, mac):
     result = {}
     try:
         conn = Connector(mac)
         conn.connect()
         if not conn.isconnected:
             conn.connect()
             if not conn.isconnected:
                 return
         batteryFirm = bytearray(conn.readCharacteristic('0x38'))
         conn.writeCharacteristic('0x33', 'a01f', response=True)
         battery = batteryFirm[0]
         firmware = "".join(map(chr, batteryFirm[2:]))
         notification = Notification(conn, Miflora)
         conn.writeCharacteristic('0x36', '0100', response=True)
         result['battery'] = battery
         result['firmware'] = firmware
         result['id'] = mac
         received = bytearray(conn.readCharacteristic('0x35'))
         temperature = float(received[1] * 256 + received[0]) / 10
         if temperature > 3276.8:
             temperature = 0 - (6553.6 - temperature)
         sunlight = received[4] * 256 + received[3]
         moisture = received[7]
         fertility = received[9] * 256 + received[8]
         result['sunlight'] = sunlight
         result['moisture'] = moisture
         result['fertility'] = fertility
         result['temperature'] = temperature
         result['source'] = globals.daemonname
         logging.debug(str(result))
         globals.JEEDOM_COM.add_changes('devices::' + conn.mac, result)
         return result
     except Exception, e:
         logging.error(str(e))
Exemplo n.º 14
0
 def action(self, message):
     logging.debug('toto')
     type = ''
     mac = message['device']['id']
     handle = message['command']['handle']
     value = message['command']['value']
     if 'type' in message['command']:
         type = message['command']['type']
     if mac in globals.KEEPED_CONNECTION:
         logging.debug('Already a connection for ' + mac + ' use it')
         conn = globals.KEEPED_CONNECTION[mac]
     else:
         logging.debug('Creating a new connection for ' + mac)
         conn = Connector(mac)
         globals.KEEPED_CONNECTION[mac] = conn
         conn.connect()
     if not conn.isconnected:
         conn.connect()
         if not conn.isconnected:
             return
     if type == 'pair':
         conn.writeCharacteristic('0x12', '4367' + self.key)
         time.sleep(5)
     if type == 'switch':
         conn.writeCharacteristic('0x12', '4367' + self.key)
         conn.writeCharacteristic(handle, value.ljust(36, '0'))
     if type == 'color':
         conn.writeCharacteristic('0x12', '4367' + self.key)
         if value == '000000':
             conn.writeCharacteristic(handle, ('434002').ljust(36, '0'))
         else:
             conn.writeCharacteristic(handle,
                                      ('4341' + value).ljust(36, '0'))
     if type == 'brightness':
         init = utils.tuple_to_hex(
             struct.unpack('18B', conn.readCharacteristic('0x12')))
         conn.writeCharacteristic('0x12', '4367' + self.key)
         if str(init)[0:4] == '4343':
             logging.debug(str(init)[0:8])
             conn.writeCharacteristic(
                 handle,
                 str(init)[0:8] + hex(int(value))[2:].zfill(2) +
                 str(init)[10:36])
         else:
             conn.writeCharacteristic(
                 handle,
                 str(init)[0:12] + hex(int(value))[2:].zfill(2) +
                 str(init)[14:36])
     if type == 'white':
         conn.writeCharacteristic('0x12', '4367' + self.key)
         logging.debug('4343' +
                       (hex(int(value))[2:].zfill(4) + '00').ljust(36, '0'))
         conn.writeCharacteristic(handle,
                                  ('4343' + hex(int(value))[2:].zfill(4) +
                                   '00').ljust(36, '0'))
     conn.disconnect()
     return
Exemplo n.º 15
0
 def read(self, mac, connection=''):
     result = {}
     try:
         if mac in globals.KEEPED_CONNECTION:
             logging.debug('Already a connection for ' + mac + ' use it')
             conn = globals.KEEPED_CONNECTION[mac]
         else:
             if connection != '':
                 conn = connection
             else:
                 logging.debug('Creating a new connection for ' + mac)
                 conn = Connector(mac)
                 globals.KEEPED_CONNECTION[mac] = conn
                 conn.connect()
         if not conn.isconnected:
             conn.connect()
             if not conn.isconnected:
                 return
         refreshlist = globals.KNOWN_DEVICES[mac]['refreshlist']
         logging.debug('Here is the list to refresh ' + str(refreshlist))
         if 'color' in refreshlist:
             try:
                 color = utils.tuple_to_hex(
                     struct.unpack(
                         '4B',
                         conn.readCharacteristic(refreshlist['color'])))
                 if color[0:2] != '00':
                     color = 'FFFFFF'
                 else:
                     color = color[2:]
                 result['color'] = '#' + color
             except Exception, e:
                 logging.debug(str(e))
         if 'effect' in refreshlist:
             try:
                 effect = utils.tuple_to_hex(
                     struct.unpack(
                         '8B',
                         conn.readCharacteristic(refreshlist['effect'])))
                 mode = effect[8:10]
                 if mode == '04':
                     result['mode'] = 'Bougie'
                 elif mode == '01':
                     result['mode'] = 'Fondu uni'
                 elif mode == '00':
                     result['mode'] = 'Flash uni'
                 elif mode == '02':
                     result['mode'] = 'Flash arc-en-ciel'
                 elif mode == '03':
                     result['mode'] = 'Fondu arc-en-ciel'
                 else:
                     result['mode'] = 'Aucun'
                 speed = 255 - int(effect[12:14], 16)
                 result['speed'] = speed
             except Exception, e:
                 logging.debug(str(e))
Exemplo n.º 16
0
	def action(self,message):
		mac = message['device']['id']
		handle = message['command']['handle']
		value = message['command']['value']
		conn = Connector(mac)
		conn.connect()
		if not conn.isconnected:
			return
		conn.writeCharacteristic(handle,value)
		conn.disconnect()
		return
Exemplo n.º 17
0
	def action(self,message):
		type =''
		mac = message['device']['id']
		handle = message['command']['handle']
		value = message['command']['value']
		if 'type' in message['command']:
			type = message['command']['type']
		if mac in globals.KEEPED_CONNECTION:
			logging.debug('Already a connection for ' + mac + ' use it')
			conn = globals.KEEPED_CONNECTION[mac]
		else:
			logging.debug('Creating a new connection for ' + mac)
			conn = Connector(mac)
			globals.KEEPED_CONNECTION[mac]=conn
			conn.connect()
		if not conn.isconnected:
			conn.connect()
			if not conn.isconnected:
				return
		if type == 'speed':
			init = utils.tuple_to_hex(struct.unpack('8B',conn.readCharacteristic(handle)))
			speed = 255-int(value);
			if speed == 0: 
				speed = 1
			value = str(init)[0:12]+ hex(speed)[2:].zfill(2)+ str(init)[14:16]
		elif type == 'effect':
			init = utils.tuple_to_hex(struct.unpack('8B',conn.readCharacteristic(handle)))
			initcolor = utils.tuple_to_hex(struct.unpack('4B',conn.readCharacteristic(message['command']['color'])))
			value = str(initcolor) + value + '00' + str(init)[12:16]
		elif type == 'color':
			initeffect = utils.tuple_to_hex(struct.unpack('8B',conn.readCharacteristic(message['command']['effect'])))
			if str(initeffect)[8:10] == '04':
				valueprep = str(initeffect)[0:8] + 'ff' + '00' + str(initeffect)[12:16]
				result = conn.writeCharacteristic(message['command']['effect'],valueprep)
				if not result:
					conn.disconnect()
					logging.debug("Failed to write to device probably bad bluetooth connection")
		elif type == 'luminosity':
			value = utils.getTintedColor(message['command']['secondary'],value)
		arrayValue = [int('0x'+value[i:i+2],16) for i in range(0, len(value), 2)]
		result = conn.writeCharacteristic(handle,value)
		if not result:
			result = conn.writeCharacteristic(handle,value)
			if not result:
				logging.debug("Failed to write to device probably bad bluetooth connection")
		data={}
		data = self.read(mac,conn)
		if len(data)>2:
			data['source'] = globals.daemonname
			if type == 'luminosity':
				data['luminosity'] = luminosityvalue
			globals.JEEDOM_COM.add_changes('devices::'+mac,data)
		conn.disconnect()
		return
Exemplo n.º 18
0
 def read(self, mac):
     result = {}
     try:
         conn = Connector(mac)
         conn.connect()
         if not conn.isconnected:
             conn.connect()
             if not conn.isconnected:
                 return
         batteryDatas = bytearray(conn.readCharacteristic('0x2c'))
         if len(batteryDatas) == 10:
             battery = batteryDatas[0]
             status = batteryDatas[9]
             cycle = batteryDatas[7] + batteryDatas[8]
             year = str(batteryDatas[1] + 2000)
             month = str(batteryDatas[2] + 1)
             day = str(batteryDatas[3])
             hour = str(batteryDatas[4])
             minutes = str(batteryDatas[5])
             seconds = str(batteryDatas[6])
             if status == 1:
                 status = 'Faible'
             elif status == 2:
                 status = 'En charge'
             elif status == 3:
                 status = 'Branché Full'
             elif status == 4:
                 status = 'Débranché'
             else:
                 status = 'Inconnu'
             result['battery'] = battery
             result['status'] = status
             result['cycle'] = cycle
             result[
                 'lastcharge'] = day + '/' + month + '/' + year + ' ' + hour + 'h' + minutes + 'min' + seconds + 's'
         firmwareDatas = bytearray(conn.readCharacteristic('0x12'))
         firmware = str(firmwareDatas[15]) + '.' + str(
             firmwareDatas[14]) + '.' + str(firmwareDatas[13]) + '.' + str(
                 firmwareDatas[12])
         stepsDatas = conn.readCharacteristic('0x1d')
         steps = ord(stepsDatas[0]) + (ord(stepsDatas[1]) << 8)
         result['steps'] = steps
         result['firmware'] = firmware
         result['id'] = mac
         logging.debug(str(result))
         conn.disconnect()
         return result
     except Exception as e:
         logging.error(str(e))
         conn.disconnect()
     return result
Exemplo n.º 19
0
 def parse(self, data, mac, name, manuf):
     result = {}
     result['present'] = 1
     try:
         conn = Connector(mac)
         conn.connect()
         if not conn.isconnected:
             conn.connect()
             if not conn.isconnected:
                 return
         notification = Notification(conn, LogiSwitch)
         notification.subscribe(2)
     except Exception, e:
         logging.error(str(e))
Exemplo n.º 20
0
 def action(self, message):
     mac = message['device']['id']
     handle = message['command']['handle']
     value = message['command']['value']
     conn = Connector(mac)
     conn.connect()
     if not conn.isconnected:
         conn.connect()
         if not conn.isconnected:
             return
     try:
         if 'key' in message['command']:
             conn.writeCharacteristic('0x19',
                                      message['command']['key'],
                                      response=True)
         if handle == '0x4e':
             conn.writeCharacteristic(handle, value, response=True)
             conn.connect()
             if not conn.isconnected:
                 conn.connect()
                 if not conn.isconnected:
                     return
             conn.writeCharacteristic('0x51', '04')
             notification = Notification(conn, Miband)
             notification.subscribe(20)
             conn.writeCharacteristic('0x4c', '0100', response=True)
         else:
             conn.writeCharacteristic(handle, value)
             if value == '02':
                 time.sleep(10)
             conn.disconnect()
     except Exception as e:
         logging.error(str(e))
         conn.disconnect()
     return
Exemplo n.º 21
0
 def read(self, mac, connection=''):
     result = {}
     chars = []
     try:
         if mac in globals.KEEPED_CONNECTION:
             logging.debug('Already a connection for ' + mac + ' use it')
             conn = globals.KEEPED_CONNECTION[mac]
         else:
             if connection != '':
                 conn = connection
             else:
                 logging.debug('Creating a new connection for ' + mac)
                 conn = Connector(mac)
                 conn.connect(type='random')
         if not conn.isconnected:
             return
         if (mac in globals.KNOWN_DEVICES):
             if ('specificconfiguration' in globals.KNOWN_DEVICES[mac]
                     and len(globals.KNOWN_DEVICES[mac]
                             ['specificconfiguration']) > 0):
                 logging.debug('Already known handles ' + str(
                     globals.KNOWN_DEVICES[mac]['specificconfiguration']))
                 chars = [
                     globals.KNOWN_DEVICES[mac]['specificconfiguration']
                     ['batteryhandle']
                 ]
         if chars == []:
             logging.debug('Not known handles searching')
             chars = self.findCharacteristics(mac, conn)
             globals.JEEDOM_COM.add_changes(
                 'devices::' + mac, {
                     "id": mac,
                     "specificconfiguration": {
                         "batteryhandle": chars[0]
                     }
                 })
         char = chars[0]
         batteryDatas = bytearray(
             conn.readCharacteristic(char, type='random'))
         logging.debug(str(batteryDatas))
         result['battery'] = batteryDatas[0]
         result['id'] = mac
         logging.debug(str(result))
         return result
     except Exception as e:
         logging.error(str(e))
         conn.disconnect()
     conn.disconnect()
     return result
Exemplo n.º 22
0
	def parse(self,data,mac,name,manuf):
		action={}
		action['present'] = 1
		if mac.upper() in globals.KNOWN_DEVICES and globals.KNOWN_DEVICES[mac.upper()]['emitterallowed'] == globals.daemonname and globals.KNOWN_DEVICES[mac.upper()]['islocked'] == 1:
			conn = Connector(mac)
			conn.connect()
			if not conn.isconnected:
				conn.connect()
				if not conn.isconnected:
					return action
			conn.writeCharacteristic('0x36','0100')
			notification = Notification(conn,Itag)
			notification.subscribe()
			globals.KEEPED_CONNECTION[mac.upper()]=conn
		return action
Exemplo n.º 23
0
 def read(self, mac):
     result = {}
     try:
         conn = Connector(mac)
         conn.connect(type='random')
         if not conn.isconnected:
             conn.connect(type='random')
             if not conn.isconnected:
                 return
         batteryDatas = bytearray(
             conn.readCharacteristic('0x43', type='random'))
         if len(batteryDatas) >= 11:
             battery = batteryDatas[1]
             status = batteryDatas[2]
             cycle = batteryDatas[7] + batteryDatas[8]
             year = str(
                 int(
                     str(
                         hex(batteryDatas[12])[2:].zfill(2) +
                         hex(batteryDatas[11])[2:].zfill(2)), 16))
             month = str(batteryDatas[13])
             day = str(batteryDatas[14])
             hour = str(batteryDatas[15])
             minutes = str(batteryDatas[16])
             seconds = str(batteryDatas[17])
             lastchargelevel = str(batteryDatas[19])
             if status == 0:
                 status = 'Débranché'
             elif status == 1:
                 status = 'En charge'
             else:
                 status = 'Inconnu'
             result['battery'] = battery
             result['status'] = status
             result['firmware'] = str(
                 conn.readCharacteristic('0x10')) + '/' + str(
                     conn.readCharacteristic('0x12'))
             result['lastchargelevel'] = lastchargelevel
             result[
                 'lastcharge'] = day + '/' + month + '/' + year + ' ' + hour + 'h' + minutes + 'min' + seconds + 's'
         result['id'] = mac
         #conn.writeCharacteristic('0x51','0100',type='random')
         #notification = Notification(conn,Miband2,{'action':'write','handle':'0x3d','value':'02','type':'random'})
         #notification.subscribe(10)
         #conn.writeCharacteristic('0x50', '0200',type='random')
         logging.debug(str(result))
     except Exception, e:
         logging.error(str(e))
Exemplo n.º 24
0
    def read(self, mac, connection=''):
        if 'localname' in globals.KNOWN_DEVICES[mac.upper()]:
            # Make it works directly with devices paired by remote control (for testing)
            if globals.KNOWN_DEVICES[mac.upper()]['localname'].startswith(
                    "R-"):
                self.mesh_name = globals.KNOWN_DEVICES[
                    mac.upper()]['localname']
                self.mesh_password = P_DEFAULTPASSWORD

        if mac in globals.KEEPED_CONNECTION:
            logging.debug('Already a connection for ' + mac + ' use it')
            conn = globals.KEEPED_CONNECTION[mac]
        else:
            logging.debug('Creating a new connection for ' + mac)
            conn = Connector(mac)
            globals.KEEPED_CONNECTION[mac] = conn

        i = 1
        authresult = False
        while i <= 2:
            i = i + 1
            if not conn.isconnected:
                try:
                    conn.connect(retry=1)
                except:
                    pass
            if conn.isconnected:
                authresult = self.auth(conn)
            if authresult:
                break
            else:
                time.sleep(1)

        if not authresult:
            logging.debug(
                'Ending action due to authentication error on device')
            globals.PENDING_ACTION = False
            return result

        # send message
        notification = Notification(conn, Awoxmesh, {
            'mac': conn.mac,
            'session': self.session_key
        })
        notification.subscribe(timer=NOTIF_TIMEOUT, disconnect=False)
        conn.readCharacteristic(STATUS_CHAR_UUID)

        return {}
Exemplo n.º 25
0
 def action(self, message):
     logging.debug('action:  ' + str(message))
     mac = message['device']['id']
     handle = message['command']['handle']
     value = message['command']['value']
     try:
         conn = Connector(mac)
         conn.connect()
         if not conn.isconnected:
             conn.connect()
             if not conn.isconnected:
                 return
         conn.writeCharacteristic(handle, value)
         logging.debug('action:  (done) ' + str(message))
     except Exception as e:
         logging.error(str(e))
Exemplo n.º 26
0
 def parse(self, data, mac, name, manuf):
     action = {}
     action['present'] = 1
     try:
         conn = Connector(mac)
         conn.connect()
         if not conn.isconnected:
             return
         notification = Notification(conn, KST1)
         conn.writeCharacteristic('0x2c', '0100', response=True)
         batteryData = (conn.readCharacteristic('0x3a')).hex()
         logging.debug(str(batteryData))
         action['battery'] = int(batteryData, 16)
         notification.subscribe(20)
     except Exception as e:
         logging.error(str(e))
     return action
Exemplo n.º 27
0
	def findVersion(self,mac):
		conn = Connector(mac)
		conn.connect()
		if not conn.isconnected:
			conn.connect()
			if not conn.isconnected:
				return
		value=''
		characteristics = conn.getCharacteristics()
		for char in characteristics:
			try:
				if char.supportsRead():
					valueChar = char.read()
					if valueChar and valueChar[0:3] == 'BTL' and len(valueChar)>6 and len(valueChar)>len(value):
						value = valueChar
			except Exception,e:
				continue
Exemplo n.º 28
0
 def read(self, mac):
     result = {}
     try:
         conn = Connector(mac)
         conn.connect()
         if not conn.isconnected:
             conn.connect()
             if not conn.isconnected:
                 return
         batterytrame = conn.readCharacteristic('0x1b')
         logging.debug('GIGASET------Parsing data ' + batterytrame)
         battery = int(batterytrame.encode("hex"), 16)
         result['battery'] = battery
         result['present'] = 1
     except Exception, e:
         logging.error(str(e))
         conn.disconnect()
Exemplo n.º 29
0
	def action(self,message):
		mac = message['device']['id']
		handle = message['command']['handle']
		value = message['command']['value']
		conn = Connector(mac)
		conn.connect(type='random')
		if not conn.isconnected:
			conn.connect(type='random')
			if not conn.isconnected:
				return
		conn.writeCharacteristic('0x55','0100',type='random')
		notification = Notification(conn,Miband2,{'action':'write','handle':handle,'value':value,'type':'random'})
		if handle == '0x2b':
			notification.subscribe(20)
		else:
			notification.subscribe(1)
		conn.writeCharacteristic('0x54', '0200',type='random')
		return
Exemplo n.º 30
0
 def read(self, mac):
     result = {}
     try:
         conn = Connector(mac)
         conn.connect(type='random')
         if not conn.isconnected:
             conn.connect(type='random')
             if not conn.isconnected:
                 return
         batteryDatas = bytearray(conn.readCharacteristic('0x17'),
                                  type='random')
         result['battery'] = batteryDatas[0]
         result['id'] = mac
         logging.debug(str(result))
         return result
     except Exception, e:
         logging.error(str(e))
         conn.disconnect()