コード例 #1
0
    def test_set_on_level(self, test_device):
        # set_on_level(self, level, on_done=None)
        assert(test_device.get_on_level() == 255)

        def level_bytes(level):
            data = bytes([
                0x01,
                0x06,
                level,
                ] + [0x00] * 11)
            return data
        for params in ([1, 0x01], [127, 127], [255, 0xFF]):
            test_device.set_on_level(on_level=params[0])
            assert len(test_device.protocol.sent) == 1
            assert test_device.protocol.sent[0].msg.cmd1 == 0x2e
            assert (test_device.protocol.sent[0].msg.data ==
                    level_bytes(params[1]))
            test_device.protocol.clear()

        test_device.set_on_level(on_level=64)

        # Fake having completed the set_on_level(64) request
        flags = IM.message.Flags(IM.message.Flags.Type.DIRECT_ACK, False)
        ack = IM.message.InpStandard(test_device.addr.hex,
                                     test_device.modem.addr.hex,
                                     flags, 0x2e, 0x00)
        test_device.handle_on_level(ack, IM.util.make_callback(None), 64)
        assert(test_device.get_on_level() == 64)
        test_device.protocol.clear()

        # Try multiple button presses in a row; confirm that level goes to
        # default on-level then to full brightness, as expected.
        # Fast-on should always go to full brightness.
        params = [
            (Msg.CmdType.ON, 0x00, {"level":64, "mode":IM.on_off.Mode.NORMAL, "is_on": True, "reason":'device', "button":1}),
            (Msg.CmdType.ON, 0x00, {"level":255, "mode":IM.on_off.Mode.NORMAL, "is_on": True, "reason":'device', "button":1}),
            (Msg.CmdType.ON, 0x00, {"level":64, "mode":IM.on_off.Mode.NORMAL, "is_on": True, "reason":'device', "button":1}),
            (Msg.CmdType.OFF, 0x00, {"level":0, "mode":IM.on_off.Mode.NORMAL, "is_on": False, "reason":'device', "button":1}),
            (Msg.CmdType.ON_FAST, 0x00, {"level":255, "mode":IM.on_off.Mode.FAST, "is_on": True, "reason":'device', "button":1}),
            (Msg.CmdType.ON_FAST, 0x00, {"level":255, "mode":IM.on_off.Mode.FAST, "is_on": True, "reason":'device', "button":1}),
            (Msg.CmdType.OFF_FAST, 0x00, {"level":0, "mode":IM.on_off.Mode.FAST, "is_on": False, "reason":'device', "button":1}),
            (Msg.CmdType.ON_INSTANT, 0x00,
                {"level":64, "mode":IM.on_off.Mode.INSTANT, "is_on": True, "reason":'device', "button":1}),
            (Msg.CmdType.ON_INSTANT, 0x00,
                {"level":255, "mode":IM.on_off.Mode.INSTANT, "is_on": True, "reason":'device', "button":1}),
            (Msg.CmdType.ON_INSTANT, 0x00,
                {"level":64, "mode":IM.on_off.Mode.INSTANT, "is_on": True, "reason":'device', "button":1})]
        for cmd1, cmd2, expected in params:
            with mock.patch.object(IM.Signal, 'emit') as mocked:
                print("Trying:", "[%x, %x]" % (cmd1, cmd2))
                flags = Msg.Flags(Msg.Flags.Type.ALL_LINK_BROADCAST, False)
                group_num = 0x01
                group = IM.Address(0x00, 0x00, group_num)
                addr = IM.Address(0x01, 0x02, 0x03)
                msg = Msg.InpStandard(addr, group, flags, cmd1, cmd2)
                test_device.handle_broadcast(msg)
                if expected is not None:
                    mocked.assert_called_once_with(test_device, **expected)
                else:
                    mocked.assert_not_called()
コード例 #2
0
 def test_handle_on_off_manual(self, test_device):
     with mock.patch.object(IM.Signal, 'emit') as mocked:
         flags = Msg.Flags(Msg.Flags.Type.ALL_LINK_BROADCAST, False)
         group = IM.Address(0x00, 0x00, 0x01)
         addr = IM.Address(0x01, 0x02, 0x03)
         msg = Msg.InpStandard(addr, group, flags,
                               Msg.CmdType.START_MANUAL_CHANGE, 0x00)
         test_device.handle_broadcast(msg)
         assert mocked.call_count == 2
         calls = [
             call(test_device, IM.on_off.Manual.DOWN),
             call(test_device, False, IM.on_off.Mode.MANUAL, 'device')
         ]
         mocked.assert_has_calls(calls)
     with mock.patch.object(IM.Signal, 'emit') as mocked:
         flags = Msg.Flags(Msg.Flags.Type.ALL_LINK_BROADCAST, False)
         group = IM.Address(0x00, 0x00, 0x01)
         addr = IM.Address(0x01, 0x02, 0x03)
         msg = Msg.InpStandard(addr, group, flags,
                               Msg.CmdType.START_MANUAL_CHANGE, 0x01)
         test_device.handle_broadcast(msg)
         assert mocked.call_count == 2
         calls = [
             call(test_device, IM.on_off.Manual.UP),
             call(test_device, True, IM.on_off.Mode.MANUAL, 'device')
         ]
         mocked.assert_has_calls(calls)
コード例 #3
0
    def test_errors(self):
        with pytest.raises(Exception):
            IM.Address(0x01, 0x02, None)

        with pytest.raises(Exception):
            IM.Address(0x01, None, 0x03)

        with pytest.raises(Exception):
            IM.Address(None, 0x02, 0x03)

        with pytest.raises(Exception):
            IM.Address(1000, 1, 1)

        with pytest.raises(Exception):
            IM.Address(1, 1000, 1)

        with pytest.raises(Exception):
            IM.Address(1, 1, 1000)

        with pytest.raises(Exception):
            IM.Address(2**31)

        with pytest.raises(Exception):
            IM.Address([1], 1, 1)

        with pytest.raises(Exception):
            IM.Address("foo bar")

        with pytest.raises(Exception):
            IM.Address({1: 2})
コード例 #4
0
ファイル: test_Modem.py プロジェクト: lnr0626/insteon-mqtt
    def test_clear(self):
        obj = IM.db.Modem()
        assert len(obj) == 0

        addr = IM.Address('12.34.ab')
        data = bytes([0xff, 0x00, 0x00])
        e = IM.db.ModemEntry(addr, 0x01, True, data, db=obj)
        obj.add_entry(e)

        addr = IM.Address('12.34.ac')
        data = bytes([0xff, 0x00, 0x00])
        e = IM.db.ModemEntry(addr, 0x01, True, data, db=obj)
        obj.add_entry(e)

        addr = IM.Address('12.34.ad')
        data = bytes([0xff, 0x00, 0x00])
        e = IM.db.ModemEntry(addr, 0x02, True, data, db=obj)
        obj.add_entry(e)

        assert len(obj) == 3

        obj.set_meta('test', 2)
        obj.clear()
        assert len(obj) == 0
        assert len(obj.entries) == 0
        assert len(obj.groups) == 0
        assert len(obj.aliases) == 0
        assert len(obj._meta) == 1
        assert obj.get_meta('test') == 2
コード例 #5
0
    def test_acks(self):
        proto = None
        calls = []

        addr = IM.Address('0a.12.34')
        handler = IM.handler.DeviceGetDb(addr, calls.append)

        # Normal nak
        std_ack = Msg.OutStandard.direct(addr, 0x2f, 0x00)
        std_ack.is_ack = False
        r = handler.msg_received(proto, std_ack)
        assert r == Msg.CONTINUE

        # Wrong address
        nomatch = Msg.OutStandard.direct(IM.Address('0a.12.35'), 0x2f, 0x00)
        std_ack.is_ack = True
        r = handler.msg_received(proto, nomatch)
        assert r == Msg.UNKNOWN

        # Wrong command
        std_ack.cmd1 = 0x11
        r = handler.msg_received(proto, std_ack)
        assert r == Msg.UNKNOWN

        # Try w/ an extended msg.
        ext_data = bytes(14)
        ext_ack = Msg.OutExtended.direct(addr, 0x2f, 0x00, ext_data)
        ext_ack.is_ack = True
        r = handler.msg_received(proto, ext_ack)
        assert r == Msg.CONTINUE

        r = handler.msg_received(proto, "dummy")
        assert r == Msg.UNKNOWN

        assert calls == []
コード例 #6
0
    def test_ctrl(self):
        addr = IM.Address('12.34.ab')
        data = bytes([0x01, 0x02, 0x03])
        obj = IM.db.ModemEntry(addr, 0x03, True, data, db=None)

        assert obj.addr == addr
        assert obj.group == 0x03
        assert obj.is_controller is True
        assert obj.data == data

        d = obj.to_json()
        obj2 = IM.db.ModemEntry.from_json(d, db=None)
        assert obj2.addr == obj.addr
        assert obj2.group == obj.group
        assert obj2.is_controller == obj.is_controller
        assert obj2.data == obj.data

        assert obj2 == obj
        obj2.group = 0x01
        assert obj2 != obj

        str(obj)

        # compare w/ groups
        obj2.group = 0x02
        assert obj2 < obj

        # compare w/ addr
        obj2.addr = IM.Address('12.34.ac')
        assert obj < obj2
コード例 #7
0
 def test_handle_manual_not_load(self, test_device):
     test_device._load_group = 1
     with mock.patch.object(IM.Signal, 'emit') as mocked:
         flags = Msg.Flags(Msg.Flags.Type.ALL_LINK_BROADCAST, False)
         group = IM.Address(0x00, 0x00, 0x02)
         addr = IM.Address(0x01, 0x02, 0x03)
         msg = Msg.InpStandard(addr, group, flags,
                               Msg.CmdType.START_MANUAL_CHANGE, 0x00)
         test_device.handle_broadcast(msg)
         calls = [
             call(test_device, manual=IM.on_off.Manual.DOWN, button=2,
                  reason='device')
             ]
         assert mocked.call_count == 1
         mocked.assert_has_calls(calls, any_order=True)
     with mock.patch.object(IM.Signal, 'emit') as mocked:
         flags = Msg.Flags(Msg.Flags.Type.ALL_LINK_BROADCAST, False)
         group = IM.Address(0x00, 0x00, 0x02)
         addr = IM.Address(0x01, 0x02, 0x03)
         msg = Msg.InpStandard(addr, group, flags,
                               Msg.CmdType.START_MANUAL_CHANGE, 0x01)
         test_device.handle_broadcast(msg)
         calls = [
             call(test_device, manual=IM.on_off.Manual.UP, button=2,
                  reason='device')
             ]
         assert mocked.call_count == 1
         mocked.assert_has_calls(calls, any_order=True)
コード例 #8
0
    def test_basic(self):
        obj = IM.db.Modem()
        assert len(obj) == 0

        addr = IM.Address('12.34.ab')
        data = bytes([0xff, 0x00, 0x00])
        e = IM.db.ModemEntry(addr, 0x01, True, data)
        obj.add_entry(e)

        addr = IM.Address('12.34.ac')
        data = bytes([0xff, 0x00, 0x00])
        e = IM.db.ModemEntry(addr, 0x01, True, data)
        obj.add_entry(e)

        addr = IM.Address('12.34.ad')
        data = bytes([0xff, 0x00, 0x00])
        e = IM.db.ModemEntry(addr, 0x02, True, data)
        obj.add_entry(e)

        assert len(obj) == 3
        str(obj)

        j = obj.to_json()
        obj2 = IM.db.Modem.from_json(j)

        assert len(obj2) == 3
        assert obj2.entries[0] == obj.entries[0]
        assert obj2.entries[1] == obj.entries[1]
        assert obj2.entries[2] == obj.entries[2]
コード例 #9
0
    def test_cmd_from_msg(self):
        # Tests matching the command from the outbound message.
        proto = MockProto()
        calls = []

        def callback(msg, on_done=None):
            calls.append(msg)

        addr = IM.Address('0a.12.34')

        # sent message, match input command
        out = Msg.OutStandard.direct(addr, 0x11, 0xff)
        handler = IM.handler.StandardCmd(out, callback)

        r = handler.msg_received(proto, "dummy")
        assert r == Msg.UNKNOWN

        # ack back.
        out.is_ack = False
        r = handler.msg_received(proto, out)
        assert r == Msg.CONTINUE

        # wrong cmd
        out.cmd1 = 0x13
        r = handler.msg_received(proto, out)
        assert r == Msg.UNKNOWN

        # wrong addr
        out.cmd1 = 0x11
        out.to_addr = IM.Address('0a.12.33')
        r = handler.msg_received(proto, out)
        assert r == Msg.UNKNOWN

        # direct Pre NAK
        flags = Msg.Flags(Msg.Flags.Type.DIRECT_NAK, False)
        msg = Msg.InpStandard(addr, addr, flags, 0x11, 0xFC)
        r = handler.msg_received(proto, msg)
        assert r == Msg.CONTINUE

        # Now pass in the input message.

        # expected input meesage
        flags = Msg.Flags(Msg.Flags.Type.DIRECT_ACK, False)
        msg = Msg.InpStandard(addr, addr, flags, 0x11, 0x01)

        r = handler.msg_received(proto, msg)
        assert r == Msg.FINISHED
        assert len(calls) == 1
        assert calls[0] == msg

        # wrong cmd
        msg.cmd1 = 0x13
        r = handler.msg_received(proto, msg)
        assert r == Msg.UNKNOWN

        # wrong addr
        msg.cmd1 = 0x11
        msg.from_addr = IM.Address('0a.12.33')
        r = handler.msg_received(proto, msg)
        assert r == Msg.UNKNOWN
コード例 #10
0
    def test_plm_sent(self, tmpdir):
        calls = []

        def callback(success, msg, done):
            calls.append((success, msg, done))

        modem = H.main.MockModem(tmpdir)
        proto = H.main.MockProtocol()
        handler = IM.handler.ModemInfo(modem, callback)
        assert not handler._PLM_sent

        #Try a message prior to sent
        msg = Msg.OutModemInfo(addr=IM.Address('11.22.33'),
                               dev_cat=0x44,
                               sub_cat=0x55,
                               firmware=0x66,
                               is_ack=True)
        r = handler.msg_received(proto, msg)
        assert r == Msg.UNKNOWN

        # Signal Sent
        handler.sending_message(msg)
        assert handler._PLM_sent

        #Try a message prior to sent
        msg = Msg.OutModemInfo(addr=IM.Address('11.22.33'),
                               dev_cat=0x44,
                               sub_cat=0x55,
                               firmware=0x66,
                               is_ack=True)
        r = handler.msg_received(proto, msg)
        assert r == Msg.FINISHED
コード例 #11
0
 def test_broadcast(self, test_device, caplog):
     # test broadcast Messages, Base doesn't handle any
     flags = Msg.Flags(Msg.Flags.Type.ALL_LINK_BROADCAST, False)
     group = IM.Address(0x00, 0x00, 0x01)
     addr = IM.Address(0x01, 0x02, 0x03)
     msg = Msg.InpStandard(addr, group, flags, 0x11, 0x00)
     test_device.handle_broadcast(msg)
     assert "has no handler for broadcast" in caplog.text
コード例 #12
0
 def test_handle_refresh_wet(self, test_device):
     with mock.patch.object(test_device, '_set_is_wet') as mocked:
         flags = Msg.Flags(Msg.Flags.Type.ALL_LINK_BROADCAST, False)
         group = IM.Address(0x00, 0x00, 0x04)
         addr = IM.Address(0x01, 0x02, 0x03)
         msg = Msg.InpStandard(addr, group, flags, Msg.CmdType.OFF, 0x11)
         test_device.handle_refresh(msg)
         mocked.assert_called_once_with(True)
コード例 #13
0
ファイル: test_Modem.py プロジェクト: TD22057/insteon-mqtt
 def test_load_config_step2_success_addr_diff(self, test_device, tmpdir,
                                              caplog):
     cfg = IM.config.load('config-example.yaml')
     cfg['storage'] = tmpdir
     test_device.addr = IM.Address('44.85.11')
     msg = Msg.OutModemInfo(addr=IM.Address('44.85.12'), dev_cat=None,
                            sub_cat=None, firmware=None, is_ack=True)
     test_device.load_config_step2(True, 'message', msg, cfg)
     assert 'Modem address in config 44.85.11 does not match address' in caplog.text
コード例 #14
0
ファイル: test_Modem.py プロジェクト: TD22057/insteon-mqtt
 def test_load_config_step2_success_no_addr(self, test_device, tmpdir,
                                            caplog):
     cfg = IM.config.load('config-example.yaml')
     cfg['storage'] = tmpdir
     msg = Msg.OutModemInfo(addr=IM.Address('44.85.12'), dev_cat=None,
                            sub_cat=None, firmware=None, is_ack=True)
     test_device.load_config_step2(True, 'message', msg, cfg)
     for record in caplog.records:
         assert record.levelname != "ERROR"
     assert test_device.addr == IM.Address('44.85.12')
コード例 #15
0
ファイル: test_LeakDev.py プロジェクト: lnr0626/insteon-mqtt
 def test_handle_broadcast(self, test_device, group_num, cmd1, cmd2,
                           expected, kwargs):
     with mock.patch.object(IM.Signal, 'emit') as mocked:
         self._is_wet = False
         flags = Msg.Flags(Msg.Flags.Type.ALL_LINK_BROADCAST, False)
         group = IM.Address(0x00, 0x00, group_num)
         addr = IM.Address(0x01, 0x02, 0x03)
         msg = Msg.InpStandard(addr, group, flags, cmd1, cmd2)
         test_device.handle_broadcast(msg)
         mocked.assert_called_once_with(test_device, *expected, **kwargs)
コード例 #16
0
 def test_handle_on_off(self, test_device, group, cmd1, cmd2, expected):
     with mock.patch.object(IM.Signal, 'emit') as mocked:
         flags = Msg.Flags(Msg.Flags.Type.ALL_LINK_BROADCAST, False)
         group = IM.Address(0x00, 0x00, group)
         addr = IM.Address(0x01, 0x02, 0x03)
         msg = Msg.InpStandard(addr, group, flags, cmd1, cmd2)
         test_device.handle_broadcast(msg)
         if expected is not None:
             mocked.assert_called_once_with(test_device, **expected)
         else:
             mocked.assert_not_called()
コード例 #17
0
    def test_cmp(self):
        a = IM.Address(0x01, 0xe2, 0x40)
        b = IM.Address(0x01, 0xe2, 0x41)
        assert a < b
        assert b > a
        assert a == a
        assert a != b

        d = {a: 1, b: 2}
        assert d[a] == 1
        assert d[b] == 2
コード例 #18
0
 def test_broadcast_1(self, test_device, cmd1, expected):
     with mock.patch.object(Device.BatterySensor, '_set_state') as mocked:
         flags = Msg.Flags(Msg.Flags.Type.ALL_LINK_BROADCAST, False)
         group = IM.Address(0x00, 0x00, 0x01)
         addr = IM.Address(0x01, 0x02, 0x03)
         msg = Msg.InpStandard(addr, group, flags, cmd1, 0x00)
         test_device.handle_broadcast(msg)
         if expected is not None:
             mocked.assert_called_once_with(**expected)
         else:
             mocked.assert_not_called()
コード例 #19
0
    def test_handle_model_bad_resp(self, test_device, caplog):
        def on_done(success, msg, data):
            assert not success
            assert "Operation failed" in msg

        flags = Msg.Flags(Msg.Flags.Type.BROADCAST, False)
        to_addr = IM.Address(0x01, 0x30, 0x45)
        from_addr = IM.Address(0x01, 0x02, 0x03)
        msg = Msg.InpStandard(from_addr, to_addr, flags, 0x05, 0x00)
        with caplog.at_level(logging.DEBUG):
            test_device.handle_model(msg, on_done=on_done)
            assert 'get_model response with wrong cmd' in caplog.text
コード例 #20
0
 def test_handle_heartbeat(self, test_device):
     # tests updating the wet/dry state when heartbeat received
     with mock.patch.object(IM.Signal, 'emit') as mocked:
         self._is_wet = False
         flags = Msg.Flags(Msg.Flags.Type.ALL_LINK_BROADCAST, False)
         group = IM.Address(0x00, 0x00, 0x04)
         addr = IM.Address(0x01, 0x02, 0x03)
         msg = Msg.InpStandard(addr, group, flags, Msg.CmdType.OFF, 0x00)
         test_device.handle_broadcast(msg)
         assert mocked.call_count == 2
         calls = [call(test_device, True), call(test_device, True)]
         mocked.assert_has_calls(calls)
コード例 #21
0
    def test_handle_model(self, test_device, caplog):
        def on_done(success, msg, data):
            assert success
            assert msg == "Operation complete"

        flags = Msg.Flags(Msg.Flags.Type.BROADCAST, False)
        to_addr = IM.Address(0x01, 0x30, 0x45)
        from_addr = IM.Address(0x01, 0x02, 0x03)
        msg = Msg.InpStandard(from_addr, to_addr, flags, 0x01, 0x00)
        with caplog.at_level(logging.DEBUG):
            test_device.handle_model(msg, on_done=on_done)
            assert 'received model information' in caplog.text
            assert '2476D' in test_device.db.desc.model
コード例 #22
0
    def test_handle_flags(self, test_device, caplog):
        def on_done(success, msg, data):
            assert success
            assert msg == "Operation complete"

        flags = Msg.Flags(Msg.Flags.Type.DIRECT, False)
        group = IM.Address(0x00, 0x00, 0x01)
        addr = IM.Address(0x01, 0x02, 0x03)
        msg = Msg.InpStandard(addr, group, flags,
                              Msg.CmdType.GET_OPERATING_FLAGS, 0x55)
        with caplog.at_level(logging.DEBUG):
            test_device.handle_flags(msg, on_done=on_done)
            assert 'operating flags: 01010101' in caplog.text
コード例 #23
0
    def test_ctrl(self):
        addr = IM.Address('12.34.ab')
        ctrl = Msg.DbFlags(in_use=True, is_controller=True, is_last_rec=False)
        data = bytes([0x01, 0x02, 0x03])
        mem_loc = (0xfe << 8) + 0x10
        obj = IM.db.DeviceEntry(addr, 0x03, mem_loc, ctrl, data, db=None)

        assert obj.addr == addr
        assert obj.group == 0x03
        assert obj.db_flags.in_use == ctrl.in_use
        assert obj.db_flags.is_controller == ctrl.is_controller
        assert obj.db_flags.is_last_rec == ctrl.is_last_rec
        assert obj.mem_loc == mem_loc
        assert obj.data == data
        assert obj.mem_bytes() == bytes([0xfe, 0x10])

        d = obj.to_json()
        obj2 = IM.db.DeviceEntry.from_json(d, db=None)
        assert obj2.addr == obj.addr
        assert obj2.group == obj.group
        assert obj2.mem_loc == obj.mem_loc
        assert obj2.db_flags.in_use == obj.db_flags.in_use
        assert obj2.db_flags.is_controller == obj.db_flags.is_controller
        assert obj2.db_flags.is_last_rec == obj.db_flags.is_last_rec
        assert obj2.data == obj.data
        assert obj == obj2

        data = bytes([0x00, 0x01,
                      0xfe, 0x10,  # mem_loc
                      0x00, ctrl.to_bytes()[0], 0x03,
                      addr.ids[0], addr.ids[1], addr.ids[2],
                      data[0], data[1], data[2]])

        obj3 = IM.db.DeviceEntry.from_bytes(data, db=None)
        assert obj3.addr == obj.addr
        assert obj3.group == obj.group
        assert obj3.mem_loc == obj.mem_loc
        assert obj3.db_flags.in_use == obj.db_flags.in_use
        assert obj3.db_flags.is_controller == obj.db_flags.is_controller
        assert obj3.db_flags.is_last_rec == obj.db_flags.is_last_rec
        assert obj3.data == obj.data
        assert obj == obj3

        obj3.group = 0xff
        assert obj != obj3
        assert obj < obj3

        obj.addr = IM.Address('12.34.ac')
        assert obj3 < obj

        str(obj)
コード例 #24
0
    def test_handle_engine_nak(self, test_device, caplog):
        def on_done(success, msg, data):
            assert success
            assert msg == "Operation complete"

        flags = Msg.Flags(Msg.Flags.Type.DIRECT_NAK, False)
        group = IM.Address(0x00, 0x00, 0x01)
        addr = IM.Address(0x01, 0x02, 0x03)
        msg = Msg.InpStandard(addr, group, flags,
                              Msg.CmdType.GET_ENGINE_VERSION, 0x00)
        with caplog.at_level(logging.DEBUG):
            test_device.handle_engine(msg, on_done=on_done)
            assert 'sent NAK to get engine' in caplog.text
            assert test_device.db.engine == 2
コード例 #25
0
 def test_update_linked_devices(self, test_device, test_entry_1,
                                test_entry_2, test_device_2, caplog):
     test_device.db.add_entry(test_entry_1)
     test_device.db.add_entry(test_entry_2)
     test_device.modem.add(test_device_2)
     test_device.db_config = IM.db.Device(test_device.addr, None,
                                          test_device)
     flags = Msg.Flags(Msg.Flags.Type.ALL_LINK_BROADCAST, False)
     group = IM.Address(0x00, 0x00, 0x01)
     addr = IM.Address(0x01, 0x02, 0x03)
     msg = Msg.InpStandard(addr, group, flags, 0x11, 0x00)
     with caplog.at_level(logging.DEBUG):
         test_device.update_linked_devices(msg)
         assert 'device 12.34.ab is not in config' in caplog.text
         assert 'Device 56.78.cd ignoring group cmd' in caplog.text
コード例 #26
0
 def test_handle_broadcast_clear(self, test_device):
     with mock.patch.object(IM.Signal, 'emit') as mocked:
         self._is_wet = False
         flags = Msg.Flags(Msg.Flags.Type.ALL_LINK_BROADCAST, False)
         group = IM.Address(0x00, 0x00, 0x05)
         addr = IM.Address(0x01, 0x02, 0x03)
         msg = Msg.InpStandard(addr, group, flags, Msg.CmdType.ON, 0x00)
         test_device.handle_broadcast(msg)
         assert mocked.call_count == 6
         calls = []
         for type in test_device.Type:
             if type == test_device.Type.CLEAR:
                 continue
             calls.append(call(test_device, type, False))
         mocked.assert_has_calls(calls)
コード例 #27
0
    def test_handle_set_msb(self):
        # tests handle_set_msb and get_next_lsb
        protocol = MockProto()
        modem = MockModem()
        addr = IM.Address(0x01, 0x02, 0x03)
        device = IM.device.Base(protocol, modem, addr)

        # Create the new entry at the current last memory location.
        db_flags = Msg.DbFlags(in_use=True,
                               is_controller=True,
                               is_last_rec=False)
        i1_entry = IM.db.DeviceEntry(addr,
                                     0x01,
                                     device.db.last.mem_loc,
                                     db_flags,
                                     None,
                                     db=device.db)

        manager = IM.db.DeviceModifyManagerI1(device, device.db, i1_entry)

        # Test bad MSB, should cause resend of set msb
        flags = Msg.Flags(Msg.Flags.Type.DIRECT_ACK, False)
        msg = Msg.InpStandard(device.addr, device.addr, flags, 0x28, 0x0E)
        db_msg = Msg.OutStandard.direct(device.addr, 0x28, 0x0F)
        manager.handle_set_msb(msg, None)
        assert protocol.msgs[0].to_bytes() == db_msg.to_bytes()

        # Test receive correct msb
        flags = Msg.Flags(Msg.Flags.Type.DIRECT_ACK, False)
        msg = Msg.InpStandard(device.addr, device.addr, flags, 0x28, 0x0F)
        db_msg = Msg.OutStandard.direct(device.addr, 0x2B, 0xF8)
        manager.handle_set_msb(msg, None)
        assert protocol.msgs[1].to_bytes() == db_msg.to_bytes()
コード例 #28
0
    def test_handle_write_lsb_response(self):
        # tests handle_lsb_response and write_lsb_byte
        protocol = MockProto()
        modem = MockModem()
        addr = IM.Address(0x01, 0x02, 0x03)
        device = IM.device.Base(protocol, modem, addr)

        # Create the new entry at the current last memory location.
        db_flags = Msg.DbFlags(in_use=True,
                               is_controller=True,
                               is_last_rec=False)
        i1_entry = IM.db.DeviceEntry(addr,
                                     0x01,
                                     device.db.last.mem_loc,
                                     db_flags,
                                     None,
                                     db=device.db)

        manager = IM.db.DeviceModifyManagerI1(device, device.db, i1_entry)
        device.db.delta = 5
        msg = "fake message"
        on_done = "fake on_done"
        with mock.patch.object(manager, 'handle_lsb_response') as mocked:
            manager.handle_lsb_write_response(msg, on_done)
            assert device.db.delta == 6
            mocked.assert_called_once_with(msg, on_done)
コード例 #29
0
    def test_start_modify_with_on_done(self):
        # tests start_modify and _set_msb
        protocol = MockProto()
        modem = MockModem()
        addr = IM.Address(0x01, 0x02, 0x03)
        device = IM.device.Base(protocol, modem, addr)

        # Create the new entry at the current last memory location.
        db_flags = Msg.DbFlags(in_use=True,
                               is_controller=True,
                               is_last_rec=False)
        i1_entry = IM.db.DeviceEntry(addr,
                                     0x01,
                                     device.db.last.mem_loc,
                                     db_flags,
                                     None,
                                     db=device.db)

        manager = IM.db.DeviceModifyManagerI1(device, device.db, i1_entry)

        db_msg = Msg.OutStandard.direct(device.addr, 0x28, 0x0F)

        def fake_on_done(success, msg, data):
            pass

        manager.start_modify(on_done=fake_on_done)
        assert protocol.msgs[0].to_bytes() == db_msg.to_bytes()
        assert manager.on_done == fake_on_done
コード例 #30
0
    def test_handle_lsb_response(self):
        # tests handle_lsb_response and write_lsb_byte
        protocol = MockProto()
        modem = MockModem()
        addr = IM.Address(0x01, 0x02, 0x03)
        device = IM.device.Base(protocol, modem, addr)

        # Create the new entry at the current last memory location.
        db_flags = Msg.DbFlags(in_use=True,
                               is_controller=True,
                               is_last_rec=False)
        i1_entry = IM.db.DeviceEntry(addr,
                                     0x01,
                                     device.db.last.mem_loc,
                                     db_flags,
                                     None,
                                     db=device.db)

        manager = IM.db.DeviceModifyManagerI1(device, device.db, i1_entry)

        # Test wrong LSB, should cause poke of set lsb
        flags = Msg.Flags(Msg.Flags.Type.DIRECT_ACK, False)
        msg = Msg.InpStandard(device.addr, device.addr, flags, 0x2B, 0xA2)
        db_msg = Msg.OutStandard.direct(device.addr, 0x29, 0xE2)
        manager.handle_lsb_response(msg, None)
        assert protocol.msgs[0].to_bytes() == db_msg.to_bytes()

        # Test receive correct lsb, should cause request for next lsb
        flags = Msg.Flags(Msg.Flags.Type.DIRECT_ACK, False)
        msg = Msg.InpStandard(device.addr, device.addr, flags, 0x29, 0xE2)
        db_msg = Msg.OutStandard.direct(device.addr, 0x2B, 0xF9)
        manager.handle_lsb_response(msg, None)
        assert protocol.msgs[1].to_bytes() == db_msg.to_bytes()