Exemple #1
0
def test_userdata_basic():
    """Test insteonplm User Data type class."""
    userdata = {
        'd1': 0x11,
        'd2': 0x22,
        'd3': 0x33,
        'd4': 0x44,
        'd5': 0x55,
        'd6': 0x66,
        'd7': 0x77,
        'd8': 0x88,
        'd9': 0x99,
        'd10': 0xaa,
        'd11': 0xbb,
        'd12': 0xcc,
        'd13': 0xdd,
        'd14': 0xee
    }

    ud = Userdata(userdata)
    chk = Userdata.create_pattern(userdata)
    chk2 = Userdata.create_pattern({'d1': 0x11})
    assert chk == ud
    assert ud.matches_pattern(chk2)
    assert chk2.matches_pattern(ud)
Exemple #2
0
    def template(
        cls,
        address=None,
        target=None,
        commandtuple=None,
        userdata=None,
        cmd2=-1,
        flags=None,
    ):
        """Create message template for callbacks."""
        msgraw = bytearray([0x02, cls._code])
        msgraw.extend(bytes(cls._receivedSize))
        msg = ExtendedReceive.from_raw_message(msgraw)

        if commandtuple:
            cmd1 = commandtuple.get("cmd1")
            cmd2out = commandtuple.get("cmd2")
        else:
            cmd1 = None
            cmd2out = None

        if cmd2 is not -1:
            cmd2out = cmd2

        msg._address = Address(address)
        msg._target = Address(target)
        msg._messageFlags = MessageFlags(flags)
        msg._cmd1 = cmd1
        msg._cmd2 = cmd2out
        msg._userdata = Userdata.create_pattern(userdata)
        return msg