def process_rsp(client, temp_sensors, power_sensors, topic, message): rc = None for tsensor in temp_sensors: topic_match = False for otb_type in otb_types: if tsensor[STATUS_SUB % otb_type] == topic: topic_match = True if topic_match: # Match if (message == "ok:pong"): tsensor[PING_RSP] = "OK" return True elif (message == "pong"): tsensor[PING_RSP] = "OK" return True elif (message.startswith("ok:")): num = message.split(':')[1] num = int(num) correctnum = len(tsensor[SENSORS]) if (correctnum == num): tsensor[QUERY_RSP] = "OK" else: tsensor[QUERY_RSP] = "BAD %d vs %d" % (num, correctnum) return True for psensor in power_sensors: topic_match = False for otb_type in otb_types: if psensor[STATUS_SUB % otb_type] == topic: topic_match = True # Match if topic_match: if (message == "pong"): psensor[PING_RSP] = "OK" return True return rc
def extract_first_part(message: bytes, boundary: bytes): """Function to extract the first part of a multipart message.""" first_message = message.split(boundary)[1].lstrip() if first_message.endswith(b'\r\n'): first_message = first_message[:-2] else: first_message = first_message[:-1] return first_message