How to use the plugwise.protocol.BaseType function in plugwise

To help you get started, we’ve selected a few plugwise examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SevenW / Plugwise-2-py / plugwise / protocol.py View on Github external
def negative(self, val, octals):
        """compute the 2's compliment of int value val for negative values"""
        bits=octals<<2
        if( (val&(1<<(bits-1))) != 0 ):
            val = val - (1<
github SevenW / Plugwise-2-py / plugwise / protocol.py View on Github external
class BaseType(object):
    def __init__(self, value, length):
        self.value = value
        self.length = length

    def serialize(self):
        return sc(self.value)

    def unserialize(self, val):
        self.value = val

    def __len__(self):
        return self.length

class CompositeType(BaseType):
    def __init__(self):
        self.contents = []

    def serialize(self):
        return b''.join(a.serialize() for a in self.contents)

    def unserialize(self, val):
        for p in self.contents:
            myval = val[:len(p)]
            #debug("PARS      "+repr(str(myval)))
            p.unserialize(myval)
            debug("PARS      "+repr(str(myval)) + " EVAL "+repr(str(p.value)))
            val = val[len(myval):]
        return val
        
    def __len__(self):
github SevenW / Plugwise-2-py / plugwise / protocol.py View on Github external
def __init__(self, value, length=2):
        self.value = value
        self.length = length
                
    def serialize(self):
        fmt = "%%0%dd" % self.length
        return sc(fmt % self.value)

    def unserialize(self, val):
        try:
            self.value = int(val)
        except ValueError:
            debug('value error while attempting to construct StringVal object. val = %s' % val)
            self.value = 0

class SInt(BaseType):
    def __init__(self, value, length=2):
        self.value = value
        self.length = length
                
    def negative(self, val, octals):
        """compute the 2's compliment of int value val for negative values"""
        bits=octals<<2
        if( (val&(1<<(bits-1))) != 0 ):
            val = val - (1<
github SevenW / Plugwise-2-py / plugwise / protocol.py View on Github external
def unserialize(self, val):
        for p in self.contents:
            myval = val[:len(p)]
            #debug("PARS      "+repr(str(myval)))
            p.unserialize(myval)
            debug("PARS      "+repr(str(myval)) + " EVAL "+repr(str(p.value)))
            val = val[len(myval):]
        return val
        
    def __len__(self):
        return sum(len(x) for x in self.contents)

class String(BaseType):
    pass
    
class StringVal(BaseType):
    def __init__(self, value, length=2):
        self.value = value
        self.length = length
                
    def serialize(self):
        fmt = "%%0%dd" % self.length
        return sc(fmt % self.value)

    def unserialize(self, val):
        try:
            self.value = int(val)
        except ValueError:
            debug('value error while attempting to construct StringVal object. val = %s' % val)
            self.value = 0

class SInt(BaseType):
github SevenW / Plugwise-2-py / plugwise / protocol.py View on Github external
class TimeStr(CompositeType):
    """time value as used in the datetime info response"""

    def __init__(self, second=0, minute=0, hour=0):
        CompositeType.__init__(self)
        self.second = StringVal(second, 2)
        self.minute = StringVal(minute, 2)
        self.hour = StringVal(hour, 2)
        self.contents += [self.second, self.minute, self.hour]

    def unserialize(self, val):
        CompositeType.unserialize(self, val)
        self.value = datetime.time(self.hour.value, self.minute.value, self.second.value)
       
class Float(BaseType):
    def __init__(self, value, length=4):
        self.value = value
        self.length = length

    def unserialize(self, val):
        hexval = binascii.unhexlify(val)
        self.value = struct.unpack("!f", hexval)[0]

class LogAddr(Int):
    LOGADDR_OFFSET = 278528

    def serialize(self):
        return sc("%08X" % ((self.value * 32) + self.LOGADDR_OFFSET))

    def unserialize(self, val):
        Int.unserialize(self, val)
github SevenW / Plugwise-2-py / plugwise / protocol.py View on Github external
def serialize(self):
        return b''.join(a.serialize() for a in self.contents)

    def unserialize(self, val):
        for p in self.contents:
            myval = val[:len(p)]
            #debug("PARS      "+repr(str(myval)))
            p.unserialize(myval)
            debug("PARS      "+repr(str(myval)) + " EVAL "+repr(str(p.value)))
            val = val[len(myval):]
        return val
        
    def __len__(self):
        return sum(len(x) for x in self.contents)

class String(BaseType):
    pass
    
class StringVal(BaseType):
    def __init__(self, value, length=2):
        self.value = value
        self.length = length
                
    def serialize(self):
        fmt = "%%0%dd" % self.length
        return sc(fmt % self.value)

    def unserialize(self, val):
        try:
            self.value = int(val)
        except ValueError:
            debug('value error while attempting to construct StringVal object. val = %s' % val)