def testConvertBase64(self): params = [rpcbase64(base64.b64encode(b"Hello, world!"))] params_xml = py2xml(*params) expected_xml = self.parse_xml(""" <params xmlns="jabber:iq:rpc"> <param> <value> <base64>SGVsbG8sIHdvcmxkIQ==</base64> </value> </param> </params> """) alternate_xml = self.parse_xml(""" <params xmlns="jabber:iq:rpc"> <param> <value> <Base64>SGVsbG8sIHdvcmxkIQ==</Base64> </value> </param> </params> """) self.assertTrue(self.compare(expected_xml, params_xml), "Base64 to XML conversion\nExpected: %s\nGot: %s" % ( tostring(expected_xml), tostring(params_xml))) self.assertEqual(list(map(lambda x: x.decode(), params)), list(map(lambda x: x.decode(), xml2py(expected_xml))), "XML to base64 conversion") self.assertEqual(list(map(lambda x: x.decode(), params)), list(map(lambda x: x.decode(), xml2py(alternate_xml))), "Alternate XML to base64 conversion")
def testConvertArray(self): params = [[1,2,3], ('a', 'b', 'c')] params_xml = py2xml(*params) expected_xml = self.parse_xml(""" <params xmlns="jabber:iq:rpc"> <param> <value> <array> <data> <value><i4>1</i4></value> <value><i4>2</i4></value> <value><i4>3</i4></value> </data> </array> </value> </param> <param> <value> <array> <data> <value><string>a</string></value> <value><string>b</string></value> <value><string>c</string></value> </data> </array> </value> </param> </params> """) self.assertTrue(self.compare(expected_xml, params_xml), "Array to XML conversion\nExpected: %s\nGot: %s" % ( tostring(expected_xml), tostring(params_xml))) self.assertEqual(list(map(list, params)), xml2py(expected_xml), "XML to array conversion")
def testConvertStruct(self): params = [{"foo": "bar", "baz": False}] params_xml = py2xml(*params) expected_xml = self.parse_xml(""" <params xmlns="jabber:iq:rpc"> <param> <value> <struct> <member> <name>foo</name> <value><string>bar</string></value> </member> <member> <name>baz</name> <value><boolean>0</boolean></value> </member> </struct> </value> </param> </params> """) self.assertTrue(self.compare(expected_xml, params_xml), "Struct to XML conversion\nExpected: %s\nGot: %s" % ( tostring(expected_xml), tostring(params_xml))) self.assertEqual(params, xml2py(expected_xml), "XML to struct conversion")
def rpc_callback(self, iq): iq.enable('rpc_query') if iq['rpc_query']['method_response']['fault'] is not None: fault = iq['rpc_query']['method_response']['fault'] log.info(fault['string']) else: result = xml2py(iq['rpc_query']['method_response']['params']) log.info('method response: %s', result[0])
def rpc_callback(self, my_iq): ''' Capture messages returning from the sysap ''' my_iq.enable('rpc_query') if my_iq['rpc_query']['method_response']['fault'] is not None: fault = my_iq['rpc_query']['method_response']['fault'] LOG.info(fault['string']) else: result = xml2py(my_iq['rpc_query']['method_response']['params']) LOG.info('method response: %s', result[0])
def _on_jabber_rpc_method_response(self, iq): iq.enable('rpc_query') args = xml2py(iq['rpc_query']['method_response']['params']) pid = iq['id'] with self._lock: callback = self._callbacks[pid] del self._callbacks[pid] if (len(args) > 0): callback.set_value(args[0]) else: callback.set_value(None) pass
async def get_config(self): """Get config file via getAll RPC""" my_iq = await self.send_rpc_iq('RemoteInterface.getAll', 'de', 2, 0, 0) my_iq.enable('rpc_query') if my_iq['rpc_query']['method_response']['fault'] is not None: fault = my_iq['rpc_query']['method_response']['fault'] LOG.info(fault['string']) return None args = xml2py(my_iq['rpc_query']['method_response']['params']) return args[0]
def _on_jabber_rpc_method_response(self, iq): iq.enable('rpc_query') args = xml2py(iq['rpc_query']['method_response']['params']) pid = iq['id'] with self._lock: callback = self._callbacks[pid] del self._callbacks[pid] if(len(args) > 0): callback.set_value(args[0]) else: callback.set_value(None) pass
def testConvertInteger(self): params = [32767, -32768] params_xml = py2xml(*params) expected_xml = self.parse_xml(""" <params xmlns="jabber:iq:rpc"> <param> <value> <i4>32767</i4> </value> </param> <param> <value> <i4>-32768</i4> </value> </param> </params> """) alternate_xml = self.parse_xml(""" <params xmlns="jabber:iq:rpc"> <param> <value> <int>32767</int> </value> </param> <param> <value> <int>-32768</int> </value> </param> </params> """) self.assertTrue(self.compare(expected_xml, params_xml), "Integer to XML conversion\nExpected: %s\nGot: %s" % ( tostring(expected_xml), tostring(params_xml))) self.assertEqual(params, xml2py(expected_xml), "XML to boolean conversion") self.assertEqual(params, xml2py(alternate_xml), "Alternate XML to boolean conversion")
def testConvertString(self): params = ["'This' & \"That\""] params_xml = py2xml(*params) expected_xml = self.parse_xml(""" <params xmlns="jabber:iq:rpc"> <param> <value> <string>'This' & "That"</string> </value> </param> </params> """) self.assertTrue(self.compare(expected_xml, params_xml), "String to XML conversion\nExpected: %s\nGot: %s" % ( tostring(expected_xml), tostring(params_xml))) self.assertEqual(params, xml2py(expected_xml), "XML to string conversion")
def testConvertUnicodeString(self): params = ["おはよう"] params_xml = py2xml(*params) expected_xml = self.parse_xml(""" <params xmlns="jabber:iq:rpc"> <param> <value> <string>おはよう</string> </value> </param> </params> """) self.assertTrue(self.compare(expected_xml, params_xml), "String to XML conversion\nExpected: %s\nGot: %s" % ( tostring(expected_xml), tostring(params_xml))) self.assertEqual(params, xml2py(expected_xml), "XML to string conversion")
def testConvertNil(self): params = [None] params_xml = py2xml(*params) expected_xml = self.parse_xml(""" <params xmlns="jabber:iq:rpc"> <param> <value> <nil /> </value> </param> </params> """) self.assertTrue(self.compare(expected_xml, params_xml), "Nil to XML conversion\nExpected: %s\nGot: %s" % ( tostring(expected_xml), tostring(params_xml))) self.assertEqual(params, xml2py(expected_xml), "XML to nil conversion")
def testConvertDouble(self): params = [3.14159265] params_xml = py2xml(*params) expected_xml = self.parse_xml(""" <params xmlns="jabber:iq:rpc"> <param> <value> <double>3.14159265</double> </value> </param> </params> """) self.assertTrue(self.compare(expected_xml, params_xml), "Double to XML conversion\nExpected: %s\nGot: %s" % ( tostring(expected_xml), tostring(params_xml))) self.assertEqual(params, xml2py(expected_xml), "XML to double conversion")
def testConvertDateTime(self): params = [rpctime("20111220T01:50:00")] params_xml = py2xml(*params) expected_xml = self.parse_xml(""" <params xmlns="jabber:iq:rpc"> <param> <value> <dateTime.iso8601>20111220T01:50:00</dateTime.iso8601> </value> </param> </params> """) self.assertTrue(self.compare(expected_xml, params_xml), "DateTime to XML conversion\nExpected: %s\nGot: %s" % ( tostring(expected_xml), tostring(params_xml))) self.assertEqual(list(map(lambda x: x.iso8601(), params)), list(map(lambda x: x.iso8601(), xml2py(expected_xml))), None)
def _on_jabber_rpc_method_call(self, iq): iq.enable('rpc_query') params = iq['rpc_query']['method_call']['params'] args = xml2py(params) pmethod = iq['rpc_query']['method_call']['method_name'] try: with self._lock: entry = self._entries[pmethod] rules = self._acls[entry.get_endpoint_FQN()] if ACL.check(rules, iq['from'], pmethod): return_value = entry.call_method(args) else: raise AuthorizationException( "Unauthorized access to %s from %s!" % (pmethod, iq['from'])) if return_value is None: return_value = () response = self._client.plugin['xep_0009'].make_iq_method_response( iq['id'], iq['from'], py2xml(*return_value)) response.send() except InvocationException as ie: fault = dict() fault['code'] = 500 fault['string'] = ie.get_message() self._client.plugin['xep_0009']._send_fault(iq, fault2xml(fault)) except AuthorizationException as ae: log.error(ae.get_message()) error = self._client.plugin['xep_0009']._forbidden(iq) error.send() except Exception as e: if isinstance(e, KeyError): log.error("No handler available for %s!", pmethod) error = self._client.plugin['xep_0009']._item_not_found(iq) else: traceback.print_exc(file=sys.stderr) log.error("An unexpected problem occurred invoking method %s!", pmethod) error = self._client.plugin['xep_0009']._undefined_condition( iq) #! print "[REMOTE.PY] _handle_remote_procedure_call AN ERROR SHOULD BE SENT NOW %s " % e error.send()
def testConvertBoolean(self): params = [True, False] params_xml = py2xml(*params) expected_xml = self.parse_xml(""" <params xmlns="jabber:iq:rpc"> <param> <value> <boolean>1</boolean> </value> </param> <param> <value> <boolean>0</boolean> </value> </param> </params> """) self.assertTrue(self.compare(expected_xml, params_xml), "Boolean to XML conversion\nExpected: %s\nGot: %s" % ( tostring(expected_xml), tostring(params_xml))) self.assertEqual(params, xml2py(expected_xml), "XML to boolean conversion")
def _on_jabber_rpc_method_call(self, iq): iq.enable('rpc_query') params = iq['rpc_query']['method_call']['params'] args = xml2py(params) pmethod = iq['rpc_query']['method_call']['method_name'] try: with self._lock: entry = self._entries[pmethod] rules = self._acls[entry.get_endpoint_FQN()] if ACL.check(rules, iq['from'], pmethod): return_value = entry.call_method(args) else: raise AuthorizationException("Unauthorized access to %s from %s!" % (pmethod, iq['from'])) if return_value is None: return_value = () response = self._client.plugin['xep_0009'].make_iq_method_response(iq['id'], iq['from'], py2xml(*return_value)) response.send() except InvocationException as ie: fault = dict() fault['code'] = 500 fault['string'] = ie.get_message() self._client.plugin['xep_0009']._send_fault(iq, fault2xml(fault)) except AuthorizationException as ae: log.error(ae.get_message()) error = self._client.plugin['xep_0009']._forbidden(iq) error.send() except Exception as e: if isinstance(e, KeyError): log.error("No handler available for %s!", pmethod) error = self._client.plugin['xep_0009']._item_not_found(iq) else: traceback.print_exc(file=sys.stderr) log.error("An unexpected problem occurred invoking method %s!", pmethod) error = self._client.plugin['xep_0009']._undefined_condition(iq) #! print "[REMOTE.PY] _handle_remote_procedure_call AN ERROR SHOULD BE SENT NOW %s " % e error.send()
def rpc_callback(self, iq): log.info("Rpc callback jhe ") iq.enable('rpc_query') if iq['rpc_query']['method_response']['fault'] is not None: fault = iq['rpc_query']['method_response']['fault'] log.info(fault['string']) else: args = xml2py(iq['rpc_query']['method_response']['params']) """ deviceID 'B002', // Schaltaktor 4-fach, 16A, REG '100E', // Sensor/ Schaltaktor 2/1-fach 'B008', // Sensor/ Schaltaktor 8/8fach, REG '10C4' // Hue Aktor (Plug Switch) '101C', // Dimmaktor 4-fach '1021', // Dimmaktor 4-fach v2 '10C0' // Hue Aktor (LED Strip) 'B001', // Jalousieaktor 4-fach, REG '1013' // Sensor/ Jalousieaktor 1/1-fach """ log.info(len(args)) # Nu een iteratie over de devices root = ET.fromstring(args[0]) filename = 'mastermessage.xml' with open(filename,'w', encoding="utf-8") as file_object: file_object.write(args[0]) for child in root: log.info(child.tag) strings = root.find('strings') # Zet de strings in een dictionary names = {} for string in strings.findall('string'): stringNameId = string.get('nameId') stringValue = string.text names[stringNameId] = stringValue #log.info("%s", names) device = root.find('devices') for neighbor in device.findall('device'): serialNumber = neighbor.get('serialNumber') nameId = names[neighbor.get('nameId')].title() deviceId = neighbor.get('deviceId') log.info(" %s %s %s %s",serialNumber,neighbor.get('nameId'),nameId,deviceId) # Schaltaktor 4-fach, 16A, REG if deviceId == 'B002': # Nu de channnels binnen een device channels = neighbor.find('channels') if channels is not None: for channel in channels.findall('channel'): channelName = names[channel.get('nameId')].title() channelId = channel.get('i') log.info(" %s %s",channelId, channelName) for attributes in channel.findall('attribute'): attributeName = attributes.get('name') attributeValue = attributes.text log.info(" %s %s",attributeName, attributeValue) inputs = channel.find('inputs') for datapoints in inputs.findall('dataPoint'): datapointId = datapoints.get('i') datapointValue = datapoints.find('value').text if datapointId == 'idp0000': if datapointValue == '1': light_state = True else: light_state = False log.info(" %s %s %s",datapointId, datapointValue, light_state) # Dimmaktor 4-fach and Dimmaktor 4-fach v2 if deviceId == '101C' or deviceId == '1021': # Nu de channnels binnen een device channels = neighbor.find('channels') if channels is not None: for channel in channels.findall('channel'): channelName = names[channel.get('nameId')].title() channelId = channel.get('i') log.info(" %s %s",channelId, channelName) for attributes in channel.findall('attribute'): attributeName = attributes.get('name') attributeValue = attributes.text log.info(" %s %s",attributeName, attributeValue) inputs = channel.find('inputs') for datapoints in inputs.findall('dataPoint'): datapointId = datapoints.get('i') datapointValue = datapoints.find('value').text if datapointId == 'idp0000': if datapointValue == '1': light_state = True else: light_state = False log.info(" %s %s %s",datapointId, datapointValue, light_state) # switch if deviceId == '1002' or deviceId == '1000' or deviceId == '100A': # Nu de channnels binnen een device channels = neighbor.find('channels')
async def find_devices(self, use_room_names): ''' Find the devices in the system, this is a big XML file ''' self.use_room_names = use_room_names my_iq = await self.send_rpc_iq('RemoteInterface.getAll', 'de', 4, 0, 0) my_iq.enable('rpc_query') if my_iq['rpc_query']['method_response']['fault'] is not None: fault = my_iq['rpc_query']['method_response']['fault'] LOG.info(fault['string']) else: args = xml2py(my_iq['rpc_query']['method_response']['params']) # deviceID # 'B002', // Schaltaktor 4-fach, 16A, REG # '100E', // Sensor/ Schaltaktor 2/1-fach # 'B008', // Sensor/ Schaltaktor 8/8fach, REG # '100C', // Sensor/schakelaktor 1/1-voudig # 'FFE7', // Sensor/schakelaktor 2/2-voudig # # '10C4' // Hue Aktor (Plug Switch) # # '101C', // Dimmaktor 4-fach # '1021', // Dimmaktor 4-fach v2 # '1017' // Sensor/dimaktor 1/1-voudig # '10C0' // Hue Aktor (LED Strip) # # 'B001', // Jalousieaktor 4-fach, REG # '1013' // Sensor/ Jalousieaktor 1/1-fach # '1015' // Sensor/ Jalousieaktor 2/1-fach self.found_devices = True root = ET.fromstring(args[0]) # make a list of the rooms roomnames = get_room_names(root) # Now look for the devices device = root.find('devices') for neighbor in device.findall('device'): serialnumber = neighbor.get('serialNumber') device_id = neighbor.get('deviceId') # Switch actuators if (device_id == 'B002' or device_id == '100E' or device_id == 'B008' or \ device_id == '10C4' or device_id == '100C' or device_id == '1010'): self.add_light_device(neighbor, serialnumber, roomnames) # Dimming actuators # Hue Aktor (LED Strip), Sensor/dimaktor 1/1-voudig if (device_id == '101C' or device_id == '1021' or \ device_id == '10C0' or device_id == '1017'): self.add_dimmer_device(neighbor, serialnumber, roomnames) # Scene or Timer if device_id == '4800' or device_id == '4A00': self.add_scene(neighbor, serialnumber, roomnames) # blind/cover device if device_id == 'B001' or device_id == '1013' or device_id == '1015': self.add_cover_device(neighbor, serialnumber, roomnames) # Sensor units 1/2 way if device_id == '1002' or device_id == '1000': self.add_sensor_unit(neighbor, serialnumber, roomnames, device_id) # binary sensor if device_id == 'B007': self.add_binary_sensor(neighbor, serialnumber, roomnames) # movement detector if device_id == '100A': self.add_movement_detector(neighbor, serialnumber, roomnames)
async def initiate_key_exchange(self): log.debug('start key exchange') key_bytes = self.crypto.generateLocalKey() key = base64.b64encode(key_bytes) try: iq = await self.send_cryptExchangeLocalKeys2(self.x_jid, key) except (NameError, ValueError) as e: print(e) except: print('error send_cryptExchangeLocalKeys2 ', sys.exc_info()[0]) else: log.debug('crypt_exchange_callback') iq.enable('rpc_query') if iq['rpc_query']['method_response']['fault'] is not None: fault = iq['rpc_query']['method_response']['fault'] log.info(fault['string']) else: if iq['rpc_query']['method_response']['params'] is not None: args = xml2py(iq['rpc_query']['method_response']['params']) keymessage = args[0].decode() log.debug('Received Local Key') sessionidentifier = self.crypto.completeKeyExchange( keymessage) payload = self.StartNewSessionPayload(sessionidentifier) log.debug('Sending new session') try: iq = await self.send_cryptMessage( base64.b64encode(payload)) except (NameError, ValueError, TypeError) as e: print(e) except: print('error send_cryptMessage ', sys.exc_info()[0]) else: iq.enable('rpc_query') if iq['rpc_query']['method_response'][ 'fault'] is not None: fault = iq['rpc_query']['method_response']['fault'] log.info(fault['string']) else: if iq['rpc_query']['method_response'][ 'params'] is not None: log.info('Received new session result') args = xml2py(iq['rpc_query'] ['method_response']['params']) log.info(len(args)) newsessionresponse = args[0].decode() log.debug('Received new session response') self.crypto.decodeNewSessionResult( newsessionresponse ) # result is a string + blob scram = self.crypto.clientScramHandler.createClientFirst( self.x_jid) login = loginSaslPayload(scram) payload = self.crypto.encryptPayload(login) log.debug('Sending login sasl') try: iq = await self.send_cryptMessage( base64.b64encode(payload)) except: print('error send_cryptMessage ', sys.exc_info()[0]) else: iq.enable('rpc_query') if iq['rpc_query']['method_response'][ 'fault'] is not None: fault = iq['rpc_query'][ 'method_response']['fault'] log.info(fault['string']) else: if iq['rpc_query']['method_response'][ 'params'] is not None: log.info( 'Received response login sasl') args = xml2py( iq['rpc_query']['method_response'] ['params']) saslChallengeResponse = args[0].decode( ) saslChallengeMessage = self.crypto.decryptPayload( saslChallengeResponse ) # returns messageReader object msgId = saslChallengeMessage.readUint8( ) if msgId == FAHMessage.MSG_ID_SASL_CHALLENGE: log.debug( "Received SASL Challenge") clientFinal = self.crypto.processSaslChallenge( saslChallengeMessage) saslResponse = buildSaslResponse( clientFinal) payload = self.crypto.encryptPayload( saslResponse) log.debug('Sending sasl response') try: iq = await self.send_cryptMessage( base64.b64encode(payload)) except: print( 'error send_cryptMessage ', sys.exc_info()[0]) else: iq.enable('rpc_query') if iq['rpc_query'][ 'method_response'][ 'fault'] is not None: fault = iq['rpc_query'][ 'method_response'][ 'fault'] log.info(fault['string']) else: if iq['rpc_query'][ 'method_response'][ 'params'] is not None: log.info( 'Received response challenge' ) args = xml2py( iq['rpc_query'] ['method_response'] ['params']) saslChallengeResponse2 = args[ 0].decode() saslSucces = self.crypto.decryptPayload( saslChallengeResponse2 ) msgId = saslSucces.readUint8( ) if msgId == FAHMessage.MSG_ID_SASL_LOGIN_SUCCESS: self.crypto.processSaslFinal( saslSucces) log.info( "Received SASL Login Confirmation" ) log.info( "Successfully Authenticated" ) else: log.info("Wrong response ", msgId)
def find_devices(self, use_room_names): iq = yield from self.send_rpc_iq('RemoteInterface.getAll', 'de', 4, 0, 0) iq.enable('rpc_query') if iq['rpc_query']['method_response']['fault'] is not None: fault = iq['rpc_query']['method_response']['fault'] log.info(fault['string']) else: args = xml2py(iq['rpc_query']['method_response']['params']) """ deviceID 'B002', // Schaltaktor 4-fach, 16A, REG '100E', // Sensor/ Schaltaktor 2/1-fach 'B008', // Sensor/ Schaltaktor 8/8fach, REG '100C', // Sensor/schakelaktor 1/1-voudig 'FFE7', // Sensor/schakelaktor 2/2-voudig '10C4' // Hue Aktor (Plug Switch) '101C', // Dimmaktor 4-fach '1021', // Dimmaktor 4-fach v2 '1017' // Sensor/dimaktor 1/1-voudig '10C0' // Hue Aktor (LED Strip) 'B001', // Jalousieaktor 4-fach, REG '1013' // Sensor/ Jalousieaktor 1/1-fach """ self.found_devices = True root = ET.fromstring(args[0]) strings = root.find('strings') # Store all the names names = {} for string in strings.findall('string'): stringNameId = string.get('nameId') stringValue = string.text names[stringNameId] = stringValue # make a list of the rooms floorplan = root.find('floorplan') floornames = {} roomnames = {} for floor in floorplan.findall('floor'): FloorName = floor.get('name') FloorUid = floor.get('uid') floornames[FloorUid] = FloorName log.info(' floor %s', FloorName) roomnames[FloorUid] = {} # Now the rooms of this floor for room in floor.findall('room'): RoomName = room.get('name') RoomUid = room.get('uid') roomnames[FloorUid][RoomUid] = RoomName # Now look for the devices device = root.find('devices') for neighbor in device.findall('device'): serialNumber = neighbor.get('serialNumber') nameId = names[neighbor.get('nameId')].title() deviceId = neighbor.get('deviceId') # Schaltaktor 4-fach, 16A, REG if deviceId == 'B002' or deviceId == '100E' or deviceId == 'B008' or deviceId == '10C4' or deviceId == '100C' or deviceId == '1010': # Now the channels of a device channels = neighbor.find('channels') if channels is not None: for channel in channels.findall('channel'): channelName = names[channel.get('nameId')].title() channelId = channel.get('i') light_name = '' floorId = '' roomId = '' for attributes in channel.findall('attribute'): attributeName = attributes.get('name') attributeValue = attributes.text if attributeName == 'displayName': light_name = attributeValue if attributeName == 'floor': floorId = attributeValue if attributeName == 'room': roomId = attributeValue inputs = channel.find('inputs') for datapoints in inputs.findall('dataPoint'): datapointId = datapoints.get('i') datapointValue = datapoints.find('value').text outputs = channel.find('outputs') for datapoints in outputs.findall('dataPoint'): datapointId = datapoints.get('i') datapointValue = datapoints.find('value').text if datapointId == 'odp0000': if datapointValue == '1': light_state = True else: light_state = False single_light = serialNumber + '/' + channelId if light_name == '': light_name = single_light if floorId != '' and roomId != '' and use_room_names == True: light_name = light_name + ' (' + roomnames[ floorId][roomId] + ')' self.light_devices[ single_light] = self.add_light_info( name=light_name, state=light_state, floor=floornames[floorId], room=roomnames[floorId][roomId]) else: self.light_devices[ single_light] = self.add_light_info( name=light_name, state=light_state, floor='', room='') self.devices[single_light] = 'light' log.info('light %s %s is %s', single_light, light_name, light_state) # Dimmaktor 4-fach and Dimmaktor 4-fach v2 if deviceId == '101C' or deviceId == '1021' or deviceId == '10C0' or deviceId == '1017': # Now the channels of a device channels = neighbor.find('channels') if channels is not None: for channel in channels.findall('channel'): channelName = names[channel.get('nameId')].title() channelId = channel.get('i') light_name = '' floorId = '' roomId = '' brightness = None for attributes in channel.findall('attribute'): attributeName = attributes.get('name') attributeValue = attributes.text if attributeName == 'displayName': light_name = attributeValue if attributeName == 'floor': floorId = attributeValue if attributeName == 'room': roomId = attributeValue inputs = channel.find('inputs') for datapoints in inputs.findall('dataPoint'): datapointId = datapoints.get('i') datapointValue = datapoints.find('value').text outputs = channel.find('outputs') for datapoints in outputs.findall('dataPoint'): datapointId = datapoints.get('i') datapointValue = datapoints.find('value').text if datapointId == 'odp0001': brightness = datapointValue if datapointId == 'odp0000': if datapointValue == '1': light_state = True else: light_state = False single_light = serialNumber + '/' + channelId if light_name == '': light_name = single_light if floorId != '' and roomId != '' and use_room_names == True: light_name = light_name + ' (' + roomnames[ floorId][roomId] + ')' self.light_devices[ single_light] = self.add_light_info( name=light_name, state=light_state, floor=floornames[floorId], room=roomnames[floorId][roomId], light_type='dimmer', brightness=brightness) else: self.light_devices[ single_light] = self.add_light_info( name=light_name, state=light_state, floor='', room='', light_type='dimmer', brightness=brightness) self.devices[single_light] = 'light' log.info('dimmer %s %s is %s', single_light, light_name, light_state) # Scene or Timer if deviceId == '4800' or deviceId == '4A00': channels = neighbor.find('channels') if channels is not None: for channel in channels.findall('channel'): channelName = names[channel.get('nameId')].title() channelId = channel.get('i') scene_name = '' floorId = '' roomId = '' for attributes in channel.findall('attribute'): attributeName = attributes.get('name') attributeValue = attributes.text if attributeName == 'displayName': scene_name = attributeValue if attributeName == 'floor': floorId = attributeValue if attributeName == 'room': roomId = attributeValue scene = serialNumber + '/' + channelId if scene_name == '': scene_name = scene if floorId != '' and roomId != '' and use_room_names == True: scene_name = scene_name + ' (' + roomnames[ floorId][roomId] + ')' self.scene_devices[ scene] = self.add_scene_info( name=scene_name, floor=floornames[floorId], room=roomnames[floorId][roomId]) else: self.scene_devices[ scene] = self.add_scene_info( name=scene_name, floor='', room='') self.devices[scene] = 'scene' log.info('scene %s %s', scene, scene_name) # switch device if deviceId == 'B001' or deviceId == '1013': channels = neighbor.find('channels') if channels is not None: for channel in channels.findall('channel'): channelName = names[channel.get('nameId')].title() channelId = channel.get('i') cover_name = '' floorId = '' roomId = '' for attributes in channel.findall('attribute'): attributeName = attributes.get('name') attributeValue = attributes.text if attributeName == 'displayName': light_name = attributeValue if attributeName == 'floor': floorId = attributeValue if attributeName == 'room': roomId = attributeValue inputs = channel.find('inputs') for datapoints in inputs.findall('dataPoint'): datapointId = datapoints.get('i') datapointValue = datapoints.find('value').text outputs = channel.find('outputs') for datapoints in outputs.findall('dataPoint'): datapointId = datapoints.get('i') datapointValue = datapoints.find('value').text if datapointId == 'odp0000': cover_state = datapointValue if datapointId == 'odp0001': cover_position = str( abs(100 - int(datapointValue))) single_cover = serialNumber + '/' + channelId if cover_name == '': cover_name = single_cover if floorId != '' and roomId != '' and use_room_names == True: cover_name = cover_name + ' (' + roomnames[ floorId][roomId] + ')' self.cover_devices[ single_cover] = self.add_cover_info( name=cover_name, state=cover_state, position=cover_position, floor=floornames[floorId], room=roomnames[floorId][roomId]) else: self.cover_devices[ single_cover] = self.add_cover_info( name=cover_name, state=cover_state, position=cover_position, floor='', room='') self.devices[single_cover] = 'cover' log.info('cover %s %s is %s', single_cover, cover_name, cover_state)