def parse(self, data): """Parse a 11 bytes packet in the TemperatureHumidity format and return a dictionary containing the data extracted. An example of a return value would be: .. code-block:: python { 'id': "0x2EB2", 'packet_length': 10, 'packet_type': 82, 'packet_type_name': 'Temperature and humidity sensors', 'sequence_number': 0, 'packet_subtype': 2, 'packet_subtype_name': "THGR810, THGN801, THGN800", 'temperature': 21.3, 'humidity': 91, 'humidity_status': "Wet" 'signal_level': 9, 'battery_level': 6, } :param data: bytearray to be parsed :type data: bytearray :return: Data dictionary containing the parsed values :rtype: dict """ self.validate_packet(data) id_ = self.dump_hex(data[4:6]) channel = data[5] temperature = ((data[6] & 0x7f) * 256 + data[7]) / 10 signbit = data[6] & 0x80 if signbit != 0: temperature = -temperature humidity = data[8] humidity_status = self._extract_humidity_status(data[9]) sensor_specific = { 'id': id_, 'channel': channel, 'temperature': temperature, 'humidity': humidity, 'humidity_status': humidity_status } results = self.parse_header_part(data) results.update(RfxPacketUtils.parse_signal_and_battery(data[10])) results.update(sensor_specific) return results
def parse(self, data): """Parse a 12 bytes packet in the Lighting2 format and return a dictionary containing the data extracted. An example of a return value would be: .. code-block:: python { 'id': "0x111F342", 'packet_length': 10, 'packet_type': 17, 'packet_type_name': 'Humidity sensors', 'sequence_number': 19, 'packet_subtype': 0, 'packet_subtype_name': "AC", 'unit_code': 10, 'command': 1, 'command_text': "Off", 'level': 7, 'signal_level': 9, } :param data: bytearray to be parsed :type data: bytearray :return: Data dictionary containing the parsed values :rtype: dict """ self.validate_packet(data) results = self.parse_header_part(data) sub_type = results['packet_subtype'] id_ = self.dump_hex(data[4:8]) unit_code = data[8] command = data[9] command_text = SUB_TYPE_COMMANDS.get(sub_type, {}).get(command) dim_level = DIM_LEVEL_TO_PERCENT.get(data[10], '--??--') sensor_specific = { 'id': id_, 'unit_code': unit_code, 'command': command, 'command_text': command_text, 'dim_level': dim_level } results.update(RfxPacketUtils.parse_signal_upper(data[11])) results.update(sensor_specific) return results
def parse(self, data): """Parse a 18 bytes packet in the Electricity format and return a dictionary containing the data extracted. An example of a return value would be: .. code-block:: python { 'count': 3, 'current_watts': 692, 'id': "0x2EB2", 'packet_length': 17, 'packet_type': 90, 'packet_type_name': 'Energy usage sensors', 'sequence_number': 0, 'packet_subtype': 1, 'packet_subtype_name': "CM119/160", 'total_watts': 920825.1947099693, 'signal_level': 9, 'battery_level': 6, } :param data: bytearray to be parsed :type data: bytearray :return: Data dictionary containing the parsed values :rtype: dict """ self.validate_packet(data) TOTAL_DIVISOR = 223.666 id_ = self.dump_hex(data[4:6]) count = data[6] instant = data[7:11] total = data[11:16] current_watts = self._bytes_to_uint_32(instant) total_watts = self._bytes_to_uint_48(total) / TOTAL_DIVISOR sensor_specific = { 'count': count, 'current_watts': current_watts, 'id': id_, 'total_watts': total_watts } results = self.parse_header_part(data) results.update(RfxPacketUtils.parse_signal_and_battery(data[17])) results.update(sensor_specific) return results
def parse(self, data): """Parse a 11 bytes packet in the Lighting5 format and return a dictionary containing the data extracted. An example of a return value would be: .. code-block:: python { 'id': "0xF394AB", 'packet_length': 10, 'packet_type': 20, 'packet_type_name': 'Lighting5 sensors', 'sequence_number': 173, 'packet_subtype': 0, 'packet_subtype_name': "LightwaveRF, Siemens", 'unit_code': 1, 'command': 1, 'command_text': "On", 'level': 0, 'signal_level': 9, } :param data: bytearray to be parsed :type data: bytearray :return: Data dictionary containing the parsed values :rtype: dict """ self.validate_packet(data) results = self.parse_header_part(data) sub_type = results['packet_subtype'] id_ = self.dump_hex(data[4:7]) unit_code = data[7] command = data[8] command_text = SUB_TYPE_COMMANDS.get(sub_type, {}).get(command) level = data[9] sensor_specific = { 'id': id_, 'unit_code': unit_code, 'command': command, 'command_text': command_text, 'level': level } results.update(RfxPacketUtils.parse_signal_upper(data[10])) results.update(sensor_specific) return results
def parse(self, data): """Parse a 9 bytes packet in the Humidity format and return a dictionary containing the data extracted. An example of a return value would be: .. code-block:: python { 'id': "0x2EB2", 'packet_length': 8, 'packet_type': 81, 'packet_type_name': 'Humidity sensors', 'sequence_number': 0, 'packet_subtype': 1, 'packet_subtype_name': "LaCrosse TX3", 'humidity': 91, 'humidity_status': "Wet" 'signal_level': 9, 'battery_level': 6, } :param data: bytearray to be parsed :type data: bytearray :return: Data dictionary containing the parsed values :rtype: dict """ self.validate_packet(data) id_ = self.dump_hex(data[4:6]) # channel = data[5] TBC humidity = data[6] humidity_status = self._extract_humidity_status(data[7]) sensor_specific = { 'id': id_, # 'channel': channel, TBC 'humidity': humidity, 'humidity_status': humidity_status } results = self.parse_header_part(data) results.update(RfxPacketUtils.parse_signal_and_battery(data[8])) results.update(sensor_specific) return results
def parse(self, data): """Parse a 9 bytes packet in the Temperature format and return a dictionary containing the data extracted. An example of a return value would be: .. code-block:: python { 'id': "0x2EB2", 'packet_length': 8, 'packet_type': 80, 'packet_type_name': 'Temperature sensors', 'sequence_number': 0, 'packet_subtype': 1, 'packet_subtype_name': "THR128/138, THC138", 'temperature': 21.3, 'signal_level': 9, 'battery_level': 6, } :param data: bytearray to be parsed :type data: bytearray :return: Data dictionary containing the parsed values :rtype: dict """ self.validate_packet(data) id_ = self.dump_hex(data[4:6]) # channel = data[5] TBC temperature = ((data[6] & 0x7f) * 256 + data[7]) / 10 signbit = data[6] & 0x80 if signbit != 0: temperature = -temperature sensor_specific = { 'id': id_, # 'channel': channel, TBC 'temperature': temperature } results = self.parse_header_part(data) results.update(RfxPacketUtils.parse_signal_and_battery(data[8])) results.update(sensor_specific) return results
def parse(self, data): """Parse a 12 bytes packet in the Rain format and return a dictionary containing the data extracted. An example of a return value would be: .. code-block:: python { 'id': "0x2EB2", 'packet_length': 11, 'packet_type': 85, 'packet_type_name': 'Rain sensors', 'sequence_number': 0, 'packet_subtype': 1, 'packet_subtype_name': "RGR126/682/918", 'rain_rate': 5, 'rain_total': 130.0, 'signal_level': 9, 'battery_level': 6, } :param data: bytearray to be parsed :type data: bytearray :return: Data dictionary containing the parsed values :rtype: dict """ self.validate_packet(data) results = self.parse_header_part(data) sub_type = results['packet_subtype'] id_ = self.dump_hex(data[4:6]) rain_rate_high = data[6] rain_rate_low = data[7] if sub_type == 0x01: rain_rate = rain_rate_high * 0x100 + rain_rate_low elif sub_type == 0x02: rain_rate = float(rain_rate_high * 0x100 + rain_rate_low) / 100 else: rain_rate = '--??--' rain_total1 = data[8] rain_total2 = data[9] rain_total3 = data[10] if sub_type != 0x06: rain_total = float(rain_total1 * 0x1000 + rain_total2 * 0x100 + rain_total3) / 10 else: rain_total = '--??--' sensor_specific = {'id': id_} if rain_rate != '--??--': sensor_specific['rain_rate'] = rain_rate if rain_total != '--??--': sensor_specific['rain_total'] = rain_total results.update(RfxPacketUtils.parse_signal_and_battery(data[11])) results.update(sensor_specific) return results
def parse(self, data): """Parse a 17 bytes packet in the Wind format and return a dictionary containing the data extracted. An example of a return value would be: .. code-block:: python { 'id': "0x2EB2", 'packet_length': 16, 'packet_type': 86, 'packet_type_name': 'Wind sensors', 'sequence_number': 0, 'packet_subtype': 4, 'packet_subtype_name': "TFA", 'temperature': 17.3, 'direction': 120, 'wind_gust': 11, 'av_speed': 12, 'wind_chill': 10, 'signal_level': 9, 'battery_level': 6, } :param data: bytearray to be parsed :type data: bytearray :return: Data dictionary containing the parsed values :rtype: dict """ self.validate_packet(data) results = self.parse_header_part(data) sub_type = results['packet_subtype'] id_ = self.dump_hex(data[4:6]) direction = data[6] * 256 + data[7] if sub_type != 0x05: av_speed = (data[8] * 256 + data[9]) * 0.1 else: av_speed = '--??--' gust = (data[10] * 256 + data[11]) * 0.1 if sub_type == 0x04: temperature = ((data[12] & 0x7f) * 256 + data[13]) / 10 signbit = data[12] & 0x80 if signbit != 0: temperature = -temperature else: temperature = '--??--' if sub_type == 0x04: wind_chill = ((data[14] & 0x7f) * 256 + data[15]) / 10 signbit = data[14] & 0x80 if signbit != 0: wind_chill = -wind_chill else: wind_chill = '--??--' sensor_specific = { 'id': id_, 'direction': direction, 'wind_gust': gust } if av_speed != '--??--': sensor_specific['av_speed'] = av_speed if temperature != '--??--': sensor_specific['temperature'] = temperature if wind_chill != '--??--': sensor_specific['wind_chill'] = wind_chill results.update(RfxPacketUtils.parse_signal_and_battery(data[16])) results.update(sensor_specific) return results