<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _legacy_status(stat):
 """Legacy status method from the 'qsmobile.js' library. Pass in the 'val' from &devices or the 'data' received after calling a specific ID. """

    # 2d0c00002a0000
    if stat[:2] == '30' or stat[:2] == '47':  # RX1 CT
        ooo = stat[4:5]
        # console.log("legstat. " + o);
        if ooo == '0':
            return 0
        if ooo == '8':
            return 100
    if stat == '7e':
        return 0
    if stat == '7f':
        return 100
    if len(stat) == 6:  # old
        try:
            val = int(stat[4:], 16)
        except ValueError:
            val = 0
        hwt = stat[:2]
        if hwt == '01':  # old dim
            return round(((125 - val) / 125) * 100)
        if hwt == '02':  # old rel
            return 100 if val == 127 else 0
        if hwt == '28':  # LED DIM
            if stat[2:4] == '01':
                if stat[4:] == '78':
                    return 0
            return round(((120 - val) / 120) * 100)

    # Additional decodes not part of qsmobile.js
    if stat.upper().find('ON') >= 0:  # Relay
        return 100
    if (not stat) or stat.upper().find('OFF') >= 0:
        return 0
    if stat.endswith('%'):  # New style dimmers
        if stat[:-1].isdigit:
            return int(stat[:-1])
    _LOGGER.debug("val='%s' used a -1 fallback in legacy_status", stat)
    return -1