def test_ibs01_with_usbtype(): message = '$GPRP,C874A59968B3,F008D1789208,-59,02010612FF590080BC2E0100BF0A3900000005000000' def handler(data, index): msd = data.advertisement.manufacturerData assert msd.humidity == 57 assert msd.temperature == 27.51 MessageParser.parse(message, handler)
def test_ibs01_json_temperature(): message = '{"data":["$GPRP,7ABA6F20ACCF,806172C89C09,-2,02010612FF590080BCFF00007A0D4300FFFFFFFFFFFF"]}' def handler(data, index): msd = data.advertisement.manufacturerData assert msd.humidity == 67 assert msd.temperature == 34.50 MessageParser.parse(message, handler)
def test_ibs02m2(): message = '$GPRP,806FB0C7C148,F008D1798BA4,-44,02010612FF0D0083BC3E0140AAAAFFFF000004070000' def handler(data, index): msd = data.advertisement.manufacturerData assert msd.type == 'iBS02M2' assert msd.events.din is True MessageParser.parse(message, handler)
def test_ibs02pir(): message = '$GPRP,607771FCD6FB,DB024BFC4863,-49,02010612FF0D0083BC4A0110AAAAFFFF000001140000,1604900518' def handler(data, index): msd = data.advertisement.manufacturerData assert msd.type == 'iBS02PIR2' assert msd.battery == 3.3 assert msd.events.pir is True MessageParser.parse(message, handler)
def test_ibs02hm(): message = '$GPRP,F0F8F2CADCCF,C82B96AE3B04,-52,02010612FF0D0082BC280100AAAAFFFF000004050000' def handler(data, index): msd = data.advertisement.manufacturerData assert msd.type == 'iBS02HM' assert msd.battery == 2.96 MessageParser.parse(message, handler)
def test_ibs05(): message = '$GPRP,EAC653D3AA8E,CCB97E7361A4,-44,02010612FF2C0883BC290101AAAAFFFF000030000000' def handler(data, index): msd = data.advertisement.manufacturerData assert msd.type == 'iBS05' assert msd.events.button is True MessageParser.parse(message, handler)
def test_ibs01_hall_detected(): message = '$GPRP,F704B6D48BE8,1173AE7325A2,-24,02010612FF590080BC2B0104FFFFFFFFFFFFFFFFFFFF' def handler(data, index): msd = data.advertisement.manufacturerData assert msd.type == 'iBS01' assert msd.battery == 2.99 assert msd.events.hall is True MessageParser.parse(message, handler)
def test_ibs02m2_counter(): message = '$GPRP,806FB0C7C148,F008D1798BA4,-44,02010612FF0D0083BC240100AAAA37060000040B0600' def handler(data, index): msd = data.advertisement.manufacturerData assert msd.type == 'iBS02M2' assert msd.counter == 1591 assert msd.events.din is False MessageParser.parse(message, handler)
def test_ibs02ir(): message = '$GPRP,0081F9889BF9,DB024BFC4863,-44,02010612FF0D0083BC200120AAAAFFFF000002070000,1604900604' def handler(data, index): msd = data.advertisement.manufacturerData assert msd.type == 'iBS02IR2' assert msd.battery == 2.88 assert msd.events.ir is True MessageParser.parse(message, handler)
def test_ibs03t_rh(): message = '$GPRP,CDCB34E2D0A2,77AE1C1DC33D,-91,02010612FF0D0083BCAD0000A20B4700FFFF14000000' def handler(data, index): msd = data.advertisement.manufacturerData assert msd.type == 'iBS03T' assert msd.temperature == 29.78 assert msd.humidity == 71 MessageParser.parse(message, handler)
def test_ibs03r(): message = '$GPRP,0C61CFC14A4E,E3C33FF55AEC,-50,02010612FF0D0083BCFFFF00FFFF6400000013030000' def handler(data, index): msd = data.advertisement.manufacturerData assert msd.type == 'iBS03R' assert msd.range == 100 assert not hasattr(msd, 'humidity') MessageParser.parse(message, handler)
def test_ibs03p(): message = '$GPRP,0C61CFC14745,E7DAE08E6FC3,-67,02010612FF0D0083BC280100AAAAD207000012080000,1608516227' def handler(data, index): msd = data.advertisement.manufacturerData assert msd.type == 'iBS03P' assert msd.temperatureExt == 20.02 assert not hasattr(msd, 'humidity') MessageParser.parse(message, handler)
def test_ibs02ir_counter(): message = '$GPRP,0081F9889BF9,F008D1789294,-42,02010612FF0D0083BC4D0120AAAA05000000020A0600' def handler(data, index): msd = data.advertisement.manufacturerData assert msd.type == 'iBS02IR2' assert msd.battery == 3.33 assert msd.counter == 5 assert msd.events.ir is True MessageParser.parse(message, handler)
def test_irs02rg(): message = '$GPRP,0C61CFC14B58,CC4B73906F8C,-21,02010612FF0D0083BC4D010000002400FCFE22074B58,1575440728' def handler(data, index): msd = data.advertisement.manufacturerData assert msd.type == 'iRS02RG' assert msd.accel.x == 0 assert msd.accel.z == -260 MessageParser.parse(message, handler)
def test_ibs05co2(): message = '$GPRP,C8B629D6DAC3,F008D1789294,-35,02010612FF2C0883BC270100AAAA6804000034010000' def handler(data, index): msd = data.advertisement.manufacturerData assert msd.type == 'iBS05CO2' assert msd.co2 == 1128 assert not hasattr(msd, 'temperature') MessageParser.parse(message, handler)
def test_ibs05t(): message = '$GPRP,EAC653D3AA8D,CCB97E7361A4,-44,02010612FF2C0883BC4A0100A10AFFFF000032000000' def handler(data, index): msd = data.advertisement.manufacturerData assert msd.type == 'iBS05T' assert msd.battery == 3.3 assert msd.temperature == 27.21 MessageParser.parse(message, handler)
def test_ibs01_button_pressed(): message = '$GPRP,FE581D9DB308,2F9203AFA66B,-21,02010612FF590080BC360101FFFFFFFFFFFFFFFFFFFF' def handler(data, index): assert data.beacon == 'FE581D9DB308' assert data.gateway == '2F9203AFA66B' msd = data.advertisement.manufacturerData assert msd.type == 'iBS01' assert msd.battery == 3.10 assert msd.events.button is True MessageParser.parse(message, handler)
def test_ibs06(): message = '$GPRP,1804ED7048F5,E3C33FF55AEC,-55,02010612FF2C0883BC4A0100AAAAFFFF000040110000' def handler(data, index): assert data.beacon == '1804ED7048F5' assert data.gateway == 'E3C33FF55AEC' msd = data.advertisement.manufacturerData assert msd.type == 'iBS06' assert msd.battery == 3.3 MessageParser.parse(message, handler)
def test_ibs03t(): message = '$GPRP,0C61CFC14A4E,E3C33FF55AEC,-50,02010612FF0D0083BC2801020A09FFFF000015030000' def handler(data, index): msd = data.advertisement.manufacturerData assert msd.type == 'iBS03T' assert msd.temperature == 23.14 assert msd.events.button is False assert not hasattr(msd, 'humidity') MessageParser.parse(message, handler)
def test_ibs04(): message = '$GPRP,1804ED7048F5,E3C33FF55AEC,-55,02010612FF0D0083BC3A0101AAAAFFFF000019070000' def handler(data, index): assert data.beacon == '1804ED7048F5' assert data.gateway == 'E3C33FF55AEC' msd = data.advertisement.manufacturerData assert msd.type == 'iBS04' assert msd.battery == 3.14 assert msd.events.button is True MessageParser.parse(message, handler)
def test_empty_payload(): message = '$GPRP,7ABA6F20ACCF,806172C89C09,-2,' data = MessageParser.parse(message, None) ad = data[0].advertisement msd = ad.manufacturerData assert msd is None message = '$GPRP,7ABA6F20ACCF,806172C89C09,-2,,1575440728' data = MessageParser.parse(message, None) ad = data[0].advertisement msd = ad.manufacturerData assert msd is None assert data[0].timestamp == 1575440728
def test_ibs03tp(): message = '$GPRP,1804ED7D9C00,C82B96AE3B04,-48,02010612FF0D0083BC280100D809060A640017040000' def handler(data, index): msd = data.advertisement.manufacturerData assert msd.company == 'Ingics' assert msd.type == 'iBS03TP' assert msd.battery == 2.96 assert msd.temperature == 25.20 assert msd.temperatureExt == 25.66 MessageParser.parse(message, handler)
def test_ibs03rg(): message = '$GPRP,806FB0C9963F,C3674946C293,-71,02010619FF0D0081BC3E110A00F4FF00FF1600F6FF00FF1400F6FF08FF,1586245829' def handler(data, index): msd = data.advertisement.manufacturerData assert msd.type == 'iBS03RG' assert msd.battery == 3.18 assert msd.events.moving is True assert msd.accels[0].x == 10 assert msd.accels[1].y == -10 assert msd.accels[2].z == -248 MessageParser.parse(message, handler)
def test_ibs03gp(): message = '$GPRP,806FB0C9963F,C3674946C293,-71,0201061BFF0D0085BC3111160082FF9EFE4E001200D2FE10003A005CFFD9C5' def handler(data, index): msd = data.advertisement.manufacturerData assert msd.type == 'iBS03GP' assert msd.battery == 3.05 assert msd.events.moving is True assert msd.accels[0].x == 22 assert msd.accels[1].y == 18 assert msd.accels[2].z == -164 assert msd.gp == 1012.98 MessageParser.parse(message, handler)
def test_ibs01_multi_messages(): messages = {'data': [ '$GPRP,7ABA6F20ACCF,806172C89C09,-2,02010612FF590080BCFF00007A0D4300FFFFFFFFFFFF', '$GPRP,F704B6D48BE8,1173AE7325A2,-24,02010612FF590080BC2B0104FFFFFFFFFFFFFFFFFFFF' ]} def handler(data, index): msd = data.advertisement.manufacturerData if index == 0: assert msd.humidity == 67 assert msd.temperature == 34.50 elif index == 1: assert msd.battery == 2.99 assert msd.events.hall is True else: assert 'invalid index' MessageParser.parse(json.dumps(messages), handler)
def test_multi_messages(): messages = [ '$GPRP,7ABA6F20ACCF,806172C89C09,-2,02010612FF590080BCFF00007A0D4300FFFFFFFFFFFF', '$GPRP,F704B6D48BE8,1173AE7325A2,-24,02010612FF590080BC2B0104FFFFFFFFFFFFFFFFFFFF' ] data = MessageParser.parse('\n'.join(messages), None) index = 0 while index < len(data): msd = data[index].advertisement.manufacturerData if index == 0: assert msd.humidity == 67 assert msd.temperature == 34.50 elif index == 1: assert msd.battery == 2.99 assert msd.events.hall is True else: assert 'invalid index' index += 1
#!/usr/bin/env python import sys import pprint from igsparser import MessageParser as parser def cb(data, index): pprint.pprint(vars(data)) if len(sys.argv) > 1: parser.parse(sys.argv[1], cb) else: print('Usage: {} <iGS Message>'.format(sys.argv[0])) print('Example: {} \'{}\''.format( sys.argv[0], '$GPRP,F973D9D36662,E7DAE08E6FC3,-87,02010612FF590080BC330100FFFFFFFF000004000000' ))