How to use the plugwise.protocol.CompositeType 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
self.contents += [self.year, self.month, self.minutes]

    def unserialize(self, val):
        CompositeType.unserialize(self, val)
        minutes = self.minutes.value
        hours = minutes // 60
        days = hours // 24
        hours -= (days*24)
        minutes -= (days*24*60)+(hours*60)
        try:
            self.value = datetime.datetime(self.year.value, self.month.value, days+1, hours, minutes)
        except ValueError:
            debug('value error while attempting to construct datetime object')
            self.value = None

class Time(CompositeType):
    """time value as used in the clock info response"""

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

    def unserialize(self, val):
        CompositeType.unserialize(self, val)
        self.value = datetime.time(self.hour.value, self.minute.value, self.second.value)
        
class DateStr(CompositeType):
    """date value as used in the datetime info response"""
github SevenW / Plugwise-2-py / plugwise / protocol.py View on Github external
def __init__(self, day=0, month=0, year=0):
        CompositeType.__init__(self)
        self.day = StringVal(day, 2)
        self.month = StringVal(month, 2)
        self.year = StringVal(year, 2)
        self.contents += [self.day, self.month, self.year]

    def unserialize(self, val):
        CompositeType.unserialize(self, val)
        try:
            self.value = datetime.date(self.year.value+PLUGWISE_EPOCH, self.month.value, self.day.value)
        except ValueError:
            debug('value error while attempting to construct DateStr object')
            self.value = None
       
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
github SevenW / Plugwise-2-py / plugwise / protocol.py View on Github external
class UnixTimestamp(Int):
    def __init__(self, value, length=8):
        Int.__init__(self, value, length=length)

    def unserialize(self, val):
        Int.unserialize(self, val)
        self.value = datetime.datetime.fromtimestamp(self.value)

class Year2k(Int):
    """year value that is offset from the year 2000"""

    def unserialize(self, val):
        Int.unserialize(self, val)
        self.value += PLUGWISE_EPOCH

class DateTime(CompositeType):
    """datetime value as used in the general info response
    format is: YYMMmmmm
    where year is offset value from the epoch which is Y2K
    and last four bytes are offset from the beginning of the month in minutes
    """

    def __init__(self, year=0, month=0, minutes=0):
        CompositeType.__init__(self)        
        self.year = Year2k(year-PLUGWISE_EPOCH, 2)
        self.month = Int(month, 2)
        self.minutes = Int(minutes, 4)
        self.contents += [self.year, self.month, self.minutes]

    def unserialize(self, val):
        CompositeType.unserialize(self, val)
        minutes = self.minutes.value
github SevenW / Plugwise-2-py / plugwise / protocol.py View on Github external
class Time(CompositeType):
    """time value as used in the clock info response"""

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

    def unserialize(self, val):
        CompositeType.unserialize(self, val)
        self.value = datetime.time(self.hour.value, self.minute.value, self.second.value)
        
class DateStr(CompositeType):
    """date value as used in the datetime info response"""

    def __init__(self, day=0, month=0, year=0):
        CompositeType.__init__(self)
        self.day = StringVal(day, 2)
        self.month = StringVal(month, 2)
        self.year = StringVal(year, 2)
        self.contents += [self.day, self.month, self.year]

    def unserialize(self, val):
        CompositeType.unserialize(self, val)
        try:
            self.value = datetime.date(self.year.value+PLUGWISE_EPOCH, self.month.value, self.day.value)
        except ValueError:
            debug('value error while attempting to construct DateStr object')
            self.value = None