from MAXPacket import PushButtonState


class MAXDevice:
    def __init__(self, name, address):
        self.address: str = address
        self.name: str = name

    def to_string(self):
        return "{};{}".format(self.name, self.address.lower())

    def from_string(line):
        splitted = line.split(';')
        if len(splitted) >= 3:
            if splitted[0] == "1":
                new_dev = MAXThermostat(splitted[1], splitted[2].lower())
                return new_dev
            elif splitted[0] == "5":
                new_dev = MAXPushButton(splitted[1], splitted[2].lower())
                return new_dev


class MAXPushButton(MAXDevice):
    def __init__(self, name, address):
        super(MAXPushButton, self).__init__(name, address)
        self.state = PushButtonState.UNKNOWN

    def serialize(self):
        return "5;{}".format(self.to_string())


class MAXThermostat(MAXDevice):
    def __init__(self, name, address):
        super(MAXThermostat, self).__init__(name, address)

    def serialize(self):
        return "1;{}".format(self.to_string())
