diff --git a/RFXtrx/__init__.py b/RFXtrx/__init__.py index 8a12f18..c84c782 100644 --- a/RFXtrx/__init__.py +++ b/RFXtrx/__init__.py @@ -385,6 +385,8 @@ def __init__(self, pkt): self.values['Wind gust'] = pkt.gust self.values['Temperature'] = pkt.temperature self.values['Chill'] = pkt.chill + if isinstance(pkt, lowlevel.UV): + self.values['UV'] = pkt.uvi if isinstance(pkt, lowlevel.Energy): self.values['Energy usage'] = pkt.currentwatt self.values['Total usage'] = pkt.totalwatts diff --git a/RFXtrx/lowlevel.py b/RFXtrx/lowlevel.py index 1e0e9de..b593440 100644 --- a/RFXtrx/lowlevel.py +++ b/RFXtrx/lowlevel.py @@ -74,6 +74,8 @@ def parse(data): pkt = Rain() elif data[1] == 0x56: pkt = Wind() + elif data[1] == 0x57: + pkt = UV() elif data[1] == 0x59: pkt = Energy1() elif data[1] == 0x5A: @@ -1695,6 +1697,57 @@ def _set_strings(self): self.subtype) +############################################################################### +# UV class +############################################################################### + +class UV(SensorPacket): + """ + Data class for the uv packet type + """ + TYPES = { + 0x02: "UVN800"} + + def __str__(self): + return ("UV [subtype={0}, seqnbr={1}, id={2}, uv={3}," + + " battery={5}, rssi={6}]") \ + .format(self.type_string, self.seqnbr, self.id_string, + self.uvi, self.battery, self.rssi) + + def __init__(self): + """Constructor""" + super(UV, self).__init__() + self.id1 = None + self.id2 = None + self.uvi = None + self.battery = None + + def load_receive(self, data): + """Load data from a bytearray""" + self.data = data + self.packetlength = data[0] + self.packettype = data[1] + self.subtype = data[2] + self.seqnbr = data[3] + self.id1 = data[4] + self.id2 = data[5] + self.uvi = float(data[6]) / 10 + self.rssi_byte = data[9] + self.battery = self.rssi_byte & 0x0f + self.rssi = self.rssi_byte >> 4 + self._set_strings() + + def _set_strings(self): + """Translate loaded numeric values into convenience strings""" + self.id_string = "{0:02x}:{1:02x}".format(self.id1, self.id2) + if self.subtype in self.TYPES: + self.type_string = self.TYPES[self.subtype] + else: + # Degrade nicely for yet unknown subtypes + self.type_string = self._UNKNOWN_TYPE.format(self.packettype, + self.subtype) + + ############################################################################### # Energy1 class ############################################################################### diff --git a/tests/test_base.py b/tests/test_base.py index 44258c8..7cbd0b0 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -182,6 +182,12 @@ def test_format_packet(self): self.assertEquals(RFXtrx.SensorEvent, type(event)) self.assertEquals(event.__str__()," device=[ type='WTGR800' id='2f:00'] values=[('Battery numeric', 9), ('Chill', -59.2), ('Rssi numeric', 5), ('Temperature', -35.2), ('Wind average speed', 3.2), ('Wind direction', 247), ('Wind gust', 3.6)]") + #uv + bytes_array = [0x09, 0x57, 0x02, 0x02, 0x64, 0x00, 0x20, 0x02, 0x3c, 0x69] + event = core.transport.parse(bytes_array) + self.assertEquals(RFXtrx.SensorEvent, type(event)) + self.assertEquals(event.__str__()," device=[ type='UVN800' id='64:00'] values=[('Battery numeric', 9), ('Rssi numeric', 6), ('UV', 3.2)]") + #Elec4 bytes_array = [0x13, 0x5b, 0x01, 0x04, 0x2e, 0xB2, 0x01, 0x11, 0x12, 0x14, 0x15, 0x17, 0x18, 0x17, 0x18, 0x19, 0x20, 0x21, 0x22, 0x69] event = core.transport.parse(bytes_array)