Parse KNX group addresses and return the address as an integer.

    This allows to convert x/x/x and x/x address syntax to a numeric
    KNX group address

def parse_group_address(addr):
    """Parse KNX group addresses and return the address as an integer.

    This allows to convert x/x/x and x/x address syntax to a numeric
    KNX group address
    """

    if addr is None:
        raise KNXException("No address given")

    res = None

    if re.match('[0-9]+$', addr):
        res = int(addr)

    match = re.match("([0-9]+)/([0-9]+)$", addr)
    if match:
        main = match.group(1)
        sub = match.group(2)
        res = int(main) * 2048 + int(sub)

    match = re.match("([0-9]+)/([0-9]+)/([0-9]+)$", addr)
    if match:
        main = match.group(1)
        middle = match.group(2)
        sub = match.group(3)
        res = int(main) * 256 * 8 + int(middle) * 256 + int(sub)

    if res is None:
        raise KNXException("Address {} does not match any address scheme".
                           format(addr))

    return res