def ProcessOilOffKey(keyValue):

    # Do not process if we are disabled.
    if GD.currentMode == GD.MODE_MANUAL_OPTIONS_DISABLED: return 1

    # If oil to heating is active we need to make it idle and set T1 to heating. Set T1 to heating key text active.
    # Note this test must be done first before we change any config bits.
    if (system.systemControl[
            GD.SYSTEM_MANUAL_OIL_BOILER_TO_HEATING].CheckIfBitHigh() == True):

        system.UpdateSystemControlBits(
            bitsHigh=GD.SYSTEM_MANUAL_TANK_1_TO_HEATING,
            bitsLow=GD.HEATING_MANUAL_CONTROL_GROUP)
        keyData.UpdateSelectKeyGroupText(textActive=GD.KEYVALUE_T1_TO_HEAT,
                                         textIdle=GD.KEY_GROUP_HEATING_MODE)

    # Set the Oil boiler off config bit and make boiler off key text active.
    system.UpdateSystemControlBits(bitsHigh=GD.SYSTEM_MANUAL_OIL_BOILER_OFF,
                                   bitsLow=GD.BOILER_MANUAL_CONTROL_GROUP)
    keyData.UpdateSelectKeyGroupText(textActive=GD.KEYVALUE_OIL_OFF,
                                     textIdle=GD.KEY_GROUP_BOILER_MODE)

    # Read the config bits and update the bands on all the manual option control keys.
    keyData.SetControlBandStatus(GD.ALL_MANUAL_CONTROL_GROUP,
                                 GD.KEY_GROUP_MANUAL_MODE)

    # Display all the control keys with their new band status.
    display.UpdateSelectKeyImages(GD.KEY_GROUP_MANUAL_MODE, GD.UPDATE_ALL)

    return 1
def ProcessSystemModeKeys(keyValue):

    # Move to required mode.
    GD.currentMode = GD.KEY_TO_MODE_LOOKUP[keyValue]

    # Display keyboard for this mode
    display.DisplayKeyboardImage(useMode=GD.currentMode)

    # Get config bit for this mode.
    systemBit = GD.KEY_TO_CONTROL_BIT_LOOKUP[keyValue]

    # Set the config bit and clear the other config bits.
    system.UpdateSystemControlBits(bitsHigh=systemBit,
                                   bitsLow=GD.SYSTEM_CONTROL_GROUP)

    # Make key text active and clear other mode keys.
    keyData.UpdateSelectKeyGroupText(textActive=keyValue,
                                     textIdle=GD.KEY_GROUP_SYSTEM_MODE)

    # Now read the config bits and update the bands on all the system control keys.
    keyData.SetControlBandStatus(GD.SYSTEM_CONTROL_GROUP,
                                 GD.KEY_GROUP_SYSTEM_MODE)

    # Display all the control keys with their new band status.
    display.UpdateSelectKeyImages(GD.KEY_GROUP_SYSTEM_MODE, GD.UPDATE_ALL)

    # Update all the zone statuses. We do this so that the zone on/off bands will show which zones will be turning on when we
    # have switched from off mode to one of the active modes (man, auto or holiday).
    for zone in range(0, 30):
        zones.UpdateZoneStatus(zone)

    return 1
def ProcessOilToHeatingKey(keyValue):

    # Do not process if we are disabled.
    if GD.currentMode == GD.MODE_MANUAL_OPTIONS_DISABLED: return 1

    # Set the Oil to heating config bit and make Oil to heating key text active.
    system.UpdateSystemControlBits(
        bitsHigh=GD.SYSTEM_MANUAL_OIL_BOILER_TO_HEATING,
        bitsLow=GD.ALL_MANUAL_CONTROL_GROUP)
    keyData.UpdateSelectKeyGroupText(textActive=GD.KEYVALUE_OIL_TO_HEAT,
                                     textIdle=GD.KEY_GROUP_MANUAL_MODE)

    # Read the config bits and update the bands on all the manual option control keys.
    keyData.SetControlBandStatus(GD.ALL_MANUAL_CONTROL_GROUP,
                                 GD.KEY_GROUP_MANUAL_MODE)

    # Display all the control keys with their new band status.
    display.UpdateSelectKeyImages(GD.KEY_GROUP_MANUAL_MODE, GD.UPDATE_ALL)

    return 1